aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickdrag.cpp14
-rw-r--r--src/quick/items/qquickdrag_p.h6
-rw-r--r--src/quick/items/qquickmousearea.cpp8
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp45
4 files changed, 71 insertions, 2 deletions
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
*/
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index d0a1c18885..ee29ed2075 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -86,6 +86,7 @@ private slots:
void resetDrag();
void dragging_data() { acceptedButton_data(); }
void dragging();
+ void dragSmoothed();
void dragThreshold();
void invalidDrag_data() { rejectedButton_data(); }
void invalidDrag();
@@ -334,6 +335,50 @@ void tst_QQuickMouseArea::dragging()
QCOMPARE(blackRect->y(), 61.0);
}
+void tst_QQuickMouseArea::dragSmoothed()
+{
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject() != 0);
+
+ QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
+ QQuickDrag *drag = mouseRegion->drag();
+ drag->setThreshold(5);
+
+ mouseRegion->setAcceptedButtons(Qt::LeftButton);
+ QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
+ QVERIFY(blackRect != 0);
+ QVERIFY(blackRect == drag->target());
+ QVERIFY(!drag->active());
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 102), 50);
+ QTest::mouseMove(&window, QPoint(100, 106), 50);
+ QTest::mouseMove(&window, QPoint(100, 122), 50);
+ QTRY_COMPARE(blackRect->x(), 50.0);
+ QTRY_COMPARE(blackRect->y(), 66.0);
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100,122));
+
+ // reset rect position
+ blackRect->setX(50.0);
+ blackRect->setY(50.0);
+
+ // now try with smoothed disabled
+ drag->setSmoothed(false);
+ QVERIFY(!drag->active());
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
+ QVERIFY(!drag->active());
+ QTest::mouseMove(&window, QPoint(100, 102), 50);
+ QTest::mouseMove(&window, QPoint(100, 106), 50);
+ QTest::mouseMove(&window, QPoint(100, 122), 50);
+ QTRY_COMPARE(blackRect->x(), 50.0);
+ QTRY_COMPARE(blackRect->y(), 72.0);
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 122));
+}
void tst_QQuickMouseArea::dragThreshold()
{