From cb78d5c91ed33543a8e7fe7717f74f95834e4cc3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 18 Oct 2016 18:45:49 +0200 Subject: TapHandler: add gesturePolicy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/quick/handlers/qquicktaphandler_p.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/quick/handlers/qquicktaphandler_p.h') 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; -- cgit v1.2.3