31 Q_PROPERTY(
bool pressed READ isPressed NOTIFY pressedChanged)
32 Q_PROPERTY(
int tapCount READ tapCount NOTIFY tapCountChanged)
33 Q_PROPERTY(qreal timeHeld READ timeHeld NOTIFY timeHeldChanged)
34 Q_PROPERTY(qreal longPressThreshold READ longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged RESET resetLongPressThreshold)
35 Q_PROPERTY(GesturePolicy gesturePolicy READ gesturePolicy WRITE setGesturePolicy NOTIFY gesturePolicyChanged)
36 Q_PROPERTY(QQuickTapHandler::ExclusiveSignals exclusiveSignals READ exclusiveSignals WRITE setExclusiveSignals NOTIFY exclusiveSignalsChanged REVISION(6, 5))
38 QML_NAMED_ELEMENT(TapHandler)
39 QML_ADDED_IN_VERSION(2, 12)
50 enum ExclusiveSignal {
55 Q_DECLARE_FLAGS(ExclusiveSignals, ExclusiveSignal)
56 Q_FLAG(ExclusiveSignals)
58 explicit QQuickTapHandler(QQuickItem *parent =
nullptr);
60 bool isPressed()
const {
return m_pressed; }
62 int tapCount()
const {
return m_tapCount; }
63 qreal timeHeld()
const {
return (m_holdTimer.isValid() ? m_holdTimer.elapsed() / 1000.0 : -1.0); }
65 qreal longPressThreshold()
const;
66 void setLongPressThreshold(qreal longPressThreshold);
67 void resetLongPressThreshold();
69 GesturePolicy gesturePolicy()
const {
return m_gesturePolicy; }
70 void setGesturePolicy(GesturePolicy gesturePolicy);
72 QQuickTapHandler::ExclusiveSignals exclusiveSignals()
const {
return m_exclusiveSignals; }
73 void setExclusiveSignals(QQuickTapHandler::ExclusiveSignals newexclusiveSignals);
76 void pressedChanged();
77 void tapCountChanged();
78 void timeHeldChanged();
79 void longPressThresholdChanged();
80 void gesturePolicyChanged();
81 Q_REVISION(6, 5)
void exclusiveSignalsChanged();
83 void tapped(QEventPoint eventPoint, Qt::MouseButton );
84 void singleTapped(QEventPoint eventPoint, Qt::MouseButton );
85 void doubleTapped(QEventPoint eventPoint, Qt::MouseButton );
89 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition,
90 QPointerEvent *ev, QEventPoint &point) override;
91 void timerEvent(QTimerEvent *event) override;
92 bool wantsEventPoint(
const QPointerEvent *event,
const QEventPoint &point) override;
93 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
96 void setPressed(
bool press,
bool cancel, QPointerEvent *event, QEventPoint &point);
97 void connectPreRenderSignal(
bool conn =
true);
98 void updateTimeHeld();
101 QPointF m_lastTapPos;
102 quint64 m_lastTapTimestamp = 0;
103 QElapsedTimer m_holdTimer;
104 QBasicTimer m_longPressTimer;
105 QBasicTimer m_doubleTapTimer;
106 QEventPoint m_singleTapReleasedPoint;
107 QMetaObject::Connection m_preRenderSignalConnection;
108 Qt::MouseButton m_singleTapReleasedButton;
110 int m_longPressThreshold = -1;
111 GesturePolicy m_gesturePolicy = GesturePolicy::DragThreshold;
112 ExclusiveSignals m_exclusiveSignals = NotExclusive;
113 bool m_pressed =
false;
114 bool m_longPressed =
false;
116 static quint64 m_multiTapInterval;
117 static int m_mouseMultiClickDistanceSquared;
118 static int m_touchMultiTapDistanceSquared;