From 0d7c2b4a84feec5f65f440dd4a537c8946179314 Mon Sep 17 00:00:00 2001
From: Shawn Rutledge <shawn.rutledge@qt.io>
Date: Fri, 21 Feb 2020 23:51:11 +0100
Subject: [PATCH] PdfScrollablePageView: move selections and links inside the
 image

Now that the Image is being rotated and the "paper" rectangle is not,
we need to work in the right coordinate system for rendering of Shapes
on top, and for handling drags to select text.

Change-Id: I6bc1e2fe7997ffc4673720abdcd3b7e4d9bc9012
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
---
 src/pdf/quick/qml/PdfScrollablePageView.qml | 120 ++++++++++----------
 1 file changed, 57 insertions(+), 63 deletions(-)

diff --git a/src/pdf/quick/qml/PdfScrollablePageView.qml b/src/pdf/quick/qml/PdfScrollablePageView.qml
index ae7bdb6f4..e27b21d14 100644
--- a/src/pdf/quick/qml/PdfScrollablePageView.qml
+++ b/src/pdf/quick/qml/PdfScrollablePageView.qml
@@ -175,63 +175,72 @@ Flickable {
             rotation: root.pageRotation
             anchors.centerIn: parent
             property real pageScale: image.paintedWidth / document.pagePointSize(navigationStack.currentPage).width
-        }
 
-        Shape {
-            anchors.fill: parent
-            opacity: 0.25
-            visible: image.status === Image.Ready
-            ShapePath {
-                strokeWidth: 1
-                strokeColor: "cyan"
-                fillColor: "steelblue"
-                scale: Qt.size(image.pageScale, image.pageScale)
-                PathMultiline {
-                    paths: searchModel.currentPageBoundingPolygons
+            Shape {
+                anchors.fill: parent
+                opacity: 0.25
+                visible: image.status === Image.Ready
+                ShapePath {
+                    strokeWidth: 1
+                    strokeColor: "cyan"
+                    fillColor: "steelblue"
+                    scale: Qt.size(image.pageScale, image.pageScale)
+                    PathMultiline {
+                        paths: searchModel.currentPageBoundingPolygons
+                    }
                 }
-            }
-            ShapePath {
-                strokeWidth: 1
-                strokeColor: "orange"
-                fillColor: "cyan"
-                scale: Qt.size(image.pageScale, image.pageScale)
-                PathMultiline {
-                    paths: searchModel.currentResultBoundingPolygons
+                ShapePath {
+                    strokeWidth: 1
+                    strokeColor: "orange"
+                    fillColor: "cyan"
+                    scale: Qt.size(image.pageScale, image.pageScale)
+                    PathMultiline {
+                        paths: searchModel.currentResultBoundingPolygons
+                    }
                 }
-            }
-            ShapePath {
-                fillColor: "orange"
-                scale: Qt.size(image.pageScale, image.pageScale)
-                PathMultiline {
-                    paths: selection.geometry
+                ShapePath {
+                    fillColor: "orange"
+                    scale: Qt.size(image.pageScale, image.pageScale)
+                    PathMultiline {
+                        paths: selection.geometry
+                    }
                 }
             }
-        }
 
-        Repeater {
-            model: PdfLinkModel {
-                id: linkModel
-                document: root.document
-                page: navigationStack.currentPage
-            }
-            delegate: Rectangle {
-                color: "transparent"
-                border.color: "lightgrey"
-                x: rect.x * image.pageScale
-                y: rect.y * image.pageScale
-                width: rect.width * image.pageScale
-                height: rect.height * image.pageScale
-                MouseArea { // TODO switch to TapHandler / HoverHandler in 5.15
-                    anchors.fill: parent
-                    cursorShape: Qt.PointingHandCursor
-                    onClicked: {
-                        if (page >= 0)
-                            navigationStack.push(page, Qt.point(0, 0), root.renderScale)
-                        else
-                            Qt.openUrlExternally(url)
+            Repeater {
+                model: PdfLinkModel {
+                    id: linkModel
+                    document: root.document
+                    page: navigationStack.currentPage
+                }
+                delegate: Rectangle {
+                    color: "transparent"
+                    border.color: "lightgrey"
+                    x: rect.x * image.pageScale
+                    y: rect.y * image.pageScale
+                    width: rect.width * image.pageScale
+                    height: rect.height * image.pageScale
+                    MouseArea { // TODO switch to TapHandler / HoverHandler in 5.15
+                        anchors.fill: parent
+                        cursorShape: Qt.PointingHandCursor
+                        onClicked: {
+                            if (page >= 0)
+                                navigationStack.push(page, Qt.point(0, 0), root.renderScale)
+                            else
+                                Qt.openUrlExternally(url)
+                        }
                     }
                 }
             }
+            DragHandler {
+                id: textSelectionDrag
+                acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+                target: null
+            }
+            TapHandler {
+                id: tapHandler
+                acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+            }
         }
 
         PinchHandler {
@@ -269,20 +278,5 @@ Flickable {
                 }
             grabPermissions: PointerHandler.CanTakeOverFromAnything
         }
-        DragHandler {
-            id: pageMovingMiddleMouseDrag
-            acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
-            acceptedButtons: Qt.MiddleButton
-            snapMode: DragHandler.NoSnap
-        }
-        DragHandler {
-            id: textSelectionDrag
-            acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
-            target: null
-        }
-        TapHandler {
-            id: tapHandler
-            acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
-        }
     }
 }
-- 
GitLab