From 57af89d1fcbc81e9d17a02be3f54ca239afe6697 Mon Sep 17 00:00:00 2001
From: Shawn Rutledge <shawn.rutledge@qt.io>
Date: Wed, 19 Feb 2020 15:46:02 +0100
Subject: [PATCH] Fix PdfLinkModel's location y coordinate; add
 PdfMultiPageView tooltip

As usual, coordinates are in the first quadrant, and we need to
convert to 4th quadrant to get a y value that can be used to adjust
contentY of a ListView or TableView.

The tooltip when hovering over links provides a way to verify that
the link really jumps where it's intended to.

Change-Id: I9107639f15496a987c0fa7c3c2e2583c3839cc6b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
---
 src/pdf/qpdflinkmodel.cpp              |  2 +-
 src/pdf/quick/qml/PdfMultiPageView.qml | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/pdf/qpdflinkmodel.cpp b/src/pdf/qpdflinkmodel.cpp
index 8b49fec21..96e6ddd5c 100644
--- a/src/pdf/qpdflinkmodel.cpp
+++ b/src/pdf/qpdflinkmodel.cpp
@@ -179,7 +179,7 @@ void QPdfLinkModelPrivate::update()
         if (!ok)
             break;
         if (hasX && hasY)
-            linkData.location = QPointF(x, y);
+            linkData.location = QPointF(x, pageHeight - y);
         if (hasZoom)
             linkData.zoom = zoom;
         links << linkData;
diff --git a/src/pdf/quick/qml/PdfMultiPageView.qml b/src/pdf/quick/qml/PdfMultiPageView.qml
index b64f44576..b4bc61c64 100644
--- a/src/pdf/quick/qml/PdfMultiPageView.qml
+++ b/src/pdf/quick/qml/PdfMultiPageView.qml
@@ -242,8 +242,10 @@ Item {
                     width: rect.width * paper.pageScale
                     height: rect.height * paper.pageScale
                     MouseArea { // TODO switch to TapHandler / HoverHandler in 5.15
+                        id: linkMA
                         anchors.fill: parent
                         cursorShape: Qt.PointingHandCursor
+                        hoverEnabled: true
                         onClicked: {
                             if (page >= 0)
                                 root.goToLocation(page, location, zoom)
@@ -251,6 +253,14 @@ Item {
                                 Qt.openUrlExternally(url)
                         }
                     }
+                    ToolTip {
+                        visible: linkMA.containsMouse
+                        delay: 1000
+                        text: page >= 0 ?
+                                  ("page " + (page + 1) +
+                                   " location " + location.x.toFixed(1) + ", " + location.y.toFixed(1) +
+                                   " zoom " + zoom) : url
+                    }
                 }
             }
         }
-- 
GitLab