From 0c74cbcccb52e296667c6bc171084f4946daef61 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Mon, 19 Nov 2012 11:03:20 +1000 Subject: [PATCH] Allow margin changes during Flickable drag operation 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 --- src/quick/items/qquickflickable.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index a15f77d..a0bd1fa 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -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) -- 2.7.4