Improve the ordering of Flickable dragging and moving property updates.
authorAndrew den Exter <andrew.den.exter@jollamobile.com>
Tue, 5 Mar 2013 07:56:21 +0000 (17:56 +1000)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 11 Mar 2013 23:43:33 +0000 (00:43 +0100)
Move the contentItem after the dragging and moving properties have been
updated so they return the correct values from the onContentYChanged
and onContentXChanged handlers.

Task-number: QTBUG-30032
Change-Id: I15716dc8eee4d9836f96362a8b49f1d0c404b0c2
Reviewed-by: Alan Alpert <aalpert@blackberry.com>

src/quick/items/qquickflickable.cpp
tests/auto/quick/qquickflickable/data/flickable03.qml
tests/auto/quick/qquickflickable/tst_qquickflickable.cpp

index 3482db0..9346c79 100644 (file)
@@ -1014,6 +1014,12 @@ 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();
@@ -1021,7 +1027,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
         if (vData.dragStartOffset == 0)
             vData.dragStartOffset = dy;
         if (overThreshold || elapsedSincePress > 200) {
-            qreal newY = dy + vData.pressPos - vData.dragStartOffset;
+            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
@@ -1041,8 +1047,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;
@@ -1055,7 +1061,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
         if (hData.dragStartOffset == 0)
             hData.dragStartOffset = dx;
         if (overThreshold || elapsedSincePress > 200) {
-            qreal newX = dx + hData.pressPos - hData.dragStartOffset;
+            newX = dx + hData.pressPos - hData.dragStartOffset;
             const qreal minX = hData.dragMinBound + hData.startMargin;
             const qreal maxX = hData.dragMaxBound - hData.endMargin;
             if (newX > minX)
@@ -1073,8 +1079,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
 
             if (!rejectX && stealMouse && dx != 0.0) {
                 clearTimeline();
-                hData.move.setValue(newX);
                 hMoved = true;
+                moveX = true;
             }
 
             if (!rejectX && overThreshold)
@@ -1102,6 +1108,11 @@ 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 a3e9d6f..1549034 100644 (file)
@@ -1,9 +1,23 @@
 import QtQuick 2.0
 
 Flickable {
+    property bool movingInContentX: true
+    property bool movingInContentY: true
+    property bool draggingInContentX: true
+    property bool draggingInContentY: true
+
     width: 100; height: 400
     contentWidth: column.width; contentHeight: column.height
 
+    onContentXChanged: {
+        movingInContentX = movingInContentX && movingHorizontally
+        draggingInContentX = draggingInContentX && draggingHorizontally
+    }
+    onContentYChanged: {
+        movingInContentY = movingInContentY && movingVertically
+        draggingInContentY = draggingInContentY && draggingVertically
+    }
+
     Column {
         id: column
         Repeater {
index 57c4c12..c4f871f 100644 (file)
@@ -647,6 +647,9 @@ void tst_qquickflickable::movingAndFlicking()
     QVERIFY(flickable->isFlicking());
     QCOMPARE(flickable->isFlickingHorizontally(), horizontalEnabled);
     QCOMPARE(flickable->isFlickingVertically(), verticalEnabled);
+    // contentX/contentY are either unchanged, or moving is true when the value changed.
+    QCOMPARE(flickable->property("movingInContentX").value<bool>(), true);
+    QCOMPARE(flickable->property("movingInContentY").value<bool>(), true);
 
     QCOMPARE(moveSpy.count(), 1);
     QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0);
@@ -810,6 +813,11 @@ void tst_qquickflickable::movingAndDragging()
     QVERIFY(flickable->isDragging());
     QCOMPARE(flickable->isDraggingHorizontally(), horizontalEnabled);
     QCOMPARE(flickable->isDraggingVertically(), verticalEnabled);
+    // contentX/contentY are either unchanged, or moving and dragging are true when the value changes.
+    QCOMPARE(flickable->property("movingInContentX").value<bool>(), true);
+    QCOMPARE(flickable->property("movingInContentY").value<bool>(), true);
+    QCOMPARE(flickable->property("draggingInContentX").value<bool>(), true);
+    QCOMPARE(flickable->property("draggingInContentY").value<bool>(), true);
 
     QCOMPARE(moveSpy.count(), 1);
     QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0);