Allow margin changes during Flickable drag operation
authorMatt Vogt <matthew.vogt@jollamobile.com>
Mon, 19 Nov 2012 01:03:20 +0000 (11:03 +1000)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 19 Nov 2012 01:52:44 +0000 (02:52 +0100)
Previously, the dimensions of the flickable were captured at mouse
press and reused during dragging, which causes problems if the margins
of the Flickable are altered during the drag. Adjust the captured
values so that margin changes are correctly handled.

Change-Id: I1ce608dcc1302ea8639bf18a81361b27749b217b
Reviewed-by: Martin Jones <martin.jones@qinetic.com.au>
src/quick/items/qquickflickable.cpp

index a15f77d..a0bd1fa 100644 (file)
@@ -974,10 +974,10 @@ void QQuickFlickablePrivate::handleMousePressEvent(QMouseEvent *event)
 
     hData.reset();
     vData.reset();
-    hData.dragMinBound = q->minXExtent();
-    vData.dragMinBound = q->minYExtent();
-    hData.dragMaxBound = q->maxXExtent();
-    vData.dragMaxBound = q->maxYExtent();
+    hData.dragMinBound = q->minXExtent() - hData.startMargin;
+    vData.dragMinBound = q->minYExtent() - vData.startMargin;
+    hData.dragMaxBound = q->maxXExtent() + hData.endMargin;
+    vData.dragMaxBound = q->maxYExtent() + vData.endMargin;
     fixupMode = Normal;
     lastPos = QPointF();
     pressPos = event->localPos();
@@ -1021,8 +1021,11 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
             if (!vMoved)
                 vData.dragStartOffset = dy;
             qreal newY = dy + vData.pressPos - vData.dragStartOffset;
-            const qreal minY = vData.dragMinBound;
-            const qreal maxY = vData.dragMaxBound;
+            // 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
+            const qreal minY = vData.dragMinBound + vData.startMargin;
+            const qreal maxY = vData.dragMaxBound - vData.endMargin;
             if (newY > minY)
                 newY = minY + (newY - minY) / 2;
             if (newY < maxY && maxY - minY <= 0)
@@ -1055,8 +1058,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
             if (!hMoved)
                 hData.dragStartOffset = dx;
             qreal newX = dx + hData.pressPos - hData.dragStartOffset;
-            const qreal minX = hData.dragMinBound;
-            const qreal maxX = hData.dragMaxBound;
+            const qreal minX = hData.dragMinBound + hData.startMargin;
+            const qreal maxX = hData.dragMaxBound - hData.endMargin;
             if (newX > minX)
                 newX = minX + (newX - minX) / 2;
             if (newX < maxX && maxX - minX <= 0)