diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-10-18 18:45:49 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-02-09 14:32:21 +0000 |
commit | cb78d5c91ed33543a8e7fe7717f74f95834e4cc3 (patch) | |
tree | 3de3fbf56055d3aa0dc8017bbd705f9e6325f49c /src/quick/handlers/qquicktaphandler_p.h | |
parent | 5c639a07fd90916d39823e800d5d89f779d892e9 (diff) |
TapHandler: add gesturePolicy
Until now it behaved as if this was set to DragThreshold: give up on
the tap as soon as you are clearly dragging rather than tapping.
But that's not what is normally wanted when building a Button control,
for example. So provide 3 options: give up past the drag threshold,
when the pointer goes outside the bounds, or when it's released
outside the bounds. The longPressThreshold also constrains all
three cases: holding (or dragging) for too long will not result
in an immediate cancellation, but it also will not be a tap gesture.
Change-Id: I95aec978e783892b55371391a27642751d91d9ff
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquicktaphandler_p.h')
-rw-r--r-- | src/quick/handlers/qquicktaphandler_p.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/quick/handlers/qquicktaphandler_p.h b/src/quick/handlers/qquicktaphandler_p.h index 0559089fbf..93fe817844 100644 --- a/src/quick/handlers/qquicktaphandler_p.h +++ b/src/quick/handlers/qquicktaphandler_p.h @@ -64,8 +64,16 @@ class Q_AUTOTEST_EXPORT QQuickTapHandler : public QQuickPointerSingleHandler Q_PROPERTY(bool isPressed READ isPressed NOTIFY pressedChanged) Q_PROPERTY(int tapCount READ tapCount NOTIFY tapCountChanged) Q_PROPERTY(qreal longPressThreshold READ longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged) + Q_PROPERTY(GesturePolicy gesturePolicy READ gesturePolicy WRITE setGesturePolicy NOTIFY gesturePolicyChanged) public: + enum GesturePolicy { + DragThreshold, + WithinBounds, + ReleaseWithinBounds + }; + Q_ENUM(GesturePolicy) + QQuickTapHandler(QObject *parent = 0); ~QQuickTapHandler(); @@ -79,10 +87,14 @@ public: qreal longPressThreshold() const; void setLongPressThreshold(qreal longPressThreshold); + GesturePolicy gesturePolicy() const { return m_gesturePolicy; } + void setGesturePolicy(GesturePolicy gesturePolicy); + Q_SIGNALS: void pressedChanged(); void tapCountChanged(); void longPressThresholdChanged(); + void gesturePolicyChanged(); void tapped(QQuickEventPoint *point); void longPressed(); @@ -96,13 +108,13 @@ private: private: bool m_pressed; + GesturePolicy m_gesturePolicy; int m_tapCount; int m_longPressThreshold; QBasicTimer m_longPressTimer; QPointF m_lastTapPos; qreal m_lastTapTimestamp; - static qreal m_tapInterval; static qreal m_multiTapInterval; static int m_mouseMultiClickDistanceSquared; static int m_touchMultiTapDistanceSquared; |