Commit 29cb44ee authored by Shawn Rutledge's avatar Shawn Rutledge
Browse files

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: default avatarShawn Rutledge <shawn.rutledge@qt.io>
Showing with 18 additions and 4 deletions
...@@ -243,15 +243,29 @@ Flickable { ...@@ -243,15 +243,29 @@ Flickable {
enabled: image.sourceSize.width < 5000 enabled: image.sourceSize.width < 5000
onActiveChanged: onActiveChanged:
if (!active) { 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 newSourceWidth = image.sourceSize.width * paper.scale
var ratio = newSourceWidth / image.sourceSize.width 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) { if (ratio > 1.1 || ratio < 0.9) {
var centroidOnPage = Qt.point(centroidInPoints.x * root.renderScale * ratio, centroidInPoints.y * root.renderScale * ratio)
paper.scale = 1 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 grabPermissions: PointerHandler.CanTakeOverFromAnything
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment