Fix jump and property changes on first move when dragging a Flickable.
authorAndrew den Exter <andrew.den.exter@jollamobile.com>
Tue, 12 Mar 2013 04:05:32 +0000 (14:05 +1000)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 19 Mar 2013 01:20:05 +0000 (02:20 +0100)
Fixes a regression introduced by https://codereview.qt-project.org/48690
whereby on the first mouse move the contentItem was moved the total
distance from the touch point to where the drag distance was exceeded.
For large drag thresholds this causes a noticeable jump. Reverting the
dragStartOffset portion of that change fixes the regression.

That same change was also resposible for the property update regression
https://codereview.qt-project.org/49768 attempted to fix.  That change
is also reverted as it was unnecessary and may have introduced some
regressions of its own.

Task-number: QTBUG-30032
Change-Id: I7723b459cc5a6a0731893aeb6332d00cad1bd79b
Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
src/quick/items/qquickflickable.cpp
tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp

index 9346c79..dd73578 100644 (file)
@@ -1014,20 +1014,14 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
     bool prevHMoved = hMoved;
     bool prevVMoved = vMoved;
 
-    bool moveY = false;
-    bool moveX = false;
-
-    qreal newY = 0;
-    qreal newX = 0;
-
     qint64 elapsedSincePress = computeCurrentTime(event) - lastPressTime;
     if (q->yflick()) {
         qreal dy = event->localPos().y() - pressPos.y();
         bool overThreshold = QQuickWindowPrivate::dragOverThreshold(dy, Qt::YAxis, event);
-        if (vData.dragStartOffset == 0)
-            vData.dragStartOffset = dy;
         if (overThreshold || elapsedSincePress > 200) {
-            newY = dy + vData.pressPos - vData.dragStartOffset;
+            if (!vMoved)
+                vData.dragStartOffset = dy;
+            qreal newY = dy + vData.pressPos - vData.dragStartOffset;
             // Recalculate bounds in case margins have changed, but use the content
             // size estimate taken at the start of the drag in case the drag causes
             // the estimate to be altered
@@ -1047,8 +1041,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
             }
             if (!rejectY && stealMouse && dy != 0.0) {
                 clearTimeline();
+                vData.move.setValue(newY);
                 vMoved = true;
-                moveY = true;
             }
             if (!rejectY && overThreshold)
                 stealY = true;
@@ -1058,10 +1052,10 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
     if (q->xflick()) {
         qreal dx = event->localPos().x() - pressPos.x();
         bool overThreshold = QQuickWindowPrivate::dragOverThreshold(dx, Qt::XAxis, event);
-        if (hData.dragStartOffset == 0)
-            hData.dragStartOffset = dx;
         if (overThreshold || elapsedSincePress > 200) {
-            newX = dx + hData.pressPos - hData.dragStartOffset;
+            if (!hMoved)
+                hData.dragStartOffset = dx;
+            qreal newX = dx + hData.pressPos - hData.dragStartOffset;
             const qreal minX = hData.dragMinBound + hData.startMargin;
             const qreal maxX = hData.dragMaxBound - hData.endMargin;
             if (newX > minX)
@@ -1079,8 +1073,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
 
             if (!rejectX && stealMouse && dx != 0.0) {
                 clearTimeline();
+                hData.move.setValue(newX);
                 hMoved = true;
-                moveX = true;
             }
 
             if (!rejectX && overThreshold)
@@ -1108,11 +1102,6 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
         q->movementStarting();
     }
 
-    if (moveY)
-        vData.move.setValue(newY);
-    if (moveX)
-        hData.move.setValue(newX);
-
     qint64 currentTimestamp = computeCurrentTime(event);
     qreal elapsed = qreal(currentTimestamp - (lastPos.isNull() ? lastPressTime : lastPosTime)) / 1000.;
     if (elapsed <= 0)
index a4bc924..055facc 100644 (file)
@@ -807,8 +807,8 @@ void tst_QQuickMouseArea::preventStealing()
 
     // Flickable content should have moved.
 
-    QCOMPARE(flickable->contentX(), 22.);
-    QCOMPARE(flickable->contentY(), 22.);
+    QCOMPARE(flickable->contentX(), 11.);
+    QCOMPARE(flickable->contentY(), 11.);
 
     QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50, 50));