summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-04-12 19:32:41 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-06-04 20:55:31 +0200
commit66aca3c846082c516bef3b35eb5332ebba24ce9e (patch)
tree8c42dcdaa5e47f1c1bf04a84b7cc66431117e7b4 /src
parentea0e715a369b4a7ef9398e49c59dc425c8bf50a5 (diff)
Add PdfLinkDelegate instead of link decoration style properties
This simplifies PdfStyle somewhat. PdfLinkDelegate could still be replaced or augmented via file selectors, but we don't expect to need to, since link delegates are already non-visual. [ChangeLog][QtPDF] A PdfLinkDelegate will now be instantiated on top of each hyperlink in the PdfMultiPageView, PdfScrollablePageView and PdfPageView components, for event handling and to provide tapped() and contextMenuRequested() signals. It is non-visual by default, but can be customized, for example to draw underlines under hyperlinks if the PDF documents are not expected to have them already. Change-Id: Ib3726e7220a0c3858db564ca8d53a04625a11950 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/pdfquick/+Material/PdfStyle.qml4
-rw-r--r--src/pdfquick/+Universal/PdfStyle.qml4
-rw-r--r--src/pdfquick/CMakeLists.txt1
-rw-r--r--src/pdfquick/PdfLinkDelegate.qml104
-rw-r--r--src/pdfquick/PdfMultiPageView.qml36
-rw-r--r--src/pdfquick/PdfPageView.qml13
-rw-r--r--src/pdfquick/PdfScrollablePageView.qml36
-rw-r--r--src/pdfquick/PdfStyle.qml4
8 files changed, 121 insertions, 81 deletions
diff --git a/src/pdfquick/+Material/PdfStyle.qml b/src/pdfquick/+Material/PdfStyle.qml
index 0d2b9cb1f..2f9b85301 100644
--- a/src/pdfquick/+Material/PdfStyle.qml
+++ b/src/pdfquick/+Material/PdfStyle.qml
@@ -49,8 +49,4 @@ QtObject {
property color pageSearchResultsColor: withAlpha(Qt.lighter(Material.accentColor, 1.5), 0.5)
property color currentSearchResultStrokeColor: Material.accentColor
property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: palette.link
- property real linkUnderscoreStrokeWidth: -1 // no underlines under hyperlinks
- property int linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
}
diff --git a/src/pdfquick/+Universal/PdfStyle.qml b/src/pdfquick/+Universal/PdfStyle.qml
index c2d044f1d..5c01ec23a 100644
--- a/src/pdfquick/+Universal/PdfStyle.qml
+++ b/src/pdfquick/+Universal/PdfStyle.qml
@@ -49,8 +49,4 @@ QtObject {
property color pageSearchResultsColor: withAlpha(Qt.lighter(Universal.accent, 1.5), 0.5)
property color currentSearchResultStrokeColor: Universal.accent
property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: palette.link
- property real linkUnderscoreStrokeWidth: -1 // no underlines under hyperlinks
- property int linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
}
diff --git a/src/pdfquick/CMakeLists.txt b/src/pdfquick/CMakeLists.txt
index bb712be7b..112321015 100644
--- a/src/pdfquick/CMakeLists.txt
+++ b/src/pdfquick/CMakeLists.txt
@@ -3,6 +3,7 @@ find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Qml Quic
set(qml_files
"+Material/PdfStyle.qml"
"+Universal/PdfStyle.qml"
+ "PdfLinkDelegate.qml"
"PdfMultiPageView.qml"
"PdfPageView.qml"
"PdfScrollablePageView.qml"
diff --git a/src/pdfquick/PdfLinkDelegate.qml b/src/pdfquick/PdfLinkDelegate.qml
new file mode 100644
index 000000000..83e6e9284
--- /dev/null
+++ b/src/pdfquick/PdfLinkDelegate.qml
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick
+import QtQuick.Controls
+
+/*!
+ \qmltype PdfLinkDelegate
+ \inqmlmodule QtQuick.Pdf
+ \brief A component to decorate hyperlinks on a PDF page.
+
+ PdfLinkDelegate provides the component that QML-based PDF viewers
+ instantiate on top of each hyperlink that is found on each PDF page.
+
+ This component does not provide any visual decoration, because often the
+ hyperlinks will already be formatted in a distinctive way; but when the
+ mouse cursor hovers, it changes to Qt::PointingHandCursor, and a tooltip
+ appears after a delay. Clicking emits the goToLocation() signal if the link
+ is internal, or calls Qt.openUrlExternally() if the link contains a URL.
+
+ \sa PdfPageView, PdfScrollablePageView, PdfMultiPageView
+*/
+Item {
+ id: root
+ required property var link
+ required property rect rectangle
+ required property url url
+ required property int page
+ required property point location
+ required property real zoom
+
+ /*!
+ \qmlsignal PdfLinkDelegate::tapped(link)
+
+ Emitted on mouse click or touch tap.
+ */
+ signal tapped(var link)
+
+ /*!
+ \qmlsignal PdfLinkDelegate::contextMenuRequested(link)
+
+ Emitted on mouse right-click or touch long-press.
+ */
+ signal contextMenuRequested(var link)
+
+ HoverHandler {
+ id: linkHH
+ cursorShape: Qt.PointingHandCursor
+ }
+ TapHandler {
+ onTapped: root.tapped(link)
+ }
+ TapHandler {
+ acceptedButtons: Qt.RightButton
+ onTapped: root.contextMenuRequested(link)
+ }
+ TapHandler {
+ acceptedDevices: PointerDevice.TouchScreen
+ onTapped: root.contextMenuRequested(link)
+ }
+ ToolTip {
+ visible: linkHH.hovered
+ delay: 1000
+ property string destFormat: qsTr("Page %1 location %2, %3 zoom %4")
+ text: page >= 0 ?
+ destFormat.arg(page + 1).arg(location.x.toFixed(1)).arg(location.y.toFixed(1)).arg(zoom) :
+ url
+ }
+}
diff --git a/src/pdfquick/PdfMultiPageView.qml b/src/pdfquick/PdfMultiPageView.qml
index a718823fa..2756e1fee 100644
--- a/src/pdfquick/PdfMultiPageView.qml
+++ b/src/pdfquick/PdfMultiPageView.qml
@@ -508,45 +508,19 @@ Item {
document: root.document
page: image.currentFrame
}
- delegate: Shape {
- required property rect rectangle
- required property url url
- required property int page
- required property point location
- required property real zoom
+ delegate: PdfLinkDelegate {
x: rectangle.x * paper.pageScale
y: rectangle.y * paper.pageScale
width: rectangle.width * paper.pageScale
height: rectangle.height * paper.pageScale
visible: image.status === Image.Ready
- ShapePath {
- strokeWidth: style.linkUnderscoreStrokeWidth
- strokeColor: style.linkUnderscoreColor
- strokeStyle: style.linkUnderscoreStrokeStyle
- dashPattern: style.linkUnderscoreDashPattern
- startX: 0; startY: height
- PathLine { x: width; y: height }
- }
- HoverHandler {
- id: linkHH
- cursorShape: Qt.PointingHandCursor
- }
- TapHandler {
- onTapped: {
- if (page >= 0)
- root.goToLocation(page, location, zoom)
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ root.goToLocation(link.page, link.location, link.zoom)
else
Qt.openUrlExternally(url)
}
- }
- ToolTip {
- visible: linkHH.hovered
- delay: 1000
- text: page >= 0 ?
- ("page " + (page + 1) +
- " location " + location.x.toFixed(1) + ", " + location.y.toFixed(1) +
- " zoom " + zoom) : url
- }
}
}
PdfSelection {
diff --git a/src/pdfquick/PdfPageView.qml b/src/pdfquick/PdfPageView.qml
index 387981ca6..ab796ce55 100644
--- a/src/pdfquick/PdfPageView.qml
+++ b/src/pdfquick/PdfPageView.qml
@@ -433,20 +433,19 @@ Rectangle {
document: root.document
page: pageNavigator.currentPage
}
- delegate: Item {
+ delegate: PdfLinkDelegate {
x: rectangle.x * image.pageScale
y: rectangle.y * image.pageScale
width: rectangle.width * image.pageScale
height: rectangle.height * image.pageScale
- HoverHandler { cursorShape: Qt.PointingHandCursor }
- TapHandler {
- onTapped: {
- if (page >= 0)
- pageNavigator.jump(page, Qt.point(0, 0), root.renderScale)
+ visible: image.status === Image.Ready
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ pageNavigator.jump(link)
else
Qt.openUrlExternally(url)
}
- }
}
}
diff --git a/src/pdfquick/PdfScrollablePageView.qml b/src/pdfquick/PdfScrollablePageView.qml
index 65cd8bd0a..b12b622bc 100644
--- a/src/pdfquick/PdfScrollablePageView.qml
+++ b/src/pdfquick/PdfScrollablePageView.qml
@@ -441,45 +441,19 @@ Flickable {
document: root.document
page: pageNavigator.currentPage
}
- delegate: Shape {
- required property rect rectangle
- required property url url
- required property int page
- required property point location
- required property real zoom
+ delegate: PdfLinkDelegate {
x: rectangle.x * image.pageScale
y: rectangle.y * image.pageScale
width: rectangle.width * image.pageScale
height: rectangle.height * image.pageScale
visible: image.status === Image.Ready
- ShapePath {
- strokeWidth: style.linkUnderscoreStrokeWidth
- strokeColor: style.linkUnderscoreColor
- strokeStyle: style.linkUnderscoreStrokeStyle
- dashPattern: style.linkUnderscoreDashPattern
- startX: 0; startY: height
- PathLine { x: width; y: height }
- }
- HoverHandler {
- id: linkHH
- cursorShape: Qt.PointingHandCursor
- }
- TapHandler {
- onTapped: {
- if (page >= 0)
- pageNavigator.jump(page, Qt.point(0, 0), root.renderScale)
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ pageNavigator.jump(link.page, link.location, link.zoom)
else
Qt.openUrlExternally(url)
}
- }
- ToolTip {
- visible: linkHH.hovered
- delay: 1000
- text: page >= 0 ?
- ("page " + (page + 1) +
- " location " + location.x.toFixed(1) + ", " + location.y.toFixed(1) +
- " zoom " + zoom) : url
- }
}
}
DragHandler {
diff --git a/src/pdfquick/PdfStyle.qml b/src/pdfquick/PdfStyle.qml
index 5ce2d436c..8b9d4be22 100644
--- a/src/pdfquick/PdfStyle.qml
+++ b/src/pdfquick/PdfStyle.qml
@@ -49,8 +49,4 @@ QtObject {
property color pageSearchResultsColor: "#80B0C4DE"
property color currentSearchResultStrokeColor: "cyan"
property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: palette.link
- property real linkUnderscoreStrokeWidth: -1 // no underlines under hyperlinks
- property int linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
}