From 528b720d8f25c851b5e73b4159c20d70a47aefc0 Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Wed, 7 May 2014 19:01:19 +0200 Subject: Introduce MouseArea.drag.smoothed [ChangeLog][QtQuick] Added property MouseArea.drag.smoothed for toggling whether the drag target is moved to the current mouse position after a drag operation has started. Task-number: QTBUG-38539 Change-Id: I989b51bc83fc24c64b84ac8e9a50b352e674e8f8 Reviewed-by: J-P Nurmi Reviewed-by: Alan Alpert --- src/quick/items/qquickdrag.cpp | 14 +++++++++++++- src/quick/items/qquickdrag_p.h | 6 ++++++ src/quick/items/qquickmousearea.cpp | 8 +++++++- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 6c36032d3c..7e5b357e9c 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -791,7 +791,7 @@ void QQuickDragAttached::startDrag(QQmlV4Function *args) QQuickDrag::QQuickDrag(QObject *parent) : QObject(parent), _target(0), _axis(XAndYAxis), _xmin(-FLT_MAX), _xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false), _filterChildren(false), - _threshold(qApp->styleHints()->startDragDistance()) + _smoothed(true), _threshold(qApp->styleHints()->startDragDistance()) { } @@ -885,6 +885,18 @@ void QQuickDrag::setYmax(qreal m) emit maximumYChanged(); } +bool QQuickDrag::smoothed() const +{ + return _smoothed; +} + +void QQuickDrag::setSmoothed(bool smooth) +{ + if (_smoothed != smooth) { + _smoothed = smooth; + emit smoothedChanged(); + } +} qreal QQuickDrag::threshold() const { diff --git a/src/quick/items/qquickdrag_p.h b/src/quick/items/qquickdrag_p.h index d9021d0f6d..eebe07469a 100644 --- a/src/quick/items/qquickdrag_p.h +++ b/src/quick/items/qquickdrag_p.h @@ -157,6 +157,7 @@ class Q_AUTOTEST_EXPORT QQuickDrag : public QObject Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged) Q_PROPERTY(bool active READ active NOTIFY activeChanged) Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged) + Q_PROPERTY(bool smoothed READ smoothed WRITE setSmoothed NOTIFY smoothedChanged) // Note, threshold was added in QtQuick 2.2 but REVISION is not supported (or needed) for grouped // properties See QTBUG-33179 Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged RESET resetThreshold) @@ -185,6 +186,9 @@ public: qreal ymax() const; void setYmax(qreal); + bool smoothed() const; + void setSmoothed(bool smooth); + qreal threshold() const; void setThreshold(qreal); void resetThreshold(); @@ -206,6 +210,7 @@ Q_SIGNALS: void maximumYChanged(); void activeChanged(); void filterChildrenChanged(); + void smoothedChanged(); void thresholdChanged(); private: @@ -217,6 +222,7 @@ private: qreal _ymax; bool _active : 1; bool _filterChildren: 1; + bool _smoothed : 1; qreal _threshold; Q_DISABLE_COPY(QQuickDrag) }; diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 2d84660b6d..01d1305260 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -723,7 +723,9 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) || QQuickWindowPrivate::dragOverThreshold(dragPos.y() - startPos.y(), Qt::YAxis, event, d->drag->threshold()))) { setKeepMouseGrab(true); d->stealMouse = true; - d->startScene = event->windowPos(); + + if (d->drag->smoothed()) + d->startScene = event->windowPos(); } d->moved = true; @@ -1250,6 +1252,10 @@ void QQuickMouseArea::setCursorShape(Qt::CursorShape shape) start. By default this is bound to a platform dependent value. This property was added in Qt Quick 2.2. + If \c drag.smoothed is \c true, the target will be moved only after the drag operation has + started. If set to \c false, the target will be moved straight to the current mouse position. + By default, this property is \c true. This property was added in Qt Quick 2.4 + \snippet qml/mousearea/mouseareadragfilter.qml dragfilter */ -- cgit v1.2.3