diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-21 23:17:43 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-21 23:56:49 +0100 |
commit | 29cb44ee471908ac7c4cac70e3defb8bd72a80cd (patch) | |
tree | a14d555bd95f1198252c2b17cbc35d8923eb4988 /src/pdf/quick | |
parent | c0aa9d794378846e4cc0b6fe94f2765bc31cefdd (diff) |
PdfScrollablePageView: retain position after pinch zoom
If you do the pinch on a trackpad, the mouse cursor doesn't move, and
the same visible part of the page will remain under the cursor after
the page is re-rendered. Likewise when doing the pinch on a touchscreen,
the centroid (midpoint between the two fingers) is held in place.
This is achieved by moving the scrollbars afterwards, subject to their
constraints.
Change-Id: I34caca4ebbb5c11007dd2462416a42c1a2d8e104
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/pdf/quick')
-rw-r--r-- | src/pdf/quick/qml/PdfScrollablePageView.qml | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/pdf/quick/qml/PdfScrollablePageView.qml b/src/pdf/quick/qml/PdfScrollablePageView.qml index 55aa44bbf..ae7bdb6f4 100644 --- a/src/pdf/quick/qml/PdfScrollablePageView.qml +++ b/src/pdf/quick/qml/PdfScrollablePageView.qml @@ -243,15 +243,29 @@ Flickable { enabled: image.sourceSize.width < 5000 onActiveChanged: if (!active) { + var centroidInPoints = Qt.point(pinch.centroid.position.x / root.renderScale, + pinch.centroid.position.y / root.renderScale) + var centroidInFlickable = root.mapFromItem(paper, pinch.centroid.position.x, pinch.centroid.position.y) var newSourceWidth = image.sourceSize.width * paper.scale var ratio = newSourceWidth / image.sourceSize.width + if (root.debug) + console.log("pinch ended with centroid", pinch.centroid.position, centroidInPoints, "wrt flickable", centroidInFlickable, + "page at", paper.x.toFixed(2), paper.y.toFixed(2), + "contentX/Y were", root.contentX.toFixed(2), root.contentY.toFixed(2)) if (ratio > 1.1 || ratio < 0.9) { + var centroidOnPage = Qt.point(centroidInPoints.x * root.renderScale * ratio, centroidInPoints.y * root.renderScale * ratio) paper.scale = 1 - root.renderScale *= ratio + paper.x = 0 + paper.y = 0 + root.contentX = centroidOnPage.x - centroidInFlickable.x + root.contentY = centroidOnPage.y - centroidInFlickable.y + root.renderScale *= ratio // onRenderScaleChanged calls navigationStack.update() so we don't need to here + if (root.debug) + console.log("contentX/Y adjusted to", root.contentX.toFixed(2), root.contentY.toFixed(2)) + } else { + paper.x = 0 + paper.y = 0 } - // TODO adjust contentX/Y to position the page so the same region is visible - paper.x = 0 - paper.y = 0 } grabPermissions: PointerHandler.CanTakeOverFromAnything } |