From f228af06c2c712302ee1dcdaf761cd24504b473e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Wed, 8 May 2019 16:56:55 +0200 Subject: Add snapMode to DragHandler This changes snap behavior slightly. Basically, it does not snap anymore if the target() item is an ancestor of the parentItem(). In addition, we add a property that enables users to change the behavior. (SnapIfPressedOutsideTarget has the old behavior) [ChangeLog][QtQuick][Event Handlers] Added DragHandler.snapMode which can be used to configure under which conditions the dragged item is snapped to be below the cursor. The default mode is SnapAuto. The old behavior can be obtained through the SnapIfPressedOutsideTarget mode. Fixes: QTBUG-75661 Change-Id: Ibc00e8fbe31b779f8e817af1505e76425467d27a Reviewed-by: Shawn Rutledge --- src/quick/handlers/qquickdraghandler_p.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/quick/handlers/qquickdraghandler_p.h') diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h index 748026488a..18c1fd841d 100644 --- a/src/quick/handlers/qquickdraghandler_p.h +++ b/src/quick/handlers/qquickdraghandler_p.h @@ -62,8 +62,17 @@ class Q_QUICK_PRIVATE_EXPORT QQuickDragHandler : public QQuickMultiPointHandler Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT) Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT) Q_PROPERTY(QVector2D translation READ translation NOTIFY translationChanged) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) public: + enum SnapMode { + NoSnap = 0, + SnapAuto, + SnapIfPressedOutsideTarget, + SnapAlways + }; + Q_ENUM(SnapMode) + explicit QQuickDragHandler(QQuickItem *parent = nullptr); void handlePointerEventImpl(QQuickPointerEvent *event) override; @@ -73,11 +82,14 @@ public: QVector2D translation() const { return m_translation; } void setTranslation(const QVector2D &trans); + QQuickDragHandler::SnapMode snapMode() const; + void setSnapMode(QQuickDragHandler::SnapMode mode); void enforceConstraints(); Q_SIGNALS: void translationChanged(); + void snapModeChanged(); protected: void onActiveChanged() override; @@ -97,6 +109,7 @@ private: QQuickDragAxis m_xAxis; QQuickDragAxis m_yAxis; + QQuickDragHandler::SnapMode m_snapMode = SnapAuto; bool m_pressedInsideTarget = false; friend class QQuickDragAxis; -- cgit v1.2.3