summaryrefslogtreecommitdiffstats
path: root/src/pdfquick
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdfquick')
-rw-r--r--src/pdfquick/+Material/PdfStyle.qml15
-rw-r--r--src/pdfquick/+Universal/PdfStyle.qml15
-rw-r--r--src/pdfquick/CMakeLists.txt41
-rw-r--r--src/pdfquick/PdfLinkDelegate.qml74
-rw-r--r--src/pdfquick/PdfMultiPageView.qml623
-rw-r--r--src/pdfquick/PdfPageView.qml439
-rw-r--r--src/pdfquick/PdfScrollablePageView.qml487
-rw-r--r--src/pdfquick/PdfStyle.qml71
-rw-r--r--src/pdfquick/doc/src/qtquickpdf-module.qdoc18
-rw-r--r--src/pdfquick/plugin.cpp99
-rw-r--r--src/pdfquick/plugins.qmltypes52
-rw-r--r--src/pdfquick/qml/+material/PdfStyle.qml54
-rw-r--r--src/pdfquick/qml/+universal/PdfStyle.qml55
-rw-r--r--src/pdfquick/qml/PdfMultiPageView.qml434
-rw-r--r--src/pdfquick/qml/PdfPageView.qml276
-rw-r--r--src/pdfquick/qml/PdfScrollablePageView.qml307
-rw-r--r--src/pdfquick/qml/PdfStyle.qml54
-rw-r--r--src/pdfquick/qquickpdfbookmarkmodel.cpp55
-rw-r--r--src/pdfquick/qquickpdfbookmarkmodel_p.h53
-rw-r--r--src/pdfquick/qquickpdfdocument.cpp172
-rw-r--r--src/pdfquick/qquickpdfdocument_p.h131
-rw-r--r--src/pdfquick/qquickpdflinkmodel.cpp64
-rw-r--r--src/pdfquick/qquickpdflinkmodel_p.h51
-rw-r--r--src/pdfquick/qquickpdfnavigationstack.cpp272
-rw-r--r--src/pdfquick/qquickpdfnavigationstack_p.h103
-rw-r--r--src/pdfquick/qquickpdfpageimage.cpp141
-rw-r--r--src/pdfquick/qquickpdfpageimage_p.h52
-rw-r--r--src/pdfquick/qquickpdfpagenavigator.cpp130
-rw-r--r--src/pdfquick/qquickpdfpagenavigator_p.h55
-rw-r--r--src/pdfquick/qquickpdfsearchmodel.cpp179
-rw-r--r--src/pdfquick/qquickpdfsearchmodel_p.h49
-rw-r--r--src/pdfquick/qquickpdfselection.cpp177
-rw-r--r--src/pdfquick/qquickpdfselection_p.h71
-rw-r--r--src/pdfquick/qquicktableviewextra.cpp78
-rw-r--r--src/pdfquick/qquicktableviewextra_p.h93
-rw-r--r--src/pdfquick/qtpdfquickglobal_p.h40
36 files changed, 2592 insertions, 2488 deletions
diff --git a/src/pdfquick/+Material/PdfStyle.qml b/src/pdfquick/+Material/PdfStyle.qml
new file mode 100644
index 000000000..0728616a2
--- /dev/null
+++ b/src/pdfquick/+Material/PdfStyle.qml
@@ -0,0 +1,15 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+import QtQuick
+import QtQuick.Controls.Material
+
+QtObject {
+ property SystemPalette palette: SystemPalette { }
+ function withAlpha(color, alpha) {
+ return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
+ }
+ property color selectionColor: withAlpha(palette.highlight, 0.5)
+ property color pageSearchResultsColor: withAlpha(Qt.lighter(Material.accentColor, 1.5), 0.5)
+ property color currentSearchResultStrokeColor: Material.accentColor
+ property real currentSearchResultStrokeWidth: 2
+}
diff --git a/src/pdfquick/+Universal/PdfStyle.qml b/src/pdfquick/+Universal/PdfStyle.qml
new file mode 100644
index 000000000..4c559f068
--- /dev/null
+++ b/src/pdfquick/+Universal/PdfStyle.qml
@@ -0,0 +1,15 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+import QtQuick
+import QtQuick.Controls.Universal
+
+QtObject {
+ property SystemPalette palette: SystemPalette { }
+ function withAlpha(color, alpha) {
+ return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
+ }
+ property color selectionColor: withAlpha(palette.highlight, 0.5)
+ property color pageSearchResultsColor: withAlpha(Qt.lighter(Universal.accent, 1.5), 0.5)
+ property color currentSearchResultStrokeColor: Universal.accent
+ property real currentSearchResultStrokeWidth: 2
+}
diff --git a/src/pdfquick/CMakeLists.txt b/src/pdfquick/CMakeLists.txt
index 5bbe66959..d57ce04aa 100644
--- a/src/pdfquick/CMakeLists.txt
+++ b/src/pdfquick/CMakeLists.txt
@@ -1,32 +1,32 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Qml Quick)
set(qml_files
-# TODO:
-# "qml/+material/PdfStyle.qml"
-# "qml/+universal/PdfStyle.qml"
- "qml/PdfMultiPageView.qml"
- "qml/PdfPageView.qml"
- "qml/PdfScrollablePageView.qml"
- "qml/PdfStyle.qml"
+ "+Material/PdfStyle.qml"
+ "+Universal/PdfStyle.qml"
+ "PdfLinkDelegate.qml"
+ "PdfMultiPageView.qml"
+ "PdfPageView.qml"
+ "PdfScrollablePageView.qml"
+ "PdfStyle.qml"
)
qt_internal_add_qml_module(PdfQuick
URI "QtQuick.Pdf"
VERSION "${PROJECT_VERSION}"
- CLASS_NAME QtQuick2PdfPlugin
- NO_GENERATE_PLUGIN_SOURCE
- NO_PLUGIN_OPTIONAL
- NO_GENERATE_QMLTYPES
- PLUGIN_TARGET qtpdfquickplugin
+ PAST_MAJOR_VERSIONS 5
QML_FILES ${qml_files}
- DEPENDENCIES QtQuickControls2
+ DEPENDENCIES QtQuick/auto
SOURCES
+ qquickpdfbookmarkmodel.cpp qquickpdfbookmarkmodel_p.h
qquickpdfdocument.cpp qquickpdfdocument_p.h
qquickpdflinkmodel.cpp qquickpdflinkmodel_p.h
- qquickpdfnavigationstack.cpp qquickpdfnavigationstack_p.h
+ qquickpdfpagenavigator.cpp qquickpdfpagenavigator_p.h
+ qquickpdfpageimage.cpp qquickpdfpageimage_p.h
qquickpdfsearchmodel.cpp qquickpdfsearchmodel_p.h
qquickpdfselection.cpp qquickpdfselection_p.h
- qquicktableviewextra.cpp qquicktableviewextra_p.h
qtpdfquickglobal_p.h
INCLUDE_DIRECTORIES
../3rdparty/chromium
@@ -36,15 +36,6 @@ qt_internal_add_qml_module(PdfQuick
Qt::Core
Qt::Gui
Qt::Qml
+ NO_GENERATE_CPP_EXPORTS
)
-qt_internal_extend_target(qtpdfquickplugin
- SOURCES
- plugin.cpp
- LIBRARIES
- Qt::CorePrivate
- Qt::PdfQuickPrivate
-)
-
-
-
diff --git a/src/pdfquick/PdfLinkDelegate.qml b/src/pdfquick/PdfLinkDelegate.qml
new file mode 100644
index 000000000..4ac54d161
--- /dev/null
+++ b/src/pdfquick/PdfLinkDelegate.qml
@@ -0,0 +1,74 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+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. The \a link argument is an
+ instance of QPdfLink with information about the hyperlink.
+ */
+ signal tapped(var link)
+
+ /*!
+ \qmlsignal PdfLinkDelegate::contextMenuRequested(link)
+
+ Emitted on mouse right-click or touch long-press. The \a link argument
+ is an instance of QPdfLink with information about the hyperlink.
+ */
+ signal contextMenuRequested(var link)
+
+ HoverHandler {
+ id: linkHH
+ cursorShape: Qt.PointingHandCursor
+ }
+ TapHandler {
+ gesturePolicy: TapHandler.ReleaseWithinBounds
+ onTapped: root.tapped(root.link)
+ }
+ TapHandler {
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
+ acceptedButtons: Qt.RightButton
+ gesturePolicy: TapHandler.ReleaseWithinBounds
+ onTapped: root.contextMenuRequested(root.link)
+ }
+ TapHandler {
+ acceptedDevices: PointerDevice.TouchScreen
+ onLongPressed: root.contextMenuRequested(root.link)
+ }
+ ToolTip {
+ visible: linkHH.hovered
+ delay: 1000
+ property string destFormat: qsTr("Page %1 location %2, %3 zoom %4")
+ text: root.page >= 0 ?
+ destFormat.arg(root.page + 1).arg(root.location.x.toFixed(1))
+ .arg(root.location.y.toFixed(1)).arg(root.zoom) :
+ root.url
+ }
+}
diff --git a/src/pdfquick/PdfMultiPageView.qml b/src/pdfquick/PdfMultiPageView.qml
new file mode 100644
index 000000000..194d7866e
--- /dev/null
+++ b/src/pdfquick/PdfMultiPageView.qml
@@ -0,0 +1,623 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Pdf
+import QtQuick.Shapes
+
+/*!
+ \qmltype PdfMultiPageView
+ \inqmlmodule QtQuick.Pdf
+ \brief A complete PDF viewer component for scrolling through multiple pages.
+
+ PdfMultiPageView provides a PDF viewer component that offers a user
+ experience similar to many common PDF viewer applications. It supports
+ flicking through the pages in the entire document, with narrow gaps between
+ the page images.
+
+ PdfMultiPageView also supports selecting text and copying it to the
+ clipboard, zooming in and out, clicking an internal link to jump to another
+ section in the document, rotating the view, and searching for text. The
+ \l {PDF Multipage Viewer Example} demonstrates how to use these features
+ in an application.
+
+ The implementation is a QML assembly of smaller building blocks that are
+ available separately. In case you want to make changes in your own version
+ of this component, you can copy the QML, which is installed into the
+ \c QtQuick/Pdf/qml module directory, and modify it as needed.
+
+ \sa PdfPageView, PdfScrollablePageView, PdfStyle
+*/
+Item {
+ /*!
+ \qmlproperty PdfDocument PdfMultiPageView::document
+
+ A PdfDocument object with a valid \c source URL is required:
+
+ \snippet multipageview.qml 0
+ */
+ required property PdfDocument document
+
+ /*!
+ \qmlproperty PdfDocument PdfMultiPageView::selectedText
+
+ The selected text.
+ */
+ property string selectedText
+
+ /*!
+ \qmlmethod void PdfMultiPageView::selectAll()
+
+ Selects all the text on the \l {currentPage}{current page}, and makes it
+ available as the system \l {QClipboard::Selection}{selection} on systems
+ that support that feature.
+
+ \sa copySelectionToClipboard()
+ */
+ function selectAll() {
+ const currentItem = tableView.itemAtCell(tableView.cellAtPos(root.width / 2, root.height / 2))
+ const pdfSelection = currentItem?.selection as PdfSelection
+ pdfSelection?.selectAll()
+ }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::copySelectionToClipboard()
+
+ Copies the selected text (if any) to the
+ \l {QClipboard::Clipboard}{system clipboard}.
+
+ \sa selectAll()
+ */
+ function copySelectionToClipboard() {
+ const currentItem = tableView.itemAtCell(tableView.cellAtPos(root.width / 2, root.height / 2))
+ const pdfSelection = currentItem?.selection as PdfSelection
+ console.log(lcMPV, "currentItem", currentItem, "sel", pdfSelection?.text)
+ pdfSelection?.copyToClipboard()
+ }
+
+ // --------------------------------
+ // page navigation
+
+ /*!
+ \qmlproperty int PdfMultiPageView::currentPage
+ \readonly
+
+ This property holds the zero-based page number of the page visible in the
+ scrollable view. If there is no current page, it holds -1.
+
+ This property is read-only, and is typically used in a binding (or
+ \c onCurrentPageChanged script) to update the part of the user interface
+ that shows the current page number, such as a \l SpinBox.
+
+ \sa PdfPageNavigator::currentPage
+ */
+ property alias currentPage: pageNavigator.currentPage
+
+ /*!
+ \qmlproperty bool PdfMultiPageView::backEnabled
+ \readonly
+
+ This property indicates if it is possible to go back in the navigation
+ history to a previous-viewed page.
+
+ \sa PdfPageNavigator::backAvailable, back()
+ */
+ property alias backEnabled: pageNavigator.backAvailable
+
+ /*!
+ \qmlproperty bool PdfMultiPageView::forwardEnabled
+ \readonly
+
+ This property indicates if it is possible to go to next location in the
+ navigation history.
+
+ \sa PdfPageNavigator::forwardAvailable, forward()
+ */
+ property alias forwardEnabled: pageNavigator.forwardAvailable
+
+ /*!
+ \qmlmethod void PdfMultiPageView::back()
+
+ Scrolls the view back to the previous page that the user visited most
+ recently; or does nothing if there is no previous location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::back(), currentPage, backEnabled
+ */
+ function back() { pageNavigator.back() }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::forward()
+
+ Scrolls the view to the page that the user was viewing when the back()
+ method was called; or does nothing if there is no "next" location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::forward(), currentPage
+ */
+ function forward() { pageNavigator.forward() }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::goToPage(int page)
+
+ Scrolls the view to the given \a page number, if possible.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToPage(page) {
+ if (page === pageNavigator.currentPage)
+ return
+ goToLocation(page, Qt.point(-1, -1), 0)
+ }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::goToLocation(int page, point location, real zoom)
+
+ Scrolls the view to the \a location on the \a page, if possible,
+ and sets the \a zoom level.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToLocation(page, location, zoom) {
+ if (tableView.rows === 0) {
+ // save this request for later
+ tableView.pendingRow = page
+ tableView.pendingLocation = location
+ tableView.pendingZoom = zoom
+ return
+ }
+ if (zoom > 0) {
+ pageNavigator.jumping = true // don't call pageNavigator.update() because we will jump() instead
+ root.renderScale = zoom
+ pageNavigator.jumping = false
+ }
+ pageNavigator.jump(page, location, zoom) // actually jump
+ }
+
+ /*!
+ \qmlproperty int PdfMultiPageView::currentPageRenderingStatus
+
+ This property holds the \l {QtQuick::Image::status}{rendering status} of
+ the \l {currentPage}{current page}.
+ */
+ property int currentPageRenderingStatus: Image.Null
+
+ // --------------------------------
+ // page scaling
+
+ /*!
+ \qmlproperty real PdfMultiPageView::renderScale
+
+ This property holds the ratio of pixels to points. The default is \c 1,
+ meaning one point (1/72 of an inch) equals 1 logical pixel.
+ */
+ property real renderScale: 1
+
+ /*!
+ \qmlproperty real PdfMultiPageView::pageRotation
+
+ This property holds the clockwise rotation of the pages.
+
+ The default value is \c 0 degrees (that is, no rotation relative to the
+ orientation of the pages as stored in the PDF file).
+ */
+ property real pageRotation: 0
+
+ /*!
+ \qmlmethod void PdfMultiPageView::resetScale()
+
+ Sets \l renderScale back to its default value of \c 1.
+ */
+ function resetScale() { root.renderScale = 1 }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::scaleToWidth(real width, real height)
+
+ Sets \l renderScale such that the width of the first page will fit into a
+ viewport with the given \a width and \a height. If the page is not rotated,
+ it will be scaled so that its width fits \a width. If it is rotated +/- 90
+ degrees, it will be scaled so that its width fits \a height.
+ */
+ function scaleToWidth(width, height) {
+ root.renderScale = width / (tableView.rot90 ? tableView.firstPagePointSize.height : tableView.firstPagePointSize.width)
+ }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::scaleToPage(real width, real height)
+
+ Sets \l renderScale such that the whole first page will fit into a viewport
+ with the given \a width and \a height. The resulting \l renderScale depends
+ on \l pageRotation: the page will fit into the viewport at a larger size if
+ it is first rotated to have a matching aspect ratio.
+ */
+ function scaleToPage(width, height) {
+ const windowAspect = width / height
+ const pageAspect = tableView.firstPagePointSize.width / tableView.firstPagePointSize.height
+ if (tableView.rot90) {
+ if (windowAspect > pageAspect) {
+ root.renderScale = height / tableView.firstPagePointSize.width
+ } else {
+ root.renderScale = width / tableView.firstPagePointSize.height
+ }
+ } else {
+ if (windowAspect > pageAspect) {
+ root.renderScale = height / tableView.firstPagePointSize.height
+ } else {
+ root.renderScale = width / tableView.firstPagePointSize.width
+ }
+ }
+ }
+
+ // --------------------------------
+ // text search
+
+ /*!
+ \qmlproperty PdfSearchModel PdfMultiPageView::searchModel
+
+ This property holds a PdfSearchModel containing the list of search results
+ for a given \l searchString.
+
+ \sa PdfSearchModel
+ */
+ property alias searchModel: searchModel
+
+ /*!
+ \qmlproperty string PdfMultiPageView::searchString
+
+ This property holds the search string that the user may choose to search
+ for. It is typically used in a binding to the \c text property of a
+ TextField.
+
+ \sa searchModel
+ */
+ property alias searchString: searchModel.searchString
+
+ /*!
+ \qmlmethod void PdfMultiPageView::searchBack()
+
+ Decrements the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the previous search result.
+ */
+ function searchBack() { --searchModel.currentResult }
+
+ /*!
+ \qmlmethod void PdfMultiPageView::searchForward()
+
+ Increments the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the next search result.
+ */
+ function searchForward() { ++searchModel.currentResult }
+
+ LoggingCategory {
+ id: lcMPV
+ name: "qt.pdf.multipageview"
+ }
+
+ id: root
+ PdfStyle { id: style }
+ TableView {
+ id: tableView
+ property bool debug: false
+ property real minScale: 0.1
+ property real maxScale: 10
+ property point jumpLocationMargin: Qt.point(10, 10) // px away from viewport edges
+ anchors.fill: parent
+ anchors.leftMargin: 2
+ model: root.document ? root.document.pageCount : 0
+ rowSpacing: 6
+ property real rotationNorm: Math.round((360 + (root.pageRotation % 360)) % 360)
+ property bool rot90: rotationNorm == 90 || rotationNorm == 270
+ onRot90Changed: forceLayout()
+ onHeightChanged: forceLayout()
+ onWidthChanged: forceLayout()
+ property size firstPagePointSize: root.document?.status === PdfDocument.Ready ? root.document.pagePointSize(0) : Qt.size(1, 1)
+ property real pageHolderWidth: Math.max(root.width, ((rot90 ? root.document?.maxPageHeight : root.document?.maxPageWidth) ?? 0) * root.renderScale)
+ columnWidthProvider: function(col) { return root.document ? pageHolderWidth + vscroll.width + 2 : 0 }
+ rowHeightProvider: function(row) { return (rot90 ? root.document.pagePointSize(row).width : root.document.pagePointSize(row).height) * root.renderScale }
+
+ // delayed-jump feature in case the user called goToPage() or goToLocation() too early
+ property int pendingRow: -1
+ property point pendingLocation
+ property real pendingZoom: -1
+ onRowsChanged: {
+ if (rows > 0 && tableView.pendingRow >= 0) {
+ console.log(lcMPV, "initiating delayed jump to page", tableView.pendingRow, "loc", tableView.pendingLocation, "zoom", tableView.pendingZoom)
+ root.goToLocation(tableView.pendingRow, tableView.pendingLocation, tableView.pendingZoom)
+ tableView.pendingRow = -1
+ tableView.pendingLocation = Qt.point(-1, -1)
+ tableView.pendingZoom = -1
+ }
+ }
+
+ delegate: Rectangle {
+ id: pageHolder
+ required property int index
+ color: tableView.debug ? "beige" : "transparent"
+ Text {
+ visible: tableView.debug
+ anchors { right: parent.right; verticalCenter: parent.verticalCenter }
+ rotation: -90; text: pageHolder.width.toFixed(1) + "x" + pageHolder.height.toFixed(1) + "\n" +
+ image.width.toFixed(1) + "x" + image.height.toFixed(1)
+ }
+ property alias selection: selection
+ Rectangle {
+ id: paper
+ width: image.width
+ height: image.height
+ rotation: root.pageRotation
+ anchors.centerIn: pinch.active ? undefined : parent
+ property size pagePointSize: root.document.pagePointSize(pageHolder.index)
+ property real pageScale: image.paintedWidth / pagePointSize.width
+ PdfPageImage {
+ id: image
+ document: root.document
+ currentFrame: pageHolder.index
+ asynchronous: true
+ fillMode: Image.PreserveAspectFit
+ width: paper.pagePointSize.width * root.renderScale
+ height: paper.pagePointSize.height * root.renderScale
+ property real renderScale: root.renderScale
+ property real oldRenderScale: 1
+ onRenderScaleChanged: {
+ image.sourceSize.width = paper.pagePointSize.width * renderScale * Screen.devicePixelRatio
+ image.sourceSize.height = 0
+ paper.scale = 1
+ searchHighlights.update()
+ }
+ onStatusChanged: {
+ if (pageHolder.index === pageNavigator.currentPage)
+ root.currentPageRenderingStatus = status
+ }
+ }
+ Shape {
+ anchors.fill: parent
+ visible: image.status === Image.Ready
+ onVisibleChanged: searchHighlights.update()
+ ShapePath {
+ strokeWidth: -1
+ fillColor: style.pageSearchResultsColor
+ scale: Qt.size(paper.pageScale, paper.pageScale)
+ PathMultiline {
+ id: searchHighlights
+ function update() {
+ // paths could be a binding, but we need to be able to "kick" it sometimes
+ paths = searchModel.boundingPolygonsOnPage(pageHolder.index)
+ }
+ }
+ }
+ Connections {
+ target: searchModel
+ // whenever the highlights on the _current_ page change, they actually need to change on _all_ pages
+ // (usually because the search string has changed)
+ function onCurrentPageBoundingPolygonsChanged() { searchHighlights.update() }
+ }
+ ShapePath {
+ strokeWidth: -1
+ fillColor: style.selectionColor
+ scale: Qt.size(paper.pageScale, paper.pageScale)
+ PathMultiline {
+ paths: selection.geometry
+ }
+ }
+ }
+ Shape {
+ anchors.fill: parent
+ visible: image.status === Image.Ready && searchModel.currentPage === pageHolder.index
+ ShapePath {
+ strokeWidth: style.currentSearchResultStrokeWidth
+ strokeColor: style.currentSearchResultStrokeColor
+ fillColor: "transparent"
+ scale: Qt.size(paper.pageScale, paper.pageScale)
+ PathMultiline {
+ paths: searchModel.currentResultBoundingPolygons
+ }
+ }
+ }
+ PinchHandler {
+ id: pinch
+ minimumScale: tableView.minScale / root.renderScale
+ maximumScale: Math.max(1, tableView.maxScale / root.renderScale)
+ minimumRotation: root.pageRotation
+ maximumRotation: root.pageRotation
+ onActiveChanged:
+ if (active) {
+ paper.z = 10
+ } else {
+ paper.z = 0
+ const centroidInPoints = Qt.point(pinch.centroid.position.x / root.renderScale,
+ pinch.centroid.position.y / root.renderScale)
+ const centroidInFlickable = tableView.mapFromItem(paper, pinch.centroid.position.x, pinch.centroid.position.y)
+ const newSourceWidth = image.sourceSize.width * paper.scale
+ const ratio = newSourceWidth / image.sourceSize.width
+ console.log(lcMPV, "pinch ended on page", pageHolder.index,
+ "with scale", paper.scale.toFixed(3), "ratio", ratio.toFixed(3),
+ "centroid", pinch.centroid.position, centroidInPoints,
+ "wrt flickable", centroidInFlickable,
+ "page at", pageHolder.x.toFixed(2), pageHolder.y.toFixed(2),
+ "contentX/Y were", tableView.contentX.toFixed(2), tableView.contentY.toFixed(2))
+ if (ratio > 1.1 || ratio < 0.9) {
+ const centroidOnPage = Qt.point(centroidInPoints.x * root.renderScale * ratio, centroidInPoints.y * root.renderScale * ratio)
+ paper.scale = 1
+ pinch.persistentScale = 1
+ paper.x = 0
+ paper.y = 0
+ root.renderScale *= ratio
+ tableView.forceLayout()
+ if (tableView.rotationNorm == 0) {
+ tableView.contentX = pageHolder.x + tableView.originX + centroidOnPage.x - centroidInFlickable.x
+ tableView.contentY = pageHolder.y + tableView.originY + centroidOnPage.y - centroidInFlickable.y
+ } else if (tableView.rotationNorm == 90) {
+ tableView.contentX = pageHolder.x + tableView.originX + image.height - centroidOnPage.y - centroidInFlickable.x
+ tableView.contentY = pageHolder.y + tableView.originY + centroidOnPage.x - centroidInFlickable.y
+ } else if (tableView.rotationNorm == 180) {
+ tableView.contentX = pageHolder.x + tableView.originX + image.width - centroidOnPage.x - centroidInFlickable.x
+ tableView.contentY = pageHolder.y + tableView.originY + image.height - centroidOnPage.y - centroidInFlickable.y
+ } else if (tableView.rotationNorm == 270) {
+ tableView.contentX = pageHolder.x + tableView.originX + centroidOnPage.y - centroidInFlickable.x
+ tableView.contentY = pageHolder.y + tableView.originY + image.width - centroidOnPage.x - centroidInFlickable.y
+ }
+ console.log(lcMPV, "contentX/Y adjusted to", tableView.contentX.toFixed(2), tableView.contentY.toFixed(2), "y @top", pageHolder.y)
+ tableView.returnToBounds()
+ }
+ }
+ grabPermissions: PointerHandler.CanTakeOverFromAnything
+ }
+ DragHandler {
+ id: textSelectionDrag
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ target: null
+ }
+ TapHandler {
+ id: mouseClickHandler
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ }
+ TapHandler {
+ id: touchTapHandler
+ acceptedDevices: PointerDevice.TouchScreen
+ onTapped: {
+ selection.clear()
+ selection.forceActiveFocus()
+ }
+ }
+ Repeater {
+ model: PdfLinkModel {
+ id: linkModel
+ document: root.document
+ page: image.currentFrame
+ }
+ 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
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ root.goToLocation(link.page, link.location, link.zoom)
+ else
+ Qt.openUrlExternally(url)
+ }
+ }
+ }
+ PdfSelection {
+ id: selection
+ anchors.fill: parent
+ document: root.document
+ page: image.currentFrame
+ renderScale: image.renderScale
+ from: textSelectionDrag.centroid.pressPosition
+ to: textSelectionDrag.centroid.position
+ hold: !textSelectionDrag.active && !mouseClickHandler.pressed
+ onTextChanged: root.selectedText = text
+ focus: true
+ }
+ }
+ }
+ ScrollBar.vertical: ScrollBar {
+ id: vscroll
+ property bool moved: false
+ onPositionChanged: moved = true
+ onPressedChanged: if (pressed) {
+ // When the user starts scrolling, push the location where we came from so the user can go "back" there
+ const cell = tableView.cellAtPos(root.width / 2, root.height / 2)
+ const currentItem = tableView.itemAtCell(cell)
+ const currentLocation = currentItem
+ ? Qt.point((tableView.contentX - currentItem.x + tableView.jumpLocationMargin.x) / root.renderScale,
+ (tableView.contentY - currentItem.y + tableView.jumpLocationMargin.y) / root.renderScale)
+ : Qt.point(0, 0) // maybe the delegate wasn't loaded yet
+ pageNavigator.jump(cell.y, currentLocation, root.renderScale)
+ }
+ onActiveChanged: if (!active ) {
+ // When the scrollbar stops moving, tell navstack where we are, so as to update currentPage etc.
+ const cell = tableView.cellAtPos(root.width / 2, root.height / 2)
+ const currentItem = tableView.itemAtCell(cell)
+ const currentLocation = currentItem
+ ? Qt.point((tableView.contentX - currentItem.x + tableView.jumpLocationMargin.x) / root.renderScale,
+ (tableView.contentY - currentItem.y + tableView.jumpLocationMargin.y) / root.renderScale)
+ : Qt.point(0, 0) // maybe the delegate wasn't loaded yet
+ pageNavigator.update(cell.y, currentLocation, root.renderScale)
+ }
+ }
+ ScrollBar.horizontal: ScrollBar { }
+ }
+ onRenderScaleChanged: {
+ // if pageNavigator.jumped changes the scale, don't turn around and update the stack again;
+ // and don't force layout either, because positionViewAtCell() will do that
+ if (pageNavigator.jumping)
+ return
+ // page size changed: TableView needs to redo layout to avoid overlapping delegates or gaps between them
+ tableView.forceLayout()
+ const cell = tableView.cellAtPos(root.width / 2, root.height / 2)
+ const currentItem = tableView.itemAtCell(cell)
+ if (currentItem) {
+ const currentLocation = Qt.point((tableView.contentX - currentItem.x + tableView.jumpLocationMargin.x) / root.renderScale,
+ (tableView.contentY - currentItem.y + tableView.jumpLocationMargin.y) / root.renderScale)
+ pageNavigator.update(cell.y, currentLocation, renderScale)
+ }
+ }
+ PdfPageNavigator {
+ id: pageNavigator
+ property bool jumping: false
+ property int previousPage: 0
+ onJumped: function(current) {
+ jumping = true
+ if (current.zoom > 0)
+ root.renderScale = current.zoom
+ const pageSize = root.document.pagePointSize(current.page)
+ if (current.location.y < 0) {
+ // invalid to indicate that a specific location was not needed,
+ // so attempt to position the new page just as the current page is
+ const previousPageDelegate = tableView.itemAtCell(0, previousPage)
+ const currentYOffset = previousPageDelegate
+ ? tableView.contentY - previousPageDelegate.y
+ : 0
+ tableView.positionViewAtRow(current.page, Qt.AlignTop, currentYOffset)
+ console.log(lcMPV, "going from page", previousPage, "to", current.page, "offset", currentYOffset,
+ "ended up @", tableView.contentX.toFixed(1) + ", " + tableView.contentY.toFixed(1))
+ } else if (current.rectangles.length > 0) {
+ // jump to a search result and position the covered area within the viewport
+ pageSize.width *= root.renderScale
+ pageSize.height *= root.renderScale
+ const rectPts = current.rectangles[0]
+ const rectPx = Qt.rect(rectPts.x * root.renderScale - tableView.jumpLocationMargin.x,
+ rectPts.y * root.renderScale - tableView.jumpLocationMargin.y,
+ rectPts.width * root.renderScale + tableView.jumpLocationMargin.x * 2,
+ rectPts.height * root.renderScale + tableView.jumpLocationMargin.y * 2)
+ tableView.positionViewAtCell(0, current.page, TableView.Contain, Qt.point(0, 0), rectPx)
+ console.log(lcMPV, "going to zoom", root.renderScale, "rect", rectPx, "on page", current.page,
+ "ended up @", tableView.contentX.toFixed(1) + ", " + tableView.contentY.toFixed(1))
+ } else {
+ // jump to a page and position the given location relative to the top-left corner of the viewport
+ pageSize.width *= root.renderScale
+ pageSize.height *= root.renderScale
+ const rectPx = Qt.rect(current.location.x * root.renderScale - tableView.jumpLocationMargin.x,
+ current.location.y * root.renderScale - tableView.jumpLocationMargin.y,
+ tableView.jumpLocationMargin.x * 2, tableView.jumpLocationMargin.y * 2)
+ tableView.positionViewAtCell(0, current.page, TableView.AlignLeft | TableView.AlignTop, Qt.point(0, 0), rectPx)
+ console.log(lcMPV, "going to zoom", root.renderScale, "loc", current.location, "on page", current.page,
+ "ended up @", tableView.contentX.toFixed(1) + ", " + tableView.contentY.toFixed(1))
+ }
+ jumping = false
+ previousPage = current.page
+ }
+
+ property url documentSource: root.document.source
+ onDocumentSourceChanged: {
+ pageNavigator.clear()
+ root.resetScale()
+ tableView.contentX = 0
+ tableView.contentY = 0
+ }
+ }
+ PdfSearchModel {
+ id: searchModel
+ document: root.document === undefined ? null : root.document
+ onCurrentResultChanged: pageNavigator.jump(currentResultLink)
+ }
+}
diff --git a/src/pdfquick/PdfPageView.qml b/src/pdfquick/PdfPageView.qml
new file mode 100644
index 000000000..e1d97f57b
--- /dev/null
+++ b/src/pdfquick/PdfPageView.qml
@@ -0,0 +1,439 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Pdf
+import QtQuick.Shapes
+
+/*!
+ \qmltype PdfPageView
+ \inqmlmodule QtQuick.Pdf
+ \brief A PDF viewer component to show one page a time.
+
+ PdfPageView provides a PDF viewer component that shows one whole page at a
+ time, without scrolling. It supports selecting text and copying it to the
+ clipboard, zooming in and out, clicking an internal link to jump to another
+ section in the document, rotating the view, and searching for text.
+
+ The implementation is a QML assembly of smaller building blocks that are
+ available separately. In case you want to make changes in your own version
+ of this component, you can copy the QML, which is installed into the
+ \c QtQuick/Pdf/qml module directory, and modify it as needed.
+
+ \sa PdfScrollablePageView, PdfMultiPageView, PdfStyle
+*/
+Rectangle {
+ /*!
+ \qmlproperty PdfDocument PdfPageView::document
+
+ A PdfDocument object with a valid \c source URL is required:
+
+ \snippet pdfpageview.qml 0
+ */
+ required property PdfDocument document
+
+ /*!
+ \qmlproperty int PdfPageView::status
+
+ This property holds the \l {QtQuick::Image::status}{rendering status} of
+ the \l {currentPage}{current page}.
+ */
+ property alias status: image.status
+
+ /*!
+ \qmlproperty PdfDocument PdfPageView::selectedText
+
+ The selected text.
+ */
+ property alias selectedText: selection.text
+
+ /*!
+ \qmlmethod void PdfPageView::selectAll()
+
+ Selects all the text on the \l {currentPage}{current page}, and makes it
+ available as the system \l {QClipboard::Selection}{selection} on systems
+ that support that feature.
+
+ \sa copySelectionToClipboard()
+ */
+ function selectAll() {
+ selection.selectAll()
+ }
+
+ /*!
+ \qmlmethod void PdfPageView::copySelectionToClipboard()
+
+ Copies the selected text (if any) to the
+ \l {QClipboard::Clipboard}{system clipboard}.
+
+ \sa selectAll()
+ */
+ function copySelectionToClipboard() {
+ selection.copyToClipboard()
+ }
+
+ // --------------------------------
+ // page navigation
+
+ /*!
+ \qmlproperty int PdfPageView::currentPage
+ \readonly
+
+ This property holds the zero-based page number of the page visible in the
+ scrollable view. If there is no current page, it holds -1.
+
+ This property is read-only, and is typically used in a binding (or
+ \c onCurrentPageChanged script) to update the part of the user interface
+ that shows the current page number, such as a \l SpinBox.
+
+ \sa PdfPageNavigator::currentPage
+ */
+ property alias currentPage: pageNavigator.currentPage
+
+ /*!
+ \qmlproperty bool PdfPageView::backEnabled
+ \readonly
+
+ This property indicates if it is possible to go back in the navigation
+ history to a previous-viewed page.
+
+ \sa PdfPageNavigator::backAvailable, back()
+ */
+ property alias backEnabled: pageNavigator.backAvailable
+
+ /*!
+ \qmlproperty bool PdfPageView::forwardEnabled
+ \readonly
+
+ This property indicates if it is possible to go to next location in the
+ navigation history.
+
+ \sa PdfPageNavigator::forwardAvailable, forward()
+ */
+ property alias forwardEnabled: pageNavigator.forwardAvailable
+
+ /*!
+ \qmlmethod void PdfPageView::back()
+
+ Scrolls the view back to the previous page that the user visited most
+ recently; or does nothing if there is no previous location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::back(), currentPage, backEnabled
+ */
+ function back() { pageNavigator.back() }
+
+ /*!
+ \qmlmethod void PdfPageView::forward()
+
+ Scrolls the view to the page that the user was viewing when the back()
+ method was called; or does nothing if there is no "next" location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::forward(), currentPage
+ */
+ function forward() { pageNavigator.forward() }
+
+ /*!
+ \qmlmethod void PdfPageView::goToPage(int page)
+
+ Changes the view to the \a page, if possible.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToPage(page) { goToLocation(page, Qt.point(0, 0), 0) }
+
+ /*!
+ \qmlmethod void PdfPageView::goToLocation(int page, point location, real zoom)
+
+ Scrolls the view to the \a location on the \a page, if possible,
+ and sets the \a zoom level.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToLocation(page, location, zoom) {
+ if (zoom > 0)
+ root.renderScale = zoom
+ pageNavigator.jump(page, location, zoom)
+ }
+
+ // --------------------------------
+ // page scaling
+
+ /*!
+ \qmlproperty bool PdfPageView::zoomEnabled
+
+ This property holds whether the user can use the pinch gesture or
+ Control + mouse wheel to zoom. The default is \c true.
+
+ When the user zooms the page, the size of PdfPageView changes.
+ */
+ property bool zoomEnabled: true
+
+ /*!
+ \qmlproperty real PdfPageView::renderScale
+
+ This property holds the ratio of pixels to points. The default is \c 1,
+ meaning one point (1/72 of an inch) equals 1 logical pixel.
+ */
+ property real renderScale: 1
+
+ /*!
+ \qmlproperty size PdfPageView::sourceSize
+
+ This property holds the scaled width and height of the full-frame image.
+
+ \sa {QtQuick::Image::sourceSize}{Image.sourceSize}
+ */
+ property alias sourceSize: image.sourceSize
+
+ /*!
+ \qmlmethod void PdfPageView::resetScale()
+
+ Sets \l renderScale back to its default value of \c 1.
+ */
+ function resetScale() {
+ image.sourceSize.width = 0
+ image.sourceSize.height = 0
+ root.scale = 1
+ }
+
+ /*!
+ \qmlmethod void PdfPageView::scaleToWidth(real width, real height)
+
+ Sets \l renderScale such that the width of the first page will fit into a
+ viewport with the given \a width and \a height. If the page is not rotated,
+ it will be scaled so that its width fits \a width. If it is rotated +/- 90
+ degrees, it will be scaled so that its width fits \a height.
+ */
+ function scaleToWidth(width, height) {
+ const halfRotation = Math.abs(root.rotation % 180)
+ image.sourceSize = Qt.size((halfRotation > 45 && halfRotation < 135) ? height : width, 0)
+ image.centerInSize = Qt.size(width, height)
+ image.centerOnLoad = true
+ image.vCenterOnLoad = (halfRotation > 45 && halfRotation < 135)
+ root.scale = 1
+ }
+
+ /*!
+ \qmlmethod void PdfPageView::scaleToPage(real width, real height)
+
+ Sets \l renderScale such that the whole first page will fit into a viewport
+ with the given \a width and \a height. The resulting \l renderScale depends
+ on page rotation: the page will fit into the viewport at a larger size if it
+ is first rotated to have a matching aspect ratio.
+ */
+ function scaleToPage(width, height) {
+ const windowAspect = width / height
+ const halfRotation = Math.abs(root.rotation % 180)
+ const pagePointSize = document.pagePointSize(pageNavigator.currentPage)
+ const pageAspect = pagePointSize.height / pagePointSize.width
+ if (halfRotation > 45 && halfRotation < 135) {
+ // rotated 90 or 270º
+ if (windowAspect > pageAspect) {
+ image.sourceSize = Qt.size(height, 0)
+ } else {
+ image.sourceSize = Qt.size(0, width)
+ }
+ } else {
+ if (windowAspect > pageAspect) {
+ image.sourceSize = Qt.size(0, height)
+ } else {
+ image.sourceSize = Qt.size(width, 0)
+ }
+ }
+ image.centerInSize = Qt.size(width, height)
+ image.centerOnLoad = true
+ image.vCenterOnLoad = true
+ root.scale = 1
+ }
+
+ // --------------------------------
+ // text search
+
+ /*!
+ \qmlproperty PdfSearchModel PdfPageView::searchModel
+
+ This property holds a PdfSearchModel containing the list of search results
+ for a given \l searchString.
+
+ \sa PdfSearchModel
+ */
+ property alias searchModel: searchModel
+
+ /*!
+ \qmlproperty string PdfPageView::searchString
+
+ This property holds the search string that the user may choose to search
+ for. It is typically used in a binding to the \c text property of a
+ TextField.
+
+ \sa searchModel
+ */
+ property alias searchString: searchModel.searchString
+
+ /*!
+ \qmlmethod void PdfPageView::searchBack()
+
+ Decrements the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the previous search result.
+ */
+ function searchBack() { --searchModel.currentResult }
+
+ /*!
+ \qmlmethod void PdfPageView::searchForward()
+
+ Increments the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the next search result.
+ */
+ function searchForward() { ++searchModel.currentResult }
+
+ // --------------------------------
+ // implementation
+ id: root
+ width: image.width
+ height: image.height
+
+ PdfSelection {
+ id: selection
+ document: root.document
+ page: pageNavigator.currentPage
+ from: Qt.point(textSelectionDrag.centroid.pressPosition.x / image.pageScale, textSelectionDrag.centroid.pressPosition.y / image.pageScale)
+ to: Qt.point(textSelectionDrag.centroid.position.x / image.pageScale, textSelectionDrag.centroid.position.y / image.pageScale)
+ hold: !textSelectionDrag.active && !tapHandler.pressed
+ }
+
+ PdfSearchModel {
+ id: searchModel
+ document: root.document === undefined ? null : root.document
+ onCurrentPageChanged: root.goToPage(currentPage)
+ }
+
+ PdfPageNavigator {
+ id: pageNavigator
+ onCurrentPageChanged: searchModel.currentPage = currentPage
+ onCurrentZoomChanged: root.renderScale = currentZoom
+
+ property url documentSource: root.document.source
+ onDocumentSourceChanged: {
+ pageNavigator.clear()
+ root.goToPage(0)
+ }
+ }
+
+ PdfPageImage {
+ id: image
+ document: root.document
+ currentFrame: pageNavigator.currentPage
+ asynchronous: true
+ fillMode: Image.PreserveAspectFit
+ property bool centerOnLoad: false
+ property bool vCenterOnLoad: false
+ property size centerInSize
+ property real pageScale: image.paintedWidth / document.pagePointSize(pageNavigator.currentPage).width
+ function reRenderIfNecessary() {
+ const newSourceWidth = image.sourceSize.width * root.scale * Screen.devicePixelRatio
+ const ratio = newSourceWidth / image.sourceSize.width
+ if (ratio > 1.1 || ratio < 0.9) {
+ image.sourceSize.width = newSourceWidth
+ image.sourceSize.height = 0
+ root.scale = 1
+ }
+ }
+ onStatusChanged:
+ if (status == Image.Ready && centerOnLoad) {
+ root.x = (centerInSize.width - image.implicitWidth) / 2
+ root.y = vCenterOnLoad ? (centerInSize.height - image.implicitHeight) / 2 : 0
+ centerOnLoad = false
+ vCenterOnLoad = false
+ }
+ }
+ onRenderScaleChanged: {
+ image.sourceSize.width = document.pagePointSize(pageNavigator.currentPage).width * renderScale
+ image.sourceSize.height = 0
+ root.scale = 1
+ }
+
+ 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 {
+ fillColor: "orange"
+ scale: Qt.size(image.pageScale, image.pageScale)
+ PathMultiline {
+ paths: selection.geometry
+ }
+ }
+ }
+
+ Repeater {
+ model: PdfLinkModel {
+ id: linkModel
+ document: root.document
+ page: pageNavigator.currentPage
+ }
+ 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
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ pageNavigator.jump(link)
+ else
+ Qt.openUrlExternally(url)
+ }
+ }
+ }
+
+ PinchHandler {
+ id: pinch
+ enabled: root.zoomEnabled && root.scale * root.renderScale <= 10 && root.scale * root.renderScale >= 0.1
+ minimumScale: 0.1
+ maximumScale: 10
+ minimumRotation: 0
+ maximumRotation: 0
+ onActiveChanged: if (!active) image.reRenderIfNecessary()
+ grabPermissions: PinchHandler.TakeOverForbidden // don't allow takeover if pinch has started
+ }
+ WheelHandler {
+ enabled: pinch.enabled
+ acceptedModifiers: Qt.ControlModifier
+ property: "scale"
+ onActiveChanged: if (!active) image.reRenderIfNecessary()
+ }
+ DragHandler {
+ id: textSelectionDrag
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ target: null
+ }
+ TapHandler {
+ id: tapHandler
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ }
+}
diff --git a/src/pdfquick/PdfScrollablePageView.qml b/src/pdfquick/PdfScrollablePageView.qml
new file mode 100644
index 000000000..9fa0547c6
--- /dev/null
+++ b/src/pdfquick/PdfScrollablePageView.qml
@@ -0,0 +1,487 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Pdf
+import QtQuick.Shapes
+
+/*!
+ \qmltype PdfScrollablePageView
+ \inqmlmodule QtQuick.Pdf
+ \brief A complete PDF viewer component to show one page a time, with scrolling.
+
+ PdfScrollablePageView provides a PDF viewer component that shows one page
+ at a time, with scrollbars to move around the page. It also supports
+ selecting text and copying it to the clipboard, zooming in and out,
+ clicking an internal link to jump to another section in the document,
+ rotating the view, and searching for text. The pdfviewer example
+ demonstrates how to use these features in an application.
+
+ The implementation is a QML assembly of smaller building blocks that are
+ available separately. In case you want to make changes in your own version
+ of this component, you can copy the QML, which is installed into the
+ \c QtQuick/Pdf/qml module directory, and modify it as needed.
+
+ \sa PdfPageView, PdfMultiPageView, PdfStyle
+*/
+Flickable {
+ /*!
+ \qmlproperty PdfDocument PdfScrollablePageView::document
+
+ A PdfDocument object with a valid \c source URL is required:
+
+ \snippet multipageview.qml 0
+ */
+ required property PdfDocument document
+
+ /*!
+ \qmlproperty int PdfScrollablePageView::status
+
+ This property holds the \l {QtQuick::Image::status}{rendering status} of
+ the \l {currentPage}{current page}.
+ */
+ property alias status: image.status
+
+ /*!
+ \qmlproperty PdfDocument PdfScrollablePageView::selectedText
+
+ The selected text.
+ */
+ property alias selectedText: selection.text
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::selectAll()
+
+ Selects all the text on the \l {currentPage}{current page}, and makes it
+ available as the system \l {QClipboard::Selection}{selection} on systems
+ that support that feature.
+
+ \sa copySelectionToClipboard()
+ */
+ function selectAll() {
+ selection.selectAll()
+ }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::copySelectionToClipboard()
+
+ Copies the selected text (if any) to the
+ \l {QClipboard::Clipboard}{system clipboard}.
+
+ \sa selectAll()
+ */
+ function copySelectionToClipboard() {
+ selection.copyToClipboard()
+ }
+
+ // --------------------------------
+ // page navigation
+
+ /*!
+ \qmlproperty int PdfScrollablePageView::currentPage
+ \readonly
+
+ This property holds the zero-based page number of the page visible in the
+ scrollable view. If there is no current page, it holds -1.
+
+ This property is read-only, and is typically used in a binding (or
+ \c onCurrentPageChanged script) to update the part of the user interface
+ that shows the current page number, such as a \l SpinBox.
+
+ \sa PdfPageNavigator::currentPage
+ */
+ property alias currentPage: pageNavigator.currentPage
+
+ /*!
+ \qmlproperty bool PdfScrollablePageView::backEnabled
+ \readonly
+
+ This property indicates if it is possible to go back in the navigation
+ history to a previous-viewed page.
+
+ \sa PdfPageNavigator::backAvailable, back()
+ */
+ property alias backEnabled: pageNavigator.backAvailable
+
+ /*!
+ \qmlproperty bool PdfScrollablePageView::forwardEnabled
+ \readonly
+
+ This property indicates if it is possible to go to next location in the
+ navigation history.
+
+ \sa PdfPageNavigator::forwardAvailable, forward()
+ */
+ property alias forwardEnabled: pageNavigator.forwardAvailable
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::back()
+
+ Scrolls the view back to the previous page that the user visited most
+ recently; or does nothing if there is no previous location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::back(), currentPage, backEnabled
+ */
+ function back() { pageNavigator.back() }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::forward()
+
+ Scrolls the view to the page that the user was viewing when the back()
+ method was called; or does nothing if there is no "next" location on the
+ navigation stack.
+
+ \sa PdfPageNavigator::forward(), currentPage
+ */
+ function forward() { pageNavigator.forward() }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::goToPage(int page)
+
+ Changes the view to the \a page, if possible.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToPage(page) {
+ if (page === pageNavigator.currentPage)
+ return
+ goToLocation(page, Qt.point(0, 0), 0)
+ }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::goToLocation(int page, point location, real zoom)
+
+ Scrolls the view to the \a location on the \a page, if possible,
+ and sets the \a zoom level.
+
+ \sa PdfPageNavigator::jump(), currentPage
+ */
+ function goToLocation(page, location, zoom) {
+ if (zoom > 0)
+ root.renderScale = zoom
+ pageNavigator.jump(page, location, zoom)
+ }
+
+ // --------------------------------
+ // page scaling
+
+ /*!
+ \qmlproperty real PdfScrollablePageView::renderScale
+
+ This property holds the ratio of pixels to points. The default is \c 1,
+ meaning one point (1/72 of an inch) equals 1 logical pixel.
+ */
+ property real renderScale: 1
+
+ /*!
+ \qmlproperty real PdfScrollablePageView::pageRotation
+
+ This property holds the clockwise rotation of the pages.
+
+ The default value is \c 0 degrees (that is, no rotation relative to the
+ orientation of the pages as stored in the PDF file).
+ */
+ property real pageRotation: 0
+
+ /*!
+ \qmlproperty size PdfScrollablePageView::sourceSize
+
+ This property holds the scaled width and height of the full-frame image.
+
+ \sa {QtQuick::Image::sourceSize}{Image.sourceSize}
+ */
+ property alias sourceSize: image.sourceSize
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::resetScale()
+
+ Sets \l renderScale back to its default value of \c 1.
+ */
+ function resetScale() {
+ paper.scale = 1
+ root.renderScale = 1
+ }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::scaleToWidth(real width, real height)
+
+ Sets \l renderScale such that the width of the first page will fit into a
+ viewport with the given \a width and \a height. If the page is not rotated,
+ it will be scaled so that its width fits \a width. If it is rotated +/- 90
+ degrees, it will be scaled so that its width fits \a height.
+ */
+ function scaleToWidth(width, height) {
+ const pagePointSize = document.pagePointSize(pageNavigator.currentPage)
+ root.renderScale = root.width / (paper.rot90 ? pagePointSize.height : pagePointSize.width)
+ console.log(lcSPV, "scaling", pagePointSize, "to fit", root.width, "rotated?", paper.rot90, "scale", root.renderScale)
+ root.contentX = 0
+ root.contentY = 0
+ }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::scaleToPage(real width, real height)
+
+ Sets \l renderScale such that the whole first page will fit into a viewport
+ with the given \a width and \a height. The resulting \l renderScale depends
+ on \l pageRotation: the page will fit into the viewport at a larger size if
+ it is first rotated to have a matching aspect ratio.
+ */
+ function scaleToPage(width, height) {
+ const pagePointSize = document.pagePointSize(pageNavigator.currentPage)
+ root.renderScale = Math.min(
+ root.width / (paper.rot90 ? pagePointSize.height : pagePointSize.width),
+ root.height / (paper.rot90 ? pagePointSize.width : pagePointSize.height) )
+ root.contentX = 0
+ root.contentY = 0
+ }
+
+ // --------------------------------
+ // text search
+
+ /*!
+ \qmlproperty PdfSearchModel PdfScrollablePageView::searchModel
+
+ This property holds a PdfSearchModel containing the list of search results
+ for a given \l searchString.
+
+ \sa PdfSearchModel
+ */
+ property alias searchModel: searchModel
+
+ /*!
+ \qmlproperty string PdfScrollablePageView::searchString
+
+ This property holds the search string that the user may choose to search
+ for. It is typically used in a binding to the \c text property of a
+ TextField.
+
+ \sa searchModel
+ */
+ property alias searchString: searchModel.searchString
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::searchBack()
+
+ Decrements the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the previous search result.
+ */
+ function searchBack() { --searchModel.currentResult }
+
+ /*!
+ \qmlmethod void PdfScrollablePageView::searchForward()
+
+ Increments the
+ \l{PdfSearchModel::currentResult}{searchModel's current result}
+ so that the view will jump to the next search result.
+ */
+ function searchForward() { ++searchModel.currentResult }
+
+ // --------------------------------
+ // implementation
+ id: root
+ PdfStyle { id: style }
+ contentWidth: paper.width
+ contentHeight: paper.height
+ ScrollBar.vertical: ScrollBar {
+ onActiveChanged:
+ if (!active ) {
+ const currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
+ (root.contentY + root.height / 2) / root.renderScale)
+ pageNavigator.update(pageNavigator.currentPage, currentLocation, root.renderScale)
+ }
+ }
+ ScrollBar.horizontal: ScrollBar {
+ onActiveChanged:
+ if (!active ) {
+ const currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
+ (root.contentY + root.height / 2) / root.renderScale)
+ pageNavigator.update(pageNavigator.currentPage, currentLocation, root.renderScale)
+ }
+ }
+
+ onRenderScaleChanged: {
+ paper.scale = 1
+ const currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
+ (root.contentY + root.height / 2) / root.renderScale)
+ pageNavigator.update(pageNavigator.currentPage, currentLocation, root.renderScale)
+ }
+
+ PdfSearchModel {
+ id: searchModel
+ document: root.document === undefined ? null : root.document
+ onCurrentResultChanged: pageNavigator.jump(currentResultLink)
+ }
+
+ PdfPageNavigator {
+ id: pageNavigator
+ onJumped: function(current) {
+ root.renderScale = current.zoom
+ const dx = Math.max(0, current.location.x * root.renderScale - root.width / 2) - root.contentX
+ const dy = Math.max(0, current.location.y * root.renderScale - root.height / 2) - root.contentY
+ // don't jump if location is in the viewport already, i.e. if the "error" between desired and actual contentX/Y is small
+ if (Math.abs(dx) > root.width / 3)
+ root.contentX += dx
+ if (Math.abs(dy) > root.height / 3)
+ root.contentY += dy
+ console.log(lcSPV, "going to zoom", current.zoom, "loc", current.location,
+ "on page", current.page, "ended up @", root.contentX + ", " + root.contentY)
+ }
+ onCurrentPageChanged: searchModel.currentPage = currentPage
+
+ property url documentSource: root.document.source
+ onDocumentSourceChanged: {
+ pageNavigator.clear()
+ root.resetScale()
+ root.contentX = 0
+ root.contentY = 0
+ }
+ }
+
+ LoggingCategory {
+ id: lcSPV
+ name: "qt.pdf.singlepageview"
+ }
+
+ Rectangle {
+ id: paper
+ width: rot90 ? image.height : image.width
+ height: rot90 ? image.width : image.height
+ property real rotationModulus: Math.abs(root.pageRotation % 180)
+ property bool rot90: rotationModulus > 45 && rotationModulus < 135
+ property real minScale: 0.1
+ property real maxScale: 10
+
+ PdfPageImage {
+ id: image
+ document: root.document
+ currentFrame: pageNavigator.currentPage
+ asynchronous: true
+ fillMode: Image.PreserveAspectFit
+ rotation: root.pageRotation
+ anchors.centerIn: parent
+ property real pageScale: image.paintedWidth / document.pagePointSize(pageNavigator.currentPage).width
+ width: document.pagePointSize(pageNavigator.currentPage).width * root.renderScale
+ height: document.pagePointSize(pageNavigator.currentPage).height * root.renderScale
+ sourceSize.width: width * Screen.devicePixelRatio
+ sourceSize.height: 0
+
+ Shape {
+ anchors.fill: parent
+ visible: image.status === Image.Ready
+ ShapePath {
+ strokeWidth: -1
+ fillColor: style.pageSearchResultsColor
+ scale: Qt.size(image.pageScale, image.pageScale)
+ PathMultiline {
+ paths: searchModel.currentPageBoundingPolygons
+ }
+ }
+ ShapePath {
+ strokeWidth: style.currentSearchResultStrokeWidth
+ strokeColor: style.currentSearchResultStrokeColor
+ fillColor: "transparent"
+ scale: Qt.size(image.pageScale, image.pageScale)
+ PathMultiline {
+ paths: searchModel.currentResultBoundingPolygons
+ }
+ }
+ ShapePath {
+ fillColor: style.selectionColor
+ scale: Qt.size(image.pageScale, image.pageScale)
+ PathMultiline {
+ paths: selection.geometry
+ }
+ }
+ }
+
+ Repeater {
+ model: PdfLinkModel {
+ id: linkModel
+ document: root.document
+ page: pageNavigator.currentPage
+ }
+ 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
+ onTapped:
+ (link) => {
+ if (link.page >= 0)
+ pageNavigator.jump(link.page, link.location, link.zoom)
+ else
+ Qt.openUrlExternally(url)
+ }
+ }
+ }
+ DragHandler {
+ id: textSelectionDrag
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ target: null
+ }
+ TapHandler {
+ id: mouseClickHandler
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
+ }
+ TapHandler {
+ id: touchTapHandler
+ acceptedDevices: PointerDevice.TouchScreen
+ onTapped: {
+ selection.clear()
+ selection.focus = true
+ }
+ }
+ }
+
+ PdfSelection {
+ id: selection
+ anchors.fill: parent
+ document: root.document
+ page: pageNavigator.currentPage
+ renderScale: image.pageScale == 0 ? 1.0 : image.pageScale
+ from: textSelectionDrag.centroid.pressPosition
+ to: textSelectionDrag.centroid.position
+ hold: !textSelectionDrag.active && !mouseClickHandler.pressed
+ focus: true
+ }
+
+ PinchHandler {
+ id: pinch
+ minimumScale: paper.minScale / root.renderScale
+ maximumScale: Math.max(1, paper.maxScale / root.renderScale)
+ minimumRotation: 0
+ maximumRotation: 0
+ onActiveChanged:
+ if (!active) {
+ const centroidInPoints = Qt.point(pinch.centroid.position.x / root.renderScale,
+ pinch.centroid.position.y / root.renderScale)
+ const centroidInFlickable = root.mapFromItem(paper, pinch.centroid.position.x, pinch.centroid.position.y)
+ const newSourceWidth = image.sourceSize.width * paper.scale
+ const ratio = newSourceWidth / image.sourceSize.width
+ console.log(lcSPV, "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) {
+ const centroidOnPage = Qt.point(centroidInPoints.x * root.renderScale * ratio, centroidInPoints.y * root.renderScale * ratio)
+ paper.scale = 1
+ paper.x = 0
+ paper.y = 0
+ root.contentX = centroidOnPage.x - centroidInFlickable.x
+ root.contentY = centroidOnPage.y - centroidInFlickable.y
+ root.renderScale *= ratio // onRenderScaleChanged calls pageNavigator.update() so we don't need to here
+ console.log(lcSPV, "contentX/Y adjusted to", root.contentX.toFixed(2), root.contentY.toFixed(2))
+ } else {
+ paper.x = 0
+ paper.y = 0
+ }
+ }
+ grabPermissions: PointerHandler.CanTakeOverFromAnything
+ }
+ }
+}
diff --git a/src/pdfquick/PdfStyle.qml b/src/pdfquick/PdfStyle.qml
new file mode 100644
index 000000000..a22276143
--- /dev/null
+++ b/src/pdfquick/PdfStyle.qml
@@ -0,0 +1,71 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+import QtQuick
+
+/*!
+ \qmltype PdfStyle
+ \inqmlmodule QtQuick.Pdf
+ \brief A styling interface for the PDF viewer components.
+
+ PdfStyle provides properties to modify the appearance of PdfMultiPageView,
+ PdfScrollablePageView, and PdfPageView.
+
+ Default styles are provided to match the
+ \l {Styling Qt Quick Controls}{styles in Qt Quick Controls}.
+ \l {Using File Selectors with Qt Quick Controls}{File selectors}
+ are used to load the PDF style corresponding to the Controls style in use.
+ Custom styles are possible, using different \l {QFileSelector}{file selectors}.
+*/
+QtObject {
+ /*! \internal
+ \qmlproperty SystemPalette PdfStyle::palette
+ */
+ property SystemPalette palette: SystemPalette { }
+
+ /*! \internal
+ \qmlmethod color PdfStyle::withAlpha()
+ */
+ function withAlpha(color, alpha) {
+ return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
+ }
+
+ /*!
+ \qmlproperty color PdfStyle::selectionColor
+
+ The color of translucent rectangles that are overlaid on
+ \l {PdfMultiPageView::selectedText}{selected text}.
+
+ \sa PdfSelection
+ */
+ property color selectionColor: withAlpha(palette.highlight, 0.5)
+
+ /*!
+ \qmlproperty color PdfStyle::pageSearchResultsColor
+
+ The color of translucent rectangles that are overlaid on text that
+ matches the \l {PdfMultiPageView::searchString}{search string}.
+
+ \sa PdfSearchModel
+ */
+ property color pageSearchResultsColor: "#80B0C4DE"
+
+ /*!
+ \qmlproperty color PdfStyle::currentSearchResultStrokeColor
+
+ The color of the box outline around the
+ \l {PdfSearchModel::currentResult}{current search result}.
+
+ \sa PdfMultiPageView::searchBack(), PdfMultiPageView::searchForward(), PdfSearchModel::currentResult
+ */
+ property color currentSearchResultStrokeColor: "cyan"
+
+ /*!
+ \qmlproperty real PdfStyle::currentSearchResultStrokeWidth
+
+ The line width of the box outline around the
+ \l {PdfSearchModel::currentResult}{current search result}.
+
+ \sa PdfMultiPageView::searchBack(), PdfMultiPageView::searchForward(), PdfSearchModel::currentResult
+ */
+ property real currentSearchResultStrokeWidth: 2
+}
diff --git a/src/pdfquick/doc/src/qtquickpdf-module.qdoc b/src/pdfquick/doc/src/qtquickpdf-module.qdoc
new file mode 100644
index 000000000..a4ca0d9e8
--- /dev/null
+++ b/src/pdfquick/doc/src/qtquickpdf-module.qdoc
@@ -0,0 +1,18 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \qmlmodule QtQuick.Pdf
+ \title Qt Quick PDF QML Types
+ \ingroup qmlmodules
+ \brief Provides QML types for handling PDF documents.
+ \since 5.14
+
+ This QML module contains types for handling PDF documents.
+
+ To use the types in this module, import the module with the following line:
+
+ \qml
+ import QtQuick.Pdf
+ \endqml
+*/
diff --git a/src/pdfquick/plugin.cpp b/src/pdfquick/plugin.cpp
deleted file mode 100644
index 23f32bc39..000000000
--- a/src/pdfquick/plugin.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtQml/qqml.h>
-#include <QtQml/qqmlcomponent.h>
-#include <QtQml/qqmlengine.h>
-#include <QtQml/qqmlextensionplugin.h>
-#include "qquickpdfdocument_p.h"
-#include "qquickpdflinkmodel_p.h"
-#include "qquickpdfnavigationstack_p.h"
-#include "qquickpdfsearchmodel_p.h"
-#include "qquickpdfselection_p.h"
-#include "qquicktableviewextra_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmlmodule QtQuick.Pdf
- \title Qt Quick PDF QML Types
- \ingroup qmlmodules
- \brief Provides QML types for handling PDF documents.
-
- This QML module contains types for handling PDF documents.
-
- To use the types in this module, import the module with the following line:
-
- \code
- import QtQuick.Pdf
- \endcode
-*/
-
-class QtQuick2PdfPlugin : public QQmlExtensionPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
-
-public:
- QtQuick2PdfPlugin() : QQmlExtensionPlugin() { }
-
- void initializeEngine(QQmlEngine *engine, const char *uri) override {
- Q_UNUSED(uri);
-#ifdef QT_STATIC
- Q_UNUSED(engine);
-#else
- engine->addImportPath(QStringLiteral("qrc:/"));
-#endif
- }
-
- void registerTypes(const char *uri) override {
- Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.Pdf"));
-
- // Register the latest version, even if there are no new types or new revisions for existing types yet.
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
-
- qmlRegisterType<QQuickPdfDocument>(uri, 5, 15, "PdfDocument");
- qmlRegisterType<QQuickPdfLinkModel>(uri, 5, 15, "PdfLinkModel");
- qmlRegisterType<QQuickPdfNavigationStack>(uri, 5, 15, "PdfNavigationStack");
- qmlRegisterType<QQuickPdfSearchModel>(uri, 5, 15, "PdfSearchModel");
- qmlRegisterType<QQuickPdfSelection>(uri, 5, 15, "PdfSelection");
- qmlRegisterType<QQuickTableViewExtra>(uri, 5, 15, "TableViewExtra");
- }
-};
-
-QT_END_NAMESPACE
-
-#include "plugin.moc"
diff --git a/src/pdfquick/plugins.qmltypes b/src/pdfquick/plugins.qmltypes
deleted file mode 100644
index a30361d33..000000000
--- a/src/pdfquick/plugins.qmltypes
+++ /dev/null
@@ -1,52 +0,0 @@
-import QtQuick.tooling 1.2
-
-// This file describes the plugin-supplied types contained in the library.
-// It is used for QML tooling purposes only.
-//
-// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable QtQuick.Pdf 5.14'
-
-Module {
- dependencies: [
- "QtGraphicalEffects 1.12",
- "QtQuick 2.14",
- "QtQuick.Controls 2.14",
- "QtQuick.Controls.Fusion 2.14",
- "QtQuick.Controls.Fusion.impl 2.14",
- "QtQuick.Controls.Imagine 2.14",
- "QtQuick.Controls.Imagine.impl 2.14",
- "QtQuick.Controls.Material 2.14",
- "QtQuick.Controls.Material.impl 2.14",
- "QtQuick.Controls.Universal 2.14",
- "QtQuick.Controls.Universal.impl 2.12",
- "QtQuick.Controls.impl 2.14",
- "QtQuick.Shapes 1.14",
- "QtQuick.Templates 2.14",
- "QtQuick.Window 2.2"
- ]
- Component {
- name: "QQuickPdfDocument"
- prototype: "QObject"
- exports: ["QtQuick.Pdf/PdfDocument 5.14"]
- exportMetaObjectRevisions: [0]
- Property { name: "source"; type: "QUrl" }
- Property { name: "pageCount"; type: "int"; isReadonly: true }
- Property { name: "password"; type: "string" }
- Property { name: "status"; type: "QPdfDocument::Status"; isReadonly: true }
- Property { name: "title"; type: "string"; isReadonly: true }
- Property { name: "subject"; type: "string"; isReadonly: true }
- Property { name: "author"; type: "string"; isReadonly: true }
- Property { name: "keywords"; type: "string"; isReadonly: true }
- Property { name: "producer"; type: "string"; isReadonly: true }
- Property { name: "creator"; type: "string"; isReadonly: true }
- Property { name: "creationDate"; type: "QDateTime"; isReadonly: true }
- Property { name: "modificationDate"; type: "QDateTime"; isReadonly: true }
- Signal { name: "passwordRequired" }
- Signal { name: "metaDataLoaded" }
- Method {
- name: "pagePointSize"
- type: "QSizeF"
- Parameter { name: "page"; type: "int" }
- }
- }
-}
diff --git a/src/pdfquick/qml/+material/PdfStyle.qml b/src/pdfquick/qml/+material/PdfStyle.qml
deleted file mode 100644
index 12df30466..000000000
--- a/src/pdfquick/qml/+material/PdfStyle.qml
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQml 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Controls.Material 2.14
-import QtQuick.Shapes 1.14
-
-QtObject {
- property Control prototypeControl: Control { }
- function withAlpha(color, alpha) {
- return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
- }
- property color selectionColor: withAlpha(prototypeControl.palette.highlight, 0.5)
- property color pageSearchResultsColor: withAlpha(Qt.lighter(Material.accentColor, 1.5), 0.5)
- property color currentSearchResultStrokeColor: Material.accentColor
- property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: prototypeControl.palette.link
- property real linkUnderscoreStrokeWidth: 1
- property var linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
-}
diff --git a/src/pdfquick/qml/+universal/PdfStyle.qml b/src/pdfquick/qml/+universal/PdfStyle.qml
deleted file mode 100644
index e92f2a080..000000000
--- a/src/pdfquick/qml/+universal/PdfStyle.qml
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQml 2.14
-import QtQuick 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Controls.Universal 2.14
-import QtQuick.Shapes 1.14
-
-QtObject {
- property Control prototypeControl: Control { }
- function withAlpha(color, alpha) {
- return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
- }
- property color selectionColor: withAlpha(prototypeControl.palette.highlight, 0.5)
- property color pageSearchResultsColor: withAlpha(Qt.lighter(Universal.accent, 1.5), 0.5)
- property color currentSearchResultStrokeColor: Universal.accent
- property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: prototypeControl.palette.link
- property real linkUnderscoreStrokeWidth: 1
- property var linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
-}
diff --git a/src/pdfquick/qml/PdfMultiPageView.qml b/src/pdfquick/qml/PdfMultiPageView.qml
deleted file mode 100644
index 71485c214..000000000
--- a/src/pdfquick/qml/PdfMultiPageView.qml
+++ /dev/null
@@ -1,434 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQuick 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Layouts 1.14
-import QtQuick.Pdf 5.15
-import QtQuick.Shapes 1.14
-import QtQuick.Window 2.14
-
-Item {
- // public API
- // TODO 5.15: required property
- property var document: undefined
- property bool debug: false
-
- property string selectedText
- function selectAll() {
- var currentItem = tableHelper.itemAtCell(tableHelper.cellAtPos(root.width / 2, root.height / 2))
- if (currentItem)
- currentItem.selection.selectAll()
- }
- function copySelectionToClipboard() {
- var currentItem = tableHelper.itemAtCell(tableHelper.cellAtPos(root.width / 2, root.height / 2))
- if (debug)
- console.log("currentItem", currentItem, "sel", currentItem.selection.text)
- if (currentItem)
- currentItem.selection.copyToClipboard()
- }
-
- // page navigation
- property alias currentPage: navigationStack.currentPage
- property alias backEnabled: navigationStack.backAvailable
- property alias forwardEnabled: navigationStack.forwardAvailable
- function back() { navigationStack.back() }
- function forward() { navigationStack.forward() }
- function goToPage(page) {
- if (page === navigationStack.currentPage)
- return
- goToLocation(page, Qt.point(-1, -1), 0)
- }
- function goToLocation(page, location, zoom) {
- if (zoom > 0) {
- navigationStack.jumping = true // don't call navigationStack.update() because we will push() instead
- root.renderScale = zoom
- tableView.forceLayout() // but do ensure that the table layout is correct before we try to jump
- navigationStack.jumping = false
- }
- navigationStack.push(page, location, zoom) // actually jump
- }
- property vector2d jumpLocationMargin: Qt.vector2d(10, 10) // px from top-left corner
- property int currentPageRenderingStatus: Image.Null
-
- // page scaling
- property real renderScale: 1
- property real pageRotation: 0
- function resetScale() { root.renderScale = 1 }
- function scaleToWidth(width, height) {
- root.renderScale = width / (tableView.rot90 ? tableView.firstPagePointSize.height : tableView.firstPagePointSize.width)
- }
- function scaleToPage(width, height) {
- var windowAspect = width / height
- var pageAspect = tableView.firstPagePointSize.width / tableView.firstPagePointSize.height
- if (tableView.rot90) {
- if (windowAspect > pageAspect) {
- root.renderScale = height / tableView.firstPagePointSize.width
- } else {
- root.renderScale = width / tableView.firstPagePointSize.height
- }
- } else {
- if (windowAspect > pageAspect) {
- root.renderScale = height / tableView.firstPagePointSize.height
- } else {
- root.renderScale = width / tableView.firstPagePointSize.width
- }
- }
- }
-
- // text search
- property alias searchModel: searchModel
- property alias searchString: searchModel.searchString
- function searchBack() { --searchModel.currentResult }
- function searchForward() { ++searchModel.currentResult }
-
- id: root
- PdfStyle { id: style }
- TableView {
- id: tableView
- anchors.fill: parent
- anchors.leftMargin: 2
- model: modelInUse && root.document !== undefined ? root.document.pageCount : 0
- // workaround to make TableView do scheduleRebuildTable(RebuildOption::All) in cases when forceLayout() doesn't
- property bool modelInUse: true
- function rebuild() {
- modelInUse = false
- modelInUse = true
- }
- // end workaround
- rowSpacing: 6
- property real rotationNorm: Math.round((360 + (root.pageRotation % 360)) % 360)
- property bool rot90: rotationNorm == 90 || rotationNorm == 270
- onRot90Changed: forceLayout()
- property size firstPagePointSize: document === undefined ? Qt.size(0, 0) : document.pagePointSize(0)
- property real pageHolderWidth: Math.max(root.width, document === undefined ? 0 :
- (rot90 ? document.maxPageHeight : document.maxPageWidth) * root.renderScale)
- contentWidth: document === undefined ? 0 : pageHolderWidth + vscroll.width + 2
- rowHeightProvider: function(row) { return (rot90 ? document.pagePointSize(row).width : document.pagePointSize(row).height) * root.renderScale }
- TableViewExtra {
- id: tableHelper
- tableView: tableView
- }
- delegate: Rectangle {
- id: pageHolder
- color: root.debug ? "beige" : "transparent"
- Text {
- visible: root.debug
- anchors { right: parent.right; verticalCenter: parent.verticalCenter }
- rotation: -90; text: pageHolder.width.toFixed(1) + "x" + pageHolder.height.toFixed(1) + "\n" +
- image.width.toFixed(1) + "x" + image.height.toFixed(1)
- }
- implicitWidth: tableView.pageHolderWidth
- implicitHeight: tableView.rot90 ? image.width : image.height
- property alias selection: selection
- Rectangle {
- id: paper
- width: image.width
- height: image.height
- rotation: root.pageRotation
- anchors.centerIn: pinch.active ? undefined : parent
- property size pagePointSize: document.pagePointSize(index)
- property real pageScale: image.paintedWidth / pagePointSize.width
- Image {
- id: image
- source: document.source
- currentFrame: index
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- width: paper.pagePointSize.width * root.renderScale
- height: paper.pagePointSize.height * root.renderScale
- property real renderScale: root.renderScale
- property real oldRenderScale: 1
- onRenderScaleChanged: {
- image.sourceSize.width = paper.pagePointSize.width * renderScale
- image.sourceSize.height = 0
- paper.scale = 1
- searchHighlights.update()
- }
- onStatusChanged: {
- if (index === navigationStack.currentPage)
- root.currentPageRenderingStatus = status
- }
- }
- Shape {
- anchors.fill: parent
- visible: image.status === Image.Ready
- onVisibleChanged: searchHighlights.update()
- ShapePath {
- strokeWidth: -1
- fillColor: style.pageSearchResultsColor
- scale: Qt.size(paper.pageScale, paper.pageScale)
- PathMultiline {
- id: searchHighlights
- function update() {
- // paths could be a binding, but we need to be able to "kick" it sometimes
- paths = searchModel.boundingPolygonsOnPage(index)
- }
- }
- }
- Connections {
- target: searchModel
- // whenever the highlights on the _current_ page change, they actually need to change on _all_ pages
- // (usually because the search string has changed)
- function onCurrentPageBoundingPolygonsChanged() { searchHighlights.update() }
- }
- ShapePath {
- strokeWidth: -1
- fillColor: style.selectionColor
- scale: Qt.size(paper.pageScale, paper.pageScale)
- PathMultiline {
- paths: selection.geometry
- }
- }
- }
- Shape {
- anchors.fill: parent
- visible: image.status === Image.Ready && searchModel.currentPage === index
- ShapePath {
- strokeWidth: style.currentSearchResultStrokeWidth
- strokeColor: style.currentSearchResultStrokeColor
- fillColor: "transparent"
- scale: Qt.size(paper.pageScale, paper.pageScale)
- PathMultiline {
- paths: searchModel.currentResultBoundingPolygons
- }
- }
- }
- PinchHandler {
- id: pinch
- minimumScale: 0.1
- maximumScale: root.renderScale < 4 ? 2 : 1
- minimumRotation: root.pageRotation
- maximumRotation: root.pageRotation
- enabled: image.sourceSize.width < 5000
- onActiveChanged:
- if (active) {
- paper.z = 10
- } else {
- paper.z = 0
- var centroidInPoints = Qt.point(pinch.centroid.position.x / root.renderScale,
- pinch.centroid.position.y / root.renderScale)
- var centroidInFlickable = tableView.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 on page", index, "with centroid", pinch.centroid.position, centroidInPoints, "wrt flickable", centroidInFlickable,
- "page at", pageHolder.x.toFixed(2), pageHolder.y.toFixed(2),
- "contentX/Y were", tableView.contentX.toFixed(2), tableView.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
- paper.x = 0
- paper.y = 0
- root.renderScale *= ratio
- tableView.forceLayout()
- if (tableView.rotationNorm == 0) {
- tableView.contentX = pageHolder.x + tableView.originX + centroidOnPage.x - centroidInFlickable.x
- tableView.contentY = pageHolder.y + tableView.originY + centroidOnPage.y - centroidInFlickable.y
- } else if (tableView.rotationNorm == 90) {
- tableView.contentX = pageHolder.x + tableView.originX + image.height - centroidOnPage.y - centroidInFlickable.x
- tableView.contentY = pageHolder.y + tableView.originY + centroidOnPage.x - centroidInFlickable.y
- } else if (tableView.rotationNorm == 180) {
- tableView.contentX = pageHolder.x + tableView.originX + image.width - centroidOnPage.x - centroidInFlickable.x
- tableView.contentY = pageHolder.y + tableView.originY + image.height - centroidOnPage.y - centroidInFlickable.y
- } else if (tableView.rotationNorm == 270) {
- tableView.contentX = pageHolder.x + tableView.originX + centroidOnPage.y - centroidInFlickable.x
- tableView.contentY = pageHolder.y + tableView.originY + image.width - centroidOnPage.x - centroidInFlickable.y
- }
- if (root.debug)
- console.log("contentX/Y adjusted to", tableView.contentX.toFixed(2), tableView.contentY.toFixed(2), "y @top", pageHolder.y)
- tableView.returnToBounds()
- }
- }
- grabPermissions: PointerHandler.CanTakeOverFromAnything
- }
- DragHandler {
- id: textSelectionDrag
- acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
- target: null
- }
- TapHandler {
- id: mouseClickHandler
- acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
- }
- TapHandler {
- id: touchTapHandler
- acceptedDevices: PointerDevice.TouchScreen
- onTapped: {
- selection.clear()
- selection.forceActiveFocus()
- }
- }
- Repeater {
- model: PdfLinkModel {
- id: linkModel
- document: root.document
- page: image.currentFrame
- }
- delegate: Shape {
- x: rect.x * paper.pageScale
- y: rect.y * paper.pageScale
- width: rect.width * paper.pageScale
- height: rect.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 }
- }
- 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)
- else
- 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
- }
- }
- }
- PdfSelection {
- id: selection
- anchors.fill: parent
- document: root.document
- page: image.currentFrame
- renderScale: image.renderScale
- fromPoint: textSelectionDrag.centroid.pressPosition
- toPoint: textSelectionDrag.centroid.position
- hold: !textSelectionDrag.active && !mouseClickHandler.pressed
- onTextChanged: root.selectedText = text
- focus: true
- }
- }
- }
- ScrollBar.vertical: ScrollBar {
- id: vscroll
- property bool moved: false
- onPositionChanged: moved = true
- onActiveChanged: {
- var cell = tableHelper.cellAtPos(root.width / 2, root.height / 2)
- var currentItem = tableHelper.itemAtCell(cell)
- var currentLocation = Qt.point(0, 0)
- if (currentItem) { // maybe the delegate wasn't loaded yet
- currentLocation = Qt.point((tableView.contentX - currentItem.x + jumpLocationMargin.x) / root.renderScale,
- (tableView.contentY - currentItem.y + jumpLocationMargin.y) / root.renderScale)
- }
- if (active) {
- moved = false
- // emitJumped false to avoid interrupting a pinch if TableView thinks it should scroll at the same time
- navigationStack.push(cell.y, currentLocation, root.renderScale, false)
- } else if (moved) {
- navigationStack.update(cell.y, currentLocation, root.renderScale)
- }
- }
- }
- ScrollBar.horizontal: ScrollBar { }
- }
- onRenderScaleChanged: {
- // if navigationStack.jumped changes the scale, don't turn around and update the stack again;
- // and don't force layout either, because positionViewAtCell() will do that
- if (navigationStack.jumping)
- return
- // make TableView rebuild from scratch, because otherwise it doesn't know the delegates are changing size
- tableView.rebuild()
- var cell = tableHelper.cellAtPos(root.width / 2, root.height / 2)
- var currentItem = tableHelper.itemAtCell(cell)
- if (currentItem) {
- var currentLocation = Qt.point((tableView.contentX - currentItem.x + jumpLocationMargin.x) / root.renderScale,
- (tableView.contentY - currentItem.y + jumpLocationMargin.y) / root.renderScale)
- navigationStack.update(cell.y, currentLocation, renderScale)
- }
- }
- PdfNavigationStack {
- id: navigationStack
- property bool jumping: false
- property int previousPage: 0
- onJumped: {
- jumping = true
- root.renderScale = zoom
- if (location.y < 0) {
- // invalid to indicate that a specific location was not needed,
- // so attempt to position the new page just as the current page is
- var currentYOffset = 0
- var previousPageDelegate = tableHelper.itemAtCell(0, previousPage)
- if (previousPageDelegate)
- currentYOffset = tableView.contentY - previousPageDelegate.y
- tableHelper.positionViewAtRow(page, Qt.AlignTop, currentYOffset)
- if (root.debug) {
- console.log("going from page", previousPage, "to", page, "offset", currentYOffset,
- "ended up @", tableView.contentX.toFixed(1) + ", " + tableView.contentY.toFixed(1))
- }
- } else {
- // jump to a page and position the given location relative to the top-left corner of the viewport
- var pageSize = root.document.pagePointSize(page)
- pageSize.width *= root.renderScale
- pageSize.height *= root.renderScale
- var xOffsetLimit = Math.max(0, pageSize.width - root.width) / 2
- var offset = Qt.point(Math.max(-xOffsetLimit, Math.min(xOffsetLimit,
- location.x * root.renderScale - jumpLocationMargin.x)),
- Math.max(0, location.y * root.renderScale - jumpLocationMargin.y))
- tableHelper.positionViewAtCell(0, page, Qt.AlignLeft | Qt.AlignTop, offset)
- if (root.debug) {
- console.log("going to zoom", zoom, "loc", location, "on page", page,
- "ended up @", tableView.contentX.toFixed(1) + ", " + tableView.contentY.toFixed(1))
- }
- }
- jumping = false
- previousPage = page
- }
- onCurrentPageChanged: searchModel.currentPage = currentPage
- }
- PdfSearchModel {
- id: searchModel
- document: root.document === undefined ? null : root.document
- // TODO maybe avoid jumping if the result is already fully visible in the viewport
- onCurrentResultBoundingRectChanged: root.goToLocation(currentPage,
- Qt.point(currentResultBoundingRect.x, currentResultBoundingRect.y), 0)
- }
-}
diff --git a/src/pdfquick/qml/PdfPageView.qml b/src/pdfquick/qml/PdfPageView.qml
deleted file mode 100644
index b90ad2d7f..000000000
--- a/src/pdfquick/qml/PdfPageView.qml
+++ /dev/null
@@ -1,276 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQuick 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Pdf 5.15
-import QtQuick.Shapes 1.14
-import Qt.labs.animation 1.0
-
-Rectangle {
- // public API
- // TODO 5.15: required property
- property var document: undefined
- property alias status: image.status
-
- property alias selectedText: selection.text
- function selectAll() {
- selection.selectAll()
- }
- function copySelectionToClipboard() {
- selection.copyToClipboard()
- }
-
- // page navigation
- property alias currentPage: navigationStack.currentPage
- property alias backEnabled: navigationStack.backAvailable
- property alias forwardEnabled: navigationStack.forwardAvailable
- function back() { navigationStack.back() }
- function forward() { navigationStack.forward() }
- function goToPage(page) { goToLocation(page, Qt.point(0, 0), 0) }
- function goToLocation(page, location, zoom) {
- if (zoom > 0)
- root.renderScale = zoom
- navigationStack.push(page, location, zoom)
- }
-
- // page scaling
- property real renderScale: 1
- property alias sourceSize: image.sourceSize
- function resetScale() {
- image.sourceSize.width = 0
- image.sourceSize.height = 0
- root.x = 0
- root.y = 0
- root.scale = 1
- }
- function scaleToWidth(width, height) {
- var halfRotation = Math.abs(root.rotation % 180)
- image.sourceSize = Qt.size((halfRotation > 45 && halfRotation < 135) ? height : width, 0)
- root.x = 0
- root.y = 0
- image.centerInSize = Qt.size(width, height)
- image.centerOnLoad = true
- image.vCenterOnLoad = (halfRotation > 45 && halfRotation < 135)
- root.scale = 1
- }
- function scaleToPage(width, height) {
- var windowAspect = width / height
- var halfRotation = Math.abs(root.rotation % 180)
- var pagePointSize = document.pagePointSize(navigationStack.currentPage)
- if (halfRotation > 45 && halfRotation < 135) {
- // rotated 90 or 270º
- var pageAspect = pagePointSize.height / pagePointSize.width
- if (windowAspect > pageAspect) {
- image.sourceSize = Qt.size(height, 0)
- } else {
- image.sourceSize = Qt.size(0, width)
- }
- } else {
- var pageAspect = pagePointSize.width / pagePointSize.height
- if (windowAspect > pageAspect) {
- image.sourceSize = Qt.size(0, height)
- } else {
- image.sourceSize = Qt.size(width, 0)
- }
- }
- image.centerInSize = Qt.size(width, height)
- image.centerOnLoad = true
- image.vCenterOnLoad = true
- root.scale = 1
- }
-
- // text search
- property alias searchModel: searchModel
- property alias searchString: searchModel.searchString
- function searchBack() { --searchModel.currentResult }
- function searchForward() { ++searchModel.currentResult }
-
- // implementation
- id: root
- width: image.width
- height: image.height
-
- PdfSelection {
- id: selection
- document: root.document
- page: navigationStack.currentPage
- fromPoint: Qt.point(textSelectionDrag.centroid.pressPosition.x / image.pageScale, textSelectionDrag.centroid.pressPosition.y / image.pageScale)
- toPoint: Qt.point(textSelectionDrag.centroid.position.x / image.pageScale, textSelectionDrag.centroid.position.y / image.pageScale)
- hold: !textSelectionDrag.active && !tapHandler.pressed
- }
-
- PdfSearchModel {
- id: searchModel
- document: root.document === undefined ? null : root.document
- onCurrentPageChanged: root.goToPage(currentPage)
- }
-
- PdfNavigationStack {
- id: navigationStack
- onCurrentPageChanged: searchModel.currentPage = currentPage
- // TODO onCurrentLocationChanged: position currentLocation.x and .y in middle // currentPageChanged() MUST occur first!
- onCurrentZoomChanged: root.renderScale = currentZoom
- // TODO deal with horizontal location (need WheelHandler or Flickable probably)
- }
-
- Image {
- id: image
- currentFrame: navigationStack.currentPage
- source: document.status === PdfDocument.Ready ? document.source : ""
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- property bool centerOnLoad: false
- property bool vCenterOnLoad: false
- property size centerInSize
- property real pageScale: image.paintedWidth / document.pagePointSize(navigationStack.currentPage).width
- function reRenderIfNecessary() {
- var newSourceWidth = image.sourceSize.width * root.scale
- var ratio = newSourceWidth / image.sourceSize.width
- if (ratio > 1.1 || ratio < 0.9) {
- image.sourceSize.width = newSourceWidth
- image.sourceSize.height = 0
- root.scale = 1
- }
- }
- onStatusChanged:
- if (status == Image.Ready && centerOnLoad) {
- root.x = (centerInSize.width - image.implicitWidth) / 2
- root.y = vCenterOnLoad ? (centerInSize.height - image.implicitHeight) / 2 : 0
- centerOnLoad = false
- vCenterOnLoad = false
- }
- }
- onRenderScaleChanged: {
- image.sourceSize.width = document.pagePointSize(navigationStack.currentPage).width * renderScale
- image.sourceSize.height = 0
- root.scale = 1
- }
-
- 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 {
- 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)
- }
- }
- }
- }
-
- PinchHandler {
- id: pinch
- minimumScale: 0.1
- maximumScale: 10
- minimumRotation: 0
- maximumRotation: 0
- onActiveChanged: if (!active) image.reRenderIfNecessary()
- grabPermissions: PinchHandler.TakeOverForbidden // don't allow takeover if pinch has started
- }
- DragHandler {
- id: pageMovingTouchDrag
- acceptedDevices: PointerDevice.TouchScreen
- }
- 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
- }
- // prevent it from being scrolled out of view
- BoundaryRule on x {
- minimum: 100 - root.width
- maximum: root.parent.width - 100
- }
- BoundaryRule on y {
- minimum: 100 - root.height
- maximum: root.parent.height - 100
- }
-}
diff --git a/src/pdfquick/qml/PdfScrollablePageView.qml b/src/pdfquick/qml/PdfScrollablePageView.qml
deleted file mode 100644
index 51d9e530d..000000000
--- a/src/pdfquick/qml/PdfScrollablePageView.qml
+++ /dev/null
@@ -1,307 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQuick 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Pdf 5.15
-import QtQuick.Shapes 1.14
-import Qt.labs.animation 1.0
-
-Flickable {
- // public API
- // TODO 5.15: required property
- property var document: undefined
- property bool debug: false
- property alias status: image.status
-
- property alias selectedText: selection.text
- function selectAll() {
- selection.selectAll()
- }
- function copySelectionToClipboard() {
- selection.copyToClipboard()
- }
-
- // page navigation
- property alias currentPage: navigationStack.currentPage
- property alias backEnabled: navigationStack.backAvailable
- property alias forwardEnabled: navigationStack.forwardAvailable
- function back() { navigationStack.back() }
- function forward() { navigationStack.forward() }
- function goToPage(page) {
- if (page === navigationStack.currentPage)
- return
- goToLocation(page, Qt.point(0, 0), 0)
- }
- function goToLocation(page, location, zoom) {
- if (zoom > 0)
- root.renderScale = zoom
- navigationStack.push(page, location, zoom)
- }
-
- // page scaling
- property real renderScale: 1
- property real pageRotation: 0
- property alias sourceSize: image.sourceSize
- function resetScale() {
- paper.scale = 1
- root.renderScale = 1
- }
- function scaleToWidth(width, height) {
- var pagePointSize = document.pagePointSize(navigationStack.currentPage)
- root.renderScale = root.width / (paper.rot90 ? pagePointSize.height : pagePointSize.width)
- if (debug)
- console.log("scaling", pagePointSize, "to fit", root.width, "rotated?", paper.rot90, "scale", root.renderScale)
- root.contentX = 0
- root.contentY = 0
- }
- function scaleToPage(width, height) {
- var pagePointSize = document.pagePointSize(navigationStack.currentPage)
- root.renderScale = Math.min(
- root.width / (paper.rot90 ? pagePointSize.height : pagePointSize.width),
- root.height / (paper.rot90 ? pagePointSize.width : pagePointSize.height) )
- root.contentX = 0
- root.contentY = 0
- }
-
- // text search
- property alias searchModel: searchModel
- property alias searchString: searchModel.searchString
- function searchBack() { --searchModel.currentResult }
- function searchForward() { ++searchModel.currentResult }
-
- // implementation
- id: root
- PdfStyle { id: style }
- contentWidth: paper.width
- contentHeight: paper.height
- ScrollBar.vertical: ScrollBar {
- onActiveChanged:
- if (!active ) {
- var currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
- (root.contentY + root.height / 2) / root.renderScale)
- navigationStack.update(navigationStack.currentPage, currentLocation, root.renderScale)
- }
- }
- ScrollBar.horizontal: ScrollBar {
- onActiveChanged:
- if (!active ) {
- var currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
- (root.contentY + root.height / 2) / root.renderScale)
- navigationStack.update(navigationStack.currentPage, currentLocation, root.renderScale)
- }
- }
-
- onRenderScaleChanged: {
- image.sourceSize.width = document.pagePointSize(navigationStack.currentPage).width * renderScale
- image.sourceSize.height = 0
- paper.scale = 1
- var currentLocation = Qt.point((root.contentX + root.width / 2) / root.renderScale,
- (root.contentY + root.height / 2) / root.renderScale)
- navigationStack.update(navigationStack.currentPage, currentLocation, root.renderScale)
- }
-
- PdfSearchModel {
- id: searchModel
- document: root.document === undefined ? null : root.document
- // TODO maybe avoid jumping if the result is already fully visible in the viewport
- onCurrentResultBoundingRectChanged: root.goToLocation(currentPage,
- Qt.point(currentResultBoundingRect.x, currentResultBoundingRect.y), 0)
- }
-
- PdfNavigationStack {
- id: navigationStack
- onJumped: {
- root.renderScale = zoom
- var dx = Math.max(0, location.x * root.renderScale - root.width / 2) - root.contentX
- var dy = Math.max(0, location.y * root.renderScale - root.height / 2) - root.contentY
- // don't jump if location is in the viewport already, i.e. if the "error" between desired and actual contentX/Y is small
- if (Math.abs(dx) > root.width / 3)
- root.contentX += dx
- if (Math.abs(dy) > root.height / 3)
- root.contentY += dy
- if (root.debug) {
- console.log("going to zoom", zoom, "loc", location,
- "on page", page, "ended up @", root.contentX + ", " + root.contentY)
- }
- }
- onCurrentPageChanged: searchModel.currentPage = currentPage
- }
-
- Rectangle {
- id: paper
- width: rot90 ? image.height : image.width
- height: rot90 ? image.width : image.height
- property real rotationModulus: Math.abs(root.pageRotation % 180)
- property bool rot90: rotationModulus > 45 && rotationModulus < 135
-
- Image {
- id: image
- currentFrame: navigationStack.currentPage
- source: document.status === PdfDocument.Ready ? document.source : ""
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- rotation: root.pageRotation
- anchors.centerIn: parent
- property real pageScale: image.paintedWidth / document.pagePointSize(navigationStack.currentPage).width
-
- Shape {
- anchors.fill: parent
- visible: image.status === Image.Ready
- ShapePath {
- strokeWidth: -1
- fillColor: style.pageSearchResultsColor
- scale: Qt.size(image.pageScale, image.pageScale)
- PathMultiline {
- paths: searchModel.currentPageBoundingPolygons
- }
- }
- ShapePath {
- strokeWidth: style.currentSearchResultStrokeWidth
- strokeColor: style.currentSearchResultStrokeColor
- fillColor: "transparent"
- scale: Qt.size(image.pageScale, image.pageScale)
- PathMultiline {
- paths: searchModel.currentResultBoundingPolygons
- }
- }
- ShapePath {
- fillColor: style.selectionColor
- scale: Qt.size(image.pageScale, image.pageScale)
- PathMultiline {
- paths: selection.geometry
- }
- }
- }
-
- Repeater {
- model: PdfLinkModel {
- id: linkModel
- document: root.document
- page: navigationStack.currentPage
- }
- delegate: Shape {
- x: rect.x * image.pageScale
- y: rect.y * image.pageScale
- width: rect.width * image.pageScale
- height: rect.height * image.pageScale
- ShapePath {
- strokeWidth: style.linkUnderscoreStrokeWidth
- strokeColor: style.linkUnderscoreColor
- strokeStyle: style.linkUnderscoreStrokeStyle
- dashPattern: style.linkUnderscoreDashPattern
- startX: 0; startY: height
- PathLine { x: width; y: height }
- }
- 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: mouseClickHandler
- acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
- }
- TapHandler {
- id: touchTapHandler
- acceptedDevices: PointerDevice.TouchScreen
- onTapped: {
- selection.clear()
- selection.focus = true
- }
- }
- }
-
- PdfSelection {
- id: selection
- anchors.fill: parent
- document: root.document
- page: navigationStack.currentPage
- renderScale: image.pageScale
- fromPoint: textSelectionDrag.centroid.pressPosition
- toPoint: textSelectionDrag.centroid.position
- hold: !textSelectionDrag.active && !mouseClickHandler.pressed
- focus: true
- }
-
- PinchHandler {
- id: pinch
- minimumScale: 0.1
- maximumScale: root.renderScale < 4 ? 2 : 1
- minimumRotation: 0
- maximumRotation: 0
- 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
- 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
- }
- }
- grabPermissions: PointerHandler.CanTakeOverFromAnything
- }
- }
-}
diff --git a/src/pdfquick/qml/PdfStyle.qml b/src/pdfquick/qml/PdfStyle.qml
deleted file mode 100644
index 090465ce6..000000000
--- a/src/pdfquick/qml/PdfStyle.qml
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-import QtQml 2.14
-import QtQuick 2.14
-import QtQuick.Controls 2.14
-import QtQuick.Shapes 1.14
-
-QtObject {
- property Control prototypeControl: Control { }
- function withAlpha(color, alpha) {
- return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha)
- }
- property color selectionColor: withAlpha(prototypeControl.palette.highlight, 0.5)
- property color pageSearchResultsColor: "#80B0C4DE"
- property color currentSearchResultStrokeColor: "cyan"
- property real currentSearchResultStrokeWidth: 2
- property color linkUnderscoreColor: prototypeControl.palette.link
- property real linkUnderscoreStrokeWidth: 1
- property var linkUnderscoreStrokeStyle: ShapePath.DashLine
- property var linkUnderscoreDashPattern: [ 1, 4 ]
-}
diff --git a/src/pdfquick/qquickpdfbookmarkmodel.cpp b/src/pdfquick/qquickpdfbookmarkmodel.cpp
new file mode 100644
index 000000000..81f8547ae
--- /dev/null
+++ b/src/pdfquick/qquickpdfbookmarkmodel.cpp
@@ -0,0 +1,55 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickpdfbookmarkmodel_p.h"
+#include <QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype PdfBookmarkModel
+//! \instantiates QQuickPdfBookmarkModel
+ \inqmlmodule QtQuick.Pdf
+ \ingroup pdf
+ \brief A tree of links (anchors) within a PDF document, such as the table of contents.
+ \since 6.4
+
+ A PDF document can contain a hierarchy of link destinations, usually
+ representing the table of contents, to be shown in a sidebar in a PDF
+ viewer, so that the user can quickly jump to those locations in the
+ document. This QAbstractItemModel holds the information in a form
+ suitable for display with TreeView, ListView, QTreeView or QListView.
+*/
+
+QQuickPdfBookmarkModel::QQuickPdfBookmarkModel(QObject *parent)
+ : QPdfBookmarkModel(parent)
+{
+}
+
+/*!
+ \internal
+*/
+QQuickPdfBookmarkModel::~QQuickPdfBookmarkModel() = default;
+
+/*!
+ \qmlproperty PdfDocument PdfBookmarkModel::document
+
+ This property holds the PDF document in which bookmarks are to be found.
+*/
+QQuickPdfDocument *QQuickPdfBookmarkModel::document() const
+{
+ return m_quickDocument;
+}
+
+void QQuickPdfBookmarkModel::setDocument(QQuickPdfDocument *document)
+{
+ if (document == m_quickDocument)
+ return;
+ m_quickDocument = document;
+ QPdfBookmarkModel::setDocument(document->document());
+ emit documentChanged();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickpdfbookmarkmodel_p.cpp"
diff --git a/src/pdfquick/qquickpdfbookmarkmodel_p.h b/src/pdfquick/qquickpdfbookmarkmodel_p.h
new file mode 100644
index 000000000..1276be058
--- /dev/null
+++ b/src/pdfquick/qquickpdfbookmarkmodel_p.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKPDFBOOKMARKMODEL_P_H
+#define QQUICKPDFBOOKMARKMODEL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
+#include <QtPdfQuick/private/qquickpdfdocument_p.h>
+#include <QtPdf/qpdfbookmarkmodel.h>
+
+#include <QQmlEngine>
+
+QT_BEGIN_NAMESPACE
+
+class Q_PDFQUICK_EXPORT QQuickPdfBookmarkModel : public QPdfBookmarkModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QQuickPdfDocument* document READ document WRITE setDocument NOTIFY documentChanged)
+ QML_NAMED_ELEMENT(PdfBookmarkModel)
+ QML_ADDED_IN_VERSION(6, 4)
+
+public:
+ explicit QQuickPdfBookmarkModel(QObject *parent = nullptr);
+ ~QQuickPdfBookmarkModel() override;
+
+ QQuickPdfDocument *document() const;
+ void setDocument(QQuickPdfDocument *document);
+
+Q_SIGNALS:
+ void documentChanged();
+
+private:
+ QQuickPdfDocument *m_quickDocument;
+
+ Q_DISABLE_COPY(QQuickPdfBookmarkModel)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickPdfBookmarkModel)
+
+#endif // QQUICKPDFBOOKMARKMODEL_P_H
diff --git a/src/pdfquick/qquickpdfdocument.cpp b/src/pdfquick/qquickpdfdocument.cpp
index 79b23ca84..9770900db 100644
--- a/src/pdfquick/qquickpdfdocument.cpp
+++ b/src/pdfquick/qquickpdfdocument.cpp
@@ -1,49 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpdfdocument_p.h"
-#include <QQuickItem>
-#include <QQmlEngine>
-#include <QStandardPaths>
+#include <private/qpdffile_p.h>
+#include <QtCore/qmetatype.h>
+#include <QtCore/qstandardpaths.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQuick/qquickitem.h>
+#include <QtQml/qqmlfile.h>
QT_BEGIN_NAMESPACE
/*!
\qmltype PdfDocument
- \instantiates QQuickPdfDocument
+//! \instantiates QQuickPdfDocument
\inqmlmodule QtQuick.Pdf
\ingroup pdf
\brief A representation of a PDF document.
@@ -54,26 +25,37 @@ QT_BEGIN_NAMESPACE
\l Image with source set to the URL of the PDF.
*/
-/*!
+/*
Constructs a PDF document.
*/
QQuickPdfDocument::QQuickPdfDocument(QObject *parent)
: QObject(parent)
{
- connect(&m_doc, &QPdfDocument::passwordChanged, this, &QQuickPdfDocument::passwordChanged);
- connect(&m_doc, &QPdfDocument::passwordRequired, this, &QQuickPdfDocument::passwordRequired);
- connect(&m_doc, &QPdfDocument::statusChanged, [=] (QPdfDocument::Status status) {
- emit statusChanged();
- if (status == QPdfDocument::Ready)
- emit metaDataChanged();
- });
- connect(&m_doc, &QPdfDocument::pageCountChanged, this, &QQuickPdfDocument::pageCountChanged);
}
-void QQuickPdfDocument::componentComplete()
+/*!
+ \internal
+*/
+QQuickPdfDocument::~QQuickPdfDocument()
+{
+ delete m_carrierFile;
+};
+
+void QQuickPdfDocument::classBegin()
{
- if (m_doc.error() == QPdfDocument::IncorrectPasswordError)
- emit passwordRequired();
+ m_doc = static_cast<QPdfDocument *>(qmlExtendedObject(this));
+ Q_ASSERT(m_doc);
+ connect(m_doc, &QPdfDocument::passwordChanged, this, [this]() -> void {
+ if (resolvedSource().isValid())
+ m_doc->load(QQmlFile::urlToLocalFileOrQrc(resolvedSource()));
+ });
+ connect(m_doc, &QPdfDocument::statusChanged, this, [this] (QPdfDocument::Status status) {
+ emit errorChanged();
+ if (status == QPdfDocument::Status::Ready)
+ emit metaDataChanged();
+ });
+ if (m_doc->error() == QPdfDocument::Error::IncorrectPassword)
+ emit m_doc->passwordRequired();
}
/*!
@@ -90,11 +72,14 @@ void QQuickPdfDocument::setSource(QUrl source)
m_source = source;
m_maxPageWidthHeight = QSizeF();
+ if (m_carrierFile)
+ m_carrierFile->deleteLater();
+ m_carrierFile = nullptr;
emit sourceChanged();
- if (source.scheme() == QLatin1String("qrc"))
- m_doc.load(QLatin1Char(':') + source.path());
- else
- m_doc.load(source.toLocalFile());
+ const QQmlContext *context = qmlContext(this);
+ m_resolvedSource = context ? context->resolvedUrl(source) : source;
+ if (m_resolvedSource.isValid())
+ m_doc->load(QQmlFile::urlToLocalFileOrQrc(m_resolvedSource));
}
/*!
@@ -107,25 +92,25 @@ void QQuickPdfDocument::setSource(QUrl source)
*/
QString QQuickPdfDocument::error() const
{
- switch (m_doc.error()) {
- case QPdfDocument::NoError:
+ switch (m_doc->error()) {
+ case QPdfDocument::Error::None:
return tr("no error");
break;
- case QPdfDocument::UnknownError:
+ case QPdfDocument::Error::Unknown:
break;
- case QPdfDocument::DataNotYetAvailableError:
+ case QPdfDocument::Error::DataNotYetAvailable:
return tr("data not yet available");
break;
- case QPdfDocument::FileNotFoundError:
+ case QPdfDocument::Error::FileNotFound:
return tr("file not found");
break;
- case QPdfDocument::InvalidFileFormatError:
+ case QPdfDocument::Error::InvalidFileFormat:
return tr("invalid file format");
break;
- case QPdfDocument::IncorrectPasswordError:
+ case QPdfDocument::Error::IncorrectPassword:
return tr("incorrect password");
break;
- case QPdfDocument::UnsupportedSecuritySchemeError:
+ case QPdfDocument::Error::UnsupportedSecurityScheme:
return tr("unsupported security scheme");
break;
}
@@ -133,20 +118,12 @@ QString QQuickPdfDocument::error() const
}
/*!
- \qmlproperty bool PdfDocument::password
+ \qmlproperty string PdfDocument::password
This property holds the document password. If the passwordRequired()
signal is emitted, the UI should prompt the user and then set this
property so that document opening can continue.
*/
-void QQuickPdfDocument::setPassword(const QString &password)
-{
- if (m_doc.password() == password)
- return;
- m_doc.setPassword(password);
- if (source().isValid() && source().isLocalFile())
- m_doc.load(source().path());
-}
/*!
\qmlproperty int PdfDocument::pageCount
@@ -167,58 +144,45 @@ void QQuickPdfDocument::setPassword(const QString &password)
Returns the size of the given \a page in points.
*/
-QSizeF QQuickPdfDocument::pagePointSize(int page) const
-{
- return m_doc.pageSize(page);
-}
qreal QQuickPdfDocument::maxPageWidth() const
{
- const_cast<QQuickPdfDocument *>(this)->updateMaxPageSize();
+ updateMaxPageSize();
return m_maxPageWidthHeight.width();
}
qreal QQuickPdfDocument::maxPageHeight() const
{
- const_cast<QQuickPdfDocument *>(this)->updateMaxPageSize();
+ updateMaxPageSize();
return m_maxPageWidthHeight.height();
}
+QPdfDocument *QQuickPdfDocument::document() const
+{
+ return m_doc;
+}
+
/*!
\internal
- \qmlmethod size PdfDocument::heightSumBeforePage(int page)
-
- Returns the sum of the heights, in points, of all sets of \a facingPages
- pages from 0 to the given \a page, exclusive.
-
- That is, if the pages were laid out end-to-end in adjacent sets of
- \a facingPages, what would be the distance in points from the top of the
- first page to the top of the given page.
+ Returns a QPdfFile instance that can carry this document down into
+ QPdfIOHandler::load(QIODevice *). It should not be used for other purposes.
*/
-// Workaround for lack of something analogous to ListView.positionViewAtIndex() in TableView
-qreal QQuickPdfDocument::heightSumBeforePage(int page, qreal spacing, int facingPages) const
+QPdfFile *QQuickPdfDocument::carrierFile()
{
- qreal ret = 0;
- for (int i = 0; i < page; i+= facingPages) {
- if (i + facingPages > page)
- break;
- qreal facingPagesHeight = 0;
- for (int j = i; j < i + facingPages; ++j)
- facingPagesHeight = qMax(facingPagesHeight, pagePointSize(j).height());
- ret += facingPagesHeight + spacing;
- }
- return ret;
+ if (!m_carrierFile)
+ m_carrierFile = new QPdfFile(m_doc);
+ return m_carrierFile;
}
-void QQuickPdfDocument::updateMaxPageSize()
+void QQuickPdfDocument::updateMaxPageSize() const
{
if (m_maxPageWidthHeight.isValid())
return;
qreal w = 0;
qreal h = 0;
- const int count = pageCount();
+ const int count = m_doc->pageCount();
for (int i = 0; i < count; ++i) {
- auto size = pagePointSize(i);
+ auto size = m_doc->pagePointSize(i);
w = qMax(w, size.width());
h = qMax(w, size.height());
}
@@ -277,13 +241,13 @@ void QQuickPdfDocument::updateMaxPageSize()
*/
/*!
- \qmlproperty string PdfDocument::creationDate
+ \qmlproperty date PdfDocument::creationDate
This property holds the date and time the document was created.
*/
/*!
- \qmlproperty string PdfDocument::modificationDate
+ \qmlproperty date PdfDocument::modificationDate
This property holds the date and time the document was most recently
modified.
@@ -303,3 +267,5 @@ void QQuickPdfDocument::updateMaxPageSize()
*/
QT_END_NAMESPACE
+
+#include "moc_qquickpdfdocument_p.cpp"
diff --git a/src/pdfquick/qquickpdfdocument_p.h b/src/pdfquick/qquickpdfdocument_p.h
index cfeeb7b98..95ded7f8b 100644
--- a/src/pdfquick/qquickpdfdocument_p.h
+++ b/src/pdfquick/qquickpdfdocument_p.h
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKPDFDOCUMENT_P_H
#define QQUICKPDFDOCUMENT_P_H
@@ -50,83 +17,83 @@
#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
#include <QtPdf/QPdfDocument>
-#include <QDateTime>
-#include <QJSValue>
-#include <QQmlParserStatus>
-#include <QUrl>
-#include <QVariant>
+
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlParserStatus>
+#include <QtCore/QDateTime>
+#include <QtCore/QUrl>
QT_BEGIN_NAMESPACE
+class QPdfFile;
+
class Q_PDFQUICK_EXPORT QQuickPdfDocument : public QObject, public QQmlParserStatus
{
Q_OBJECT
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged FINAL)
- Q_PROPERTY(qreal maxPageWidth READ maxPageWidth NOTIFY metaDataChanged)
- Q_PROPERTY(qreal maxPageHeight READ maxPageHeight NOTIFY metaDataChanged)
- Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged FINAL)
- Q_PROPERTY(QPdfDocument::Status status READ status NOTIFY statusChanged FINAL)
- Q_PROPERTY(QString error READ error NOTIFY statusChanged FINAL)
-
- Q_PROPERTY(QString title READ title NOTIFY metaDataChanged)
- Q_PROPERTY(QString subject READ subject NOTIFY metaDataChanged)
- Q_PROPERTY(QString author READ author NOTIFY metaDataChanged)
- Q_PROPERTY(QString keywords READ keywords NOTIFY metaDataChanged)
- Q_PROPERTY(QString producer READ producer NOTIFY metaDataChanged)
- Q_PROPERTY(QString creator READ creator NOTIFY metaDataChanged)
- Q_PROPERTY(QDateTime creationDate READ creationDate NOTIFY metaDataChanged)
- Q_PROPERTY(QDateTime modificationDate READ modificationDate NOTIFY metaDataChanged)
+ Q_INTERFACES(QQmlParserStatus)
+
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged FINAL)
+ Q_PROPERTY(qreal maxPageWidth READ maxPageWidth NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(qreal maxPageHeight READ maxPageHeight NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString error READ error NOTIFY errorChanged FINAL)
+
+ Q_PROPERTY(QString title READ title NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString subject READ subject NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString author READ author NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString keywords READ keywords NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString producer READ producer NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QString creator READ creator NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QDateTime creationDate READ creationDate NOTIFY metaDataChanged FINAL)
+ Q_PROPERTY(QDateTime modificationDate READ modificationDate NOTIFY metaDataChanged FINAL)
+ QML_NAMED_ELEMENT(PdfDocument)
+ QML_EXTENDED(QPdfDocument)
+ QML_ADDED_IN_VERSION(5, 15)
public:
explicit QQuickPdfDocument(QObject *parent = nullptr);
+ ~QQuickPdfDocument() override;
- void classBegin() override {}
- void componentComplete() override;
+ void classBegin() override;
+ void componentComplete() override {}
QUrl source() const { return m_source; }
void setSource(QUrl source);
-
- int pageCount() const { return m_doc.pageCount(); }
- QPdfDocument::Status status() const { return m_doc.status(); }
+ QUrl resolvedSource() const { return m_resolvedSource; }
QString error() const;
- QString password() const { return m_doc.password(); }
- void setPassword(const QString &password);
-
- QString title() { return m_doc.metaData(QPdfDocument::Title).toString(); }
- QString author() { return m_doc.metaData(QPdfDocument::Author).toString(); }
- QString subject() { return m_doc.metaData(QPdfDocument::Subject).toString(); }
- QString keywords() { return m_doc.metaData(QPdfDocument::Keywords).toString(); }
- QString producer() { return m_doc.metaData(QPdfDocument::Producer).toString(); }
- QString creator() { return m_doc.metaData(QPdfDocument::Creator).toString(); }
- QDateTime creationDate() { return m_doc.metaData(QPdfDocument::CreationDate).toDateTime(); }
- QDateTime modificationDate() { return m_doc.metaData(QPdfDocument::ModificationDate).toDateTime(); }
+ QString title() { return m_doc->metaData(QPdfDocument::MetaDataField::Title).toString(); }
+ QString author() { return m_doc->metaData(QPdfDocument::MetaDataField::Author).toString(); }
+ QString subject() { return m_doc->metaData(QPdfDocument::MetaDataField::Subject).toString(); }
+ QString keywords() { return m_doc->metaData(QPdfDocument::MetaDataField::Keywords).toString(); }
+ QString producer() { return m_doc->metaData(QPdfDocument::MetaDataField::Producer).toString(); }
+ QString creator() { return m_doc->metaData(QPdfDocument::MetaDataField::Creator).toString(); }
+ QDateTime creationDate() { return m_doc->metaData(QPdfDocument::MetaDataField::CreationDate).toDateTime(); }
+ QDateTime modificationDate() { return m_doc->metaData(QPdfDocument::MetaDataField::ModificationDate).toDateTime(); }
- Q_INVOKABLE QSizeF pagePointSize(int page) const;
qreal maxPageWidth() const;
qreal maxPageHeight() const;
- Q_INVOKABLE qreal heightSumBeforePage(int page, qreal spacing = 0, int facingPages = 1) const;
Q_SIGNALS:
void sourceChanged();
- void passwordChanged();
- void passwordRequired();
- void statusChanged();
- void pageCountChanged();
+ void errorChanged();
void metaDataChanged();
private:
- QPdfDocument &document() { return m_doc; }
- void updateMaxPageSize();
+ QPdfDocument *document() const;
+ QPdfFile *carrierFile();
+ void updateMaxPageSize() const;
private:
QUrl m_source;
- QPdfDocument m_doc;
- QSizeF m_maxPageWidthHeight;
+ QUrl m_resolvedSource;
+ QPdfDocument *m_doc = nullptr;
+ QPdfFile *m_carrierFile = nullptr;
+ mutable QSizeF m_maxPageWidthHeight;
+ friend class QQuickPdfBookmarkModel;
friend class QQuickPdfLinkModel;
+ friend class QQuickPdfPageImage;
friend class QQuickPdfSearchModel;
friend class QQuickPdfSelection;
diff --git a/src/pdfquick/qquickpdflinkmodel.cpp b/src/pdfquick/qquickpdflinkmodel.cpp
index 4f3958337..469d13faf 100644
--- a/src/pdfquick/qquickpdflinkmodel.cpp
+++ b/src/pdfquick/qquickpdflinkmodel.cpp
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpdflinkmodel_p.h"
#include <QQuickItem>
@@ -43,7 +10,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmltype PdfLinkModel
- \instantiates QQuickPdfLinkModel
+//! \instantiates QQuickPdfLinkModel
\inqmlmodule QtQuick.Pdf
\ingroup pdf
\brief A representation of links within a PDF document.
@@ -54,7 +21,7 @@ QT_BEGIN_NAMESPACE
The available model roles are:
- \value rect
+ \value rectangle
Bounding rectangle around the link.
\value url
If the link is a web link, the URL for that; otherwise an empty URL.
@@ -75,12 +42,15 @@ QT_BEGIN_NAMESPACE
page: image.currentFrame
}
delegate: Rectangle {
+ required property rect rectangle
+ required property url url
+ required property int page
color: "transparent"
border.color: "lightgrey"
- x: rect.x
- y: rect.y
- width: rect.width
- height: rect.height
+ x: rectangle.x
+ y: rectangle.y
+ width: rectangle.width
+ height: rectangle.height
HoverHandler { cursorShape: Qt.PointingHandCursor }
TapHandler {
onTapped: {
@@ -95,7 +65,7 @@ QT_BEGIN_NAMESPACE
\endqml
\note General-purpose PDF viewing capabilities are provided by
- \l PdfScrollablePageView and \l PdfMultiPageView. PdfLinkModel is only needed
+ \c PdfScrollablePageView and \c PdfMultiPageView. PdfLinkModel is only needed
when building PDF view components from scratch.
*/
@@ -105,6 +75,11 @@ QQuickPdfLinkModel::QQuickPdfLinkModel(QObject *parent)
}
/*!
+ \internal
+*/
+QQuickPdfLinkModel::~QQuickPdfLinkModel() = default;
+
+/*!
\qmlproperty PdfDocument PdfLinkModel::document
This property holds the PDF document in which links are to be found.
@@ -119,7 +94,8 @@ void QQuickPdfLinkModel::setDocument(QQuickPdfDocument *document)
if (document == m_quickDocument)
return;
m_quickDocument = document;
- QPdfLinkModel::setDocument(&document->m_doc);
+ if (document)
+ QPdfLinkModel::setDocument(document->document());
}
/*!
@@ -129,3 +105,5 @@ void QQuickPdfLinkModel::setDocument(QQuickPdfDocument *document)
*/
QT_END_NAMESPACE
+
+#include "moc_qquickpdflinkmodel_p.cpp"
diff --git a/src/pdfquick/qquickpdflinkmodel_p.h b/src/pdfquick/qquickpdflinkmodel_p.h
index d777643ef..44314b2b1 100644
--- a/src/pdfquick/qquickpdflinkmodel_p.h
+++ b/src/pdfquick/qquickpdflinkmodel_p.h
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKPDFLINKMODEL_P_H
#define QQUICKPDFLINKMODEL_P_H
@@ -52,8 +19,7 @@
#include <QtPdfQuick/private/qquickpdfdocument_p.h>
#include <QtPdf/private/qpdflinkmodel_p.h>
-#include <QVariant>
-#include <QtQml/qqml.h>
+#include <QtQml/QQmlEngine>
QT_BEGIN_NAMESPACE
@@ -61,23 +27,18 @@ class Q_PDFQUICK_EXPORT QQuickPdfLinkModel : public QPdfLinkModel
{
Q_OBJECT
Q_PROPERTY(QQuickPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged)
+ QML_NAMED_ELEMENT(PdfLinkModel)
+ QML_ADDED_IN_VERSION(5, 15)
public:
explicit QQuickPdfLinkModel(QObject *parent = nullptr);
+ ~QQuickPdfLinkModel() override;
QQuickPdfDocument *document() const;
void setDocument(QQuickPdfDocument *document);
-signals:
- void documentChanged();
-
-private:
- void updateResults();
-
private:
QQuickPdfDocument *m_quickDocument;
- QList<QPolygonF> m_linksGeometry;
-
Q_DISABLE_COPY(QQuickPdfLinkModel)
};
diff --git a/src/pdfquick/qquickpdfnavigationstack.cpp b/src/pdfquick/qquickpdfnavigationstack.cpp
deleted file mode 100644
index e41e43ed5..000000000
--- a/src/pdfquick/qquickpdfnavigationstack.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qquickpdfnavigationstack_p.h"
-#include <QLoggingCategory>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(qLcNav, "qt.pdf.navigationstack")
-
-/*!
- \qmltype PdfNavigationStack
- \instantiates QQuickPdfNavigationStack
- \inqmlmodule QtQuick.Pdf
- \ingroup pdf
- \brief History of the destinations visited within a PDF Document.
- \since 5.15
-
- PdfNavigationStack remembers which destinations the user has visited in a PDF
- document, and provides the ability to traverse backward and forward.
-*/
-
-QQuickPdfNavigationStack::QQuickPdfNavigationStack(QObject *parent)
- : QObject(parent)
-{
- push(0, QPointF(), 1);
-}
-
-/*!
- \qmlmethod void PdfNavigationStack::forward()
-
- Goes back to the page, location and zoom level that was being viewed before
- back() was called, and then emits the \l jumped() signal.
-
- If a new destination was pushed since the last time \l back() was called,
- the forward() function does nothing, because there is a branch in the
- timeline which causes the "future" to be lost.
-*/
-void QQuickPdfNavigationStack::forward()
-{
- if (m_currentHistoryIndex >= m_pageHistory.count() - 1)
- return;
- bool backAvailableWas = backAvailable();
- bool forwardAvailableWas = forwardAvailable();
- QPointF currentLocationWas = currentLocation();
- qreal currentZoomWas = currentZoom();
- ++m_currentHistoryIndex;
- m_changing = true;
- emit jumped(currentPage(), currentLocation(), currentZoom());
- if (currentZoomWas != currentZoom())
- emit currentZoomChanged();
- emit currentPageChanged();
- if (currentLocationWas != currentLocation())
- emit currentLocationChanged();
- if (!backAvailableWas)
- emit backAvailableChanged();
- if (forwardAvailableWas != forwardAvailable())
- emit forwardAvailableChanged();
- m_changing = false;
- qCDebug(qLcNav) << "forward: index" << m_currentHistoryIndex << "page" << currentPage()
- << "@" << currentLocation() << "zoom" << currentZoom();
-}
-
-/*!
- \qmlmethod void PdfNavigationStack::back()
-
- Pops the stack, updates the \l currentPage, \l currentLocation and
- \l currentZoom properties to the most-recently-viewed destination, and then
- emits the \l jumped() signal.
-*/
-void QQuickPdfNavigationStack::back()
-{
- if (m_currentHistoryIndex <= 0)
- return;
- bool backAvailableWas = backAvailable();
- bool forwardAvailableWas = forwardAvailable();
- QPointF currentLocationWas = currentLocation();
- qreal currentZoomWas = currentZoom();
- --m_currentHistoryIndex;
- m_changing = true;
- emit jumped(currentPage(), currentLocation(), currentZoom());
- if (currentZoomWas != currentZoom())
- emit currentZoomChanged();
- emit currentPageChanged();
- if (currentLocationWas != currentLocation())
- emit currentLocationChanged();
- if (backAvailableWas != backAvailable())
- emit backAvailableChanged();
- if (!forwardAvailableWas)
- emit forwardAvailableChanged();
- m_changing = false;
- qCDebug(qLcNav) << "back: index" << m_currentHistoryIndex << "page" << currentPage()
- << "@" << currentLocation() << "zoom" << currentZoom();
-}
-
-/*!
- \qmlproperty int PdfNavigationStack::currentPage
-
- This property holds the current page that is being viewed.
- If there is no current page, it holds \c -1.
-*/
-int QQuickPdfNavigationStack::currentPage() const
-{
- if (m_currentHistoryIndex < 0 || m_currentHistoryIndex >= m_pageHistory.count())
- return -1;
- return m_pageHistory.at(m_currentHistoryIndex)->page;
-}
-
-/*!
- \qmlproperty point PdfNavigationStack::currentLocation
-
- This property holds the current location on the page that is being viewed.
-*/
-QPointF QQuickPdfNavigationStack::currentLocation() const
-{
- if (m_currentHistoryIndex < 0 || m_currentHistoryIndex >= m_pageHistory.count())
- return QPointF();
- return m_pageHistory.at(m_currentHistoryIndex)->location;
-}
-
-/*!
- \qmlproperty real PdfNavigationStack::currentZoom
-
- This property holds the magnification scale on the page that is being viewed.
-*/
-qreal QQuickPdfNavigationStack::currentZoom() const
-{
- if (m_currentHistoryIndex < 0 || m_currentHistoryIndex >= m_pageHistory.count())
- return 1;
- return m_pageHistory.at(m_currentHistoryIndex)->zoom;
-}
-
-/*!
- \qmlmethod void PdfNavigationStack::push(int page, point location, qreal zoom)
-
- Adds the given destination, consisting of \a page, \a location and \a zoom,
- to the history of visited locations. If \a emitJumped is \c false, the
- \l jumped() signal will not be emitted.
-
- If forwardAvailable is \c true, calling this function represents a branch
- in the timeline which causes the "future" to be lost, and therefore
- forwardAvailable will change to \c false.
-*/
-void QQuickPdfNavigationStack::push(int page, QPointF location, qreal zoom, bool emitJumped)
-{
- if (page == currentPage() && location == currentLocation() && zoom == currentZoom())
- return;
- if (qFuzzyIsNull(zoom))
- zoom = currentZoom();
- bool backAvailableWas = backAvailable();
- bool forwardAvailableWas = forwardAvailable();
- if (!m_changing) {
- if (m_currentHistoryIndex >= 0 && forwardAvailableWas)
- m_pageHistory.remove(m_currentHistoryIndex + 1, m_pageHistory.count() - m_currentHistoryIndex - 1);
- m_pageHistory.append(QExplicitlySharedDataPointer<QPdfDestinationPrivate>(new QPdfDestinationPrivate(page, location, zoom)));
- m_currentHistoryIndex = m_pageHistory.count() - 1;
- }
- emit currentZoomChanged();
- emit currentPageChanged();
- emit currentLocationChanged();
- if (m_changing)
- return;
- if (!backAvailableWas)
- emit backAvailableChanged();
- if (forwardAvailableWas)
- emit forwardAvailableChanged();
- if (emitJumped)
- emit jumped(page, location, zoom);
- qCDebug(qLcNav) << "push: index" << m_currentHistoryIndex << "page" << page
- << "@" << location << "zoom" << zoom << "-> history" <<
- [this]() {
- QStringList ret;
- for (auto d : m_pageHistory)
- ret << QString::number(d->page);
- return ret.join(QLatin1Char(','));
- }();
-}
-
-/*!
- \qmlmethod void PdfNavigationStack::update(int page, point location, qreal zoom)
-
- Modifies the current destination, consisting of \a page, \a location and \a zoom.
-
- This can be called periodically while the user is manually moving around
- the document, so that after back() is called, forward() will jump back to
- the most-recently-viewed destination rather than the destination that was
- last specified by push().
-
- The \c currentZoomChanged, \c currentPageChanged and \c currentLocationChanged
- signals will be emitted if the respective properties are actually changed.
- The \l jumped signal is not emitted, because this operation
- represents smooth movement rather than a navigational jump.
-*/
-void QQuickPdfNavigationStack::update(int page, QPointF location, qreal zoom)
-{
- if (m_currentHistoryIndex < 0 || m_currentHistoryIndex >= m_pageHistory.count())
- return;
- int currentPageWas = currentPage();
- QPointF currentLocationWas = currentLocation();
- qreal currentZoomWas = currentZoom();
- if (page == currentPageWas && location == currentLocationWas && zoom == currentZoomWas)
- return;
- m_pageHistory[m_currentHistoryIndex]->page = page;
- m_pageHistory[m_currentHistoryIndex]->location = location;
- m_pageHistory[m_currentHistoryIndex]->zoom = zoom;
- if (currentZoomWas != zoom)
- emit currentZoomChanged();
- if (currentPageWas != page)
- emit currentPageChanged();
- if (currentLocationWas != location)
- emit currentLocationChanged();
- qCDebug(qLcNav) << "update: index" << m_currentHistoryIndex << "page" << page
- << "@" << location << "zoom" << zoom << "-> history" <<
- [this]() {
- QStringList ret;
- for (auto d : m_pageHistory)
- ret << QString::number(d->page);
- return ret.join(QLatin1Char(','));
- }();
-}
-
-bool QQuickPdfNavigationStack::backAvailable() const
-{
- return m_currentHistoryIndex > 0;
-}
-
-bool QQuickPdfNavigationStack::forwardAvailable() const
-{
- return m_currentHistoryIndex < m_pageHistory.count() - 1;
-}
-
-/*!
- \qmlsignal PdfNavigationStack::jumped(int page, point location, qreal zoom)
-
- This signal is emitted when forward(), back() or push() is called, but not
- when update() is called.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/pdfquick/qquickpdfnavigationstack_p.h b/src/pdfquick/qquickpdfnavigationstack_p.h
deleted file mode 100644
index 1d37a4a85..000000000
--- a/src/pdfquick/qquickpdfnavigationstack_p.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKPDFNAVIGATIONSTACK_P_H
-#define QQUICKPDFNAVIGATIONSTACK_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
-#include <QtPdfQuick/private/qquickpdfdocument_p.h>
-#include <QtPdf/private/qpdfdestination_p.h>
-
-#include <QtQml/qqml.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_PDFQUICK_EXPORT QQuickPdfNavigationStack : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
- Q_PROPERTY(QPointF currentLocation READ currentLocation NOTIFY currentLocationChanged)
- Q_PROPERTY(qreal currentZoom READ currentZoom NOTIFY currentZoomChanged)
- Q_PROPERTY(bool backAvailable READ backAvailable NOTIFY backAvailableChanged)
- Q_PROPERTY(bool forwardAvailable READ forwardAvailable NOTIFY forwardAvailableChanged)
-
-public:
- explicit QQuickPdfNavigationStack(QObject *parent = nullptr);
-
- Q_INVOKABLE void push(int page, QPointF location, qreal zoom, bool emitJumped = true);
- Q_INVOKABLE void update(int page, QPointF location, qreal zoom);
- Q_INVOKABLE void forward();
- Q_INVOKABLE void back();
-
- int currentPage() const;
- QPointF currentLocation() const;
- qreal currentZoom() const;
-
- bool backAvailable() const;
- bool forwardAvailable() const;
-
-Q_SIGNALS:
- void currentPageChanged();
- void currentLocationChanged();
- void currentZoomChanged();
- void backAvailableChanged();
- void forwardAvailableChanged();
- void jumped(int page, QPointF location, qreal zoom);
-
-private:
- QList<QExplicitlySharedDataPointer<QPdfDestinationPrivate>> m_pageHistory;
- int m_currentHistoryIndex = 0;
- bool m_changing = false;
-
- Q_DISABLE_COPY(QQuickPdfNavigationStack)
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QQuickPdfNavigationStack)
-
-#endif // QQUICKPDFNAVIGATIONSTACK_P_H
diff --git a/src/pdfquick/qquickpdfpageimage.cpp b/src/pdfquick/qquickpdfpageimage.cpp
new file mode 100644
index 000000000..f2da067f1
--- /dev/null
+++ b/src/pdfquick/qquickpdfpageimage.cpp
@@ -0,0 +1,141 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickpdfpageimage_p.h"
+#include "qquickpdfdocument_p.h"
+#include <private/qpdffile_p.h>
+#include <QtQuick/private/qquickimage_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qLcImg, "qt.pdf.image")
+
+/*!
+ \qmltype PdfPageImage
+//! \instantiates QQuickPdfPageImage
+ \inqmlmodule QtQuick.Pdf
+ \ingroup pdf
+ \inherits Image
+ \brief Displays one page from a PDF document.
+ \since 6.4
+
+ The PdfPageImage type is an Image specialized to render a page from a PDF document.
+*/
+
+class QQuickPdfPageImagePrivate: public QQuickImagePrivate
+{
+public:
+ QQuickPdfPageImagePrivate() : QQuickImagePrivate() {}
+
+ QQuickPdfDocument *doc = nullptr;
+};
+
+QQuickPdfPageImage::QQuickPdfPageImage(QQuickItem *parent)
+ : QQuickImage(*(new QQuickPdfPageImagePrivate), parent)
+{
+}
+
+/*!
+ \internal
+*/
+QQuickPdfPageImage::~QQuickPdfPageImage()
+{
+ Q_D(QQuickPdfPageImage);
+ // cancel any async rendering job that is running on my behalf
+ d->pix.clear();
+}
+
+/*!
+ \qmlproperty PdfDocument PdfPageImage::document
+
+ This property holds the PDF document from which to render an image.
+*/
+void QQuickPdfPageImage::setDocument(QQuickPdfDocument *document)
+{
+ Q_D(QQuickPdfPageImage);
+ if (d->doc == document)
+ return;
+
+ if (d->doc)
+ disconnect(d->doc->document(), &QPdfDocument::statusChanged, this, &QQuickPdfPageImage::documentStatusChanged);
+ d->doc = document;
+ if (document) {
+ connect(document->document(), &QPdfDocument::statusChanged, this, &QQuickPdfPageImage::documentStatusChanged);
+ if (document->document()->status() == QPdfDocument::Status::Ready)
+ setSource(document->resolvedSource()); // calls load()
+ }
+ emit documentChanged();
+}
+
+QQuickPdfDocument *QQuickPdfPageImage::document() const
+{
+ Q_D(const QQuickPdfPageImage);
+ return d->doc;
+}
+
+void QQuickPdfPageImage::load()
+{
+ Q_D(QQuickPdfPageImage);
+ QUrl url = source();
+ if (!d->doc || !d->doc->carrierFile()) {
+ if (!url.isEmpty()) {
+ qmlWarning(this) << "document property not set: falling back to inefficient loading of " << url;
+ QQuickImageBase::load();
+ }
+ return;
+ }
+ if (url != d->doc->resolvedSource()) {
+ url = d->doc->resolvedSource();
+ qmlWarning(this) << "document and source properties in conflict: preferring document source " << url;
+ }
+ auto carrierFile = d->doc->carrierFile();
+ static int thisRequestProgress = -1;
+ static int thisRequestFinished = -1;
+ if (thisRequestProgress == -1) {
+ thisRequestProgress =
+ QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
+ thisRequestFinished =
+ QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()");
+ }
+
+ d->pix.loadImageFromDevice(qmlEngine(this), carrierFile, url,
+ d->sourceClipRect.toRect(), d->sourcesize * d->devicePixelRatio,
+ QQuickImageProviderOptions(), d->currentFrame, d->frameCount);
+
+ qCDebug(qLcImg) << "loading page" << d->currentFrame << "of" << d->frameCount
+ << "from" << carrierFile->fileName() << "status" << d->pix.status();
+
+ switch (d->pix.status()) {
+ case QQuickPixmap::Ready:
+ pixmapChange();
+ break;
+ case QQuickPixmap::Loading:
+ d->pix.connectFinished(this, thisRequestFinished);
+ d->pix.connectDownloadProgress(this, thisRequestProgress);
+ if (d->progress != 0.0) {
+ d->progress = 0.0;
+ emit progressChanged(d->progress);
+ }
+ if (d->status != Loading) {
+ d->status = Loading;
+ emit statusChanged(d->status);
+ }
+ break;
+ default:
+ qCDebug(qLcImg) << "unexpected status" << d->pix.status();
+ break;
+ }
+}
+
+void QQuickPdfPageImage::documentStatusChanged()
+{
+ Q_D(QQuickPdfPageImage);
+ const auto status = d->doc->document()->status();
+ qCDebug(qLcImg) << "document status" << status;
+ if (status == QPdfDocument::Status::Ready)
+ setSource(d->doc->resolvedSource()); // calls load()
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickpdfpageimage_p.cpp"
diff --git a/src/pdfquick/qquickpdfpageimage_p.h b/src/pdfquick/qquickpdfpageimage_p.h
new file mode 100644
index 000000000..daff052ac
--- /dev/null
+++ b/src/pdfquick/qquickpdfpageimage_p.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKPDFPAGEIMAGE_P_H
+#define QQUICKPDFPAGEIMAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
+#include <QtQuick/private/qquickimage_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickPdfDocument;
+class QQuickPdfPageImagePrivate;
+class Q_PDFQUICK_EXPORT QQuickPdfPageImage : public QQuickImage
+{
+ Q_OBJECT
+ Q_PROPERTY(QQuickPdfDocument* document READ document WRITE setDocument NOTIFY documentChanged FINAL)
+ QML_NAMED_ELEMENT(PdfPageImage)
+ QML_ADDED_IN_VERSION(6, 4)
+
+public:
+ QQuickPdfPageImage(QQuickItem *parent = nullptr);
+ ~QQuickPdfPageImage() override;
+
+ void setDocument(QQuickPdfDocument *document);
+ QQuickPdfDocument *document() const;
+
+signals:
+ void documentChanged();
+
+protected:
+ void load() override;
+ void documentStatusChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QQuickPdfPageImage)
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKPDFPAGEIMAGE_P_H
diff --git a/src/pdfquick/qquickpdfpagenavigator.cpp b/src/pdfquick/qquickpdfpagenavigator.cpp
new file mode 100644
index 000000000..939d928e9
--- /dev/null
+++ b/src/pdfquick/qquickpdfpagenavigator.cpp
@@ -0,0 +1,130 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickpdfpagenavigator_p.h"
+#include <QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype PdfPageNavigator
+//! \instantiates QQuickPdfPageNavigator
+ \inqmlmodule QtQuick.Pdf
+ \ingroup pdf
+ \brief History of the destinations visited within a PDF Document.
+ \since 5.15
+
+ PdfPageNavigator remembers which destinations the user has visited in a PDF
+ document, and provides the ability to traverse backward and forward.
+*/
+
+QQuickPdfPageNavigator::QQuickPdfPageNavigator(QObject *parent)
+ : QObject(parent)
+{
+}
+
+/*!
+ \internal
+*/
+QQuickPdfPageNavigator::~QQuickPdfPageNavigator() = default;
+
+/*!
+ \internal
+*/
+QPdfPageNavigator *QQuickPdfPageNavigator::navStack()
+{
+ return static_cast<QPdfPageNavigator *>(qmlExtendedObject(this));
+}
+
+/*!
+ \qmlmethod void PdfPageNavigator::forward()
+
+ Goes back to the page, location and zoom level that was being viewed before
+ back() was called, and then emits the \l jumped() signal.
+
+ If a new destination was pushed since the last time \l back() was called,
+ the forward() function does nothing, because there is a branch in the
+ timeline which causes the "future" to be lost.
+*/
+
+/*!
+ \qmlmethod void PdfPageNavigator::back()
+
+ Pops the stack, updates the \l currentPage, \l currentLocation and
+ \l currentZoom properties to the most-recently-viewed destination, and then
+ emits the \l jumped() signal.
+*/
+
+/*!
+ \qmlproperty int PdfPageNavigator::currentPage
+
+ This property holds the current page that is being viewed.
+ If there is no current page, it holds \c -1.
+*/
+
+/*!
+ \qmlproperty point PdfPageNavigator::currentLocation
+
+ This property holds the current location on the page that is being viewed.
+*/
+
+/*!
+ \qmlproperty real PdfPageNavigator::currentZoom
+
+ This property holds the magnification scale on the page that is being viewed.
+*/
+
+/*!
+ \qmlmethod void PdfPageNavigator::jump(int page, point location, qreal zoom, bool emitJumped)
+
+ Adds the given destination, consisting of \a page, \a location, and \a zoom,
+ to the history of visited locations. If \a emitJumped is \c false, the
+ \l jumped() signal will not be emitted.
+
+ If forwardAvailable is \c true, calling this function represents a branch
+ in the timeline which causes the "future" to be lost, and therefore
+ forwardAvailable will change to \c false.
+*/
+
+/*!
+ \qmlmethod void PdfPageNavigator::update(int page, point location, qreal zoom)
+
+ Modifies the current destination, consisting of \a page, \a location and \a zoom.
+
+ This can be called periodically while the user is manually moving around
+ the document, so that after back() is called, forward() will jump back to
+ the most-recently-viewed destination rather than the destination that was
+ last specified by jump().
+
+ The \c currentZoomChanged, \c currentPageChanged and \c currentLocationChanged
+ signals will be emitted if the respective properties are actually changed.
+ The \l jumped signal is not emitted, because this operation
+ represents smooth movement rather than a navigational jump.
+*/
+
+/*!
+ \qmlproperty bool PdfPageNavigator::backAvailable
+ \readonly
+
+ Holds \c true if a \e back destination is available in the history.
+*/
+
+/*!
+ \qmlproperty bool PdfPageNavigator::forwardAvailable
+ \readonly
+
+ Holds \c true if a \e forward destination is available in the history.
+*/
+
+/*!
+ \qmlsignal PdfPageNavigator::jumped(int page, point location, qreal zoom)
+
+ This signal is emitted when an abrupt jump occurs, to the specified \a page
+ index, \a location on the page, and \a zoom level; but \e not when simply
+ scrolling through the document one page at a time. That is, forward(),
+ back() and jump() always emit this signal; update() does not.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qquickpdfpagenavigator_p.cpp"
diff --git a/src/pdfquick/qquickpdfpagenavigator_p.h b/src/pdfquick/qquickpdfpagenavigator_p.h
new file mode 100644
index 000000000..2a2d92d6b
--- /dev/null
+++ b/src/pdfquick/qquickpdfpagenavigator_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKPDFPAGENAVIGATOR_P_H
+#define QQUICKPDFPAGENAVIGATOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
+#include <QtPdf/qpdfpagenavigator.h>
+#include <QtPdf/private/qpdflink_p.h>
+
+#include <QQmlEngine>
+
+QT_BEGIN_NAMESPACE
+
+struct Q_PDFQUICK_EXPORT QPdfLinkForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QPdfLink)
+ QML_VALUE_TYPE(pdfLink)
+ QML_ADDED_IN_VERSION(6, 4)
+};
+
+class Q_PDFQUICK_EXPORT QQuickPdfPageNavigator : public QObject
+{
+ Q_OBJECT
+ QML_EXTENDED(QPdfPageNavigator)
+ QML_NAMED_ELEMENT(PdfPageNavigator)
+ QML_ADDED_IN_VERSION(5, 15)
+
+public:
+ explicit QQuickPdfPageNavigator(QObject *parent = nullptr);
+ ~QQuickPdfPageNavigator() override;
+
+private:
+ QPdfPageNavigator *navStack();
+
+ Q_DISABLE_COPY(QQuickPdfPageNavigator)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickPdfPageNavigator)
+
+#endif // QQUICKPDFPAGENAVIGATOR_P_H
diff --git a/src/pdfquick/qquickpdfsearchmodel.cpp b/src/pdfquick/qquickpdfsearchmodel.cpp
index d91ca69f8..896584ad7 100644
--- a/src/pdfquick/qquickpdfsearchmodel.cpp
+++ b/src/pdfquick/qquickpdfsearchmodel.cpp
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpdfsearchmodel_p.h"
#include <QtCore/qloggingcategory.h>
@@ -43,7 +10,7 @@ Q_LOGGING_CATEGORY(qLcSearch, "qt.pdf.search")
/*!
\qmltype PdfSearchModel
- \instantiates QQuickPdfSearchModel
+//! \instantiates QQuickPdfSearchModel
\inqmlmodule QtQuick.Pdf
\ingroup pdf
\brief A representation of text search results within a PDF Document.
@@ -60,6 +27,11 @@ QQuickPdfSearchModel::QQuickPdfSearchModel(QObject *parent)
this, &QQuickPdfSearchModel::onResultsChanged);
}
+/*!
+ \internal
+*/
+QQuickPdfSearchModel::~QQuickPdfSearchModel() = default;
+
QQuickPdfDocument *QQuickPdfSearchModel::document() const
{
return m_quickDocument;
@@ -71,7 +43,7 @@ void QQuickPdfSearchModel::setDocument(QQuickPdfDocument *document)
return;
m_quickDocument = document;
- QPdfSearchModel::setDocument(&document->m_doc);
+ QPdfSearchModel::setDocument(document->document());
}
/*!
@@ -102,15 +74,16 @@ void QQuickPdfSearchModel::setDocument(QQuickPdfDocument *document)
}
\endqml
+ It becomes empty whenever \c {currentPage != currentResultLink.page}.
+
\sa PathMultiline
*/
QList<QPolygonF> QQuickPdfSearchModel::currentResultBoundingPolygons() const
{
QList<QPolygonF> ret;
- const auto &results = const_cast<QQuickPdfSearchModel *>(this)->resultsOnPage(m_currentPage);
- if (m_currentResult < 0 || m_currentResult >= results.count())
+ const auto result = currentResultLink();
+ if (result.page() != m_currentPage)
return ret;
- const auto result = results[m_currentResult];
for (auto rect : result.rectangles())
ret << QPolygonF(rect);
return ret;
@@ -119,23 +92,21 @@ QList<QPolygonF> QQuickPdfSearchModel::currentResultBoundingPolygons() const
/*!
\qmlproperty point PdfSearchModel::currentResultBoundingRect
- The bounding box containing all \l currentResultBoundingPolygons.
-
- When this property changes, a scrollable view should automatically scroll
- itself in such a way as to ensure that this region is visible; for example,
- it could try to position the upper-left corner near the upper-left of its
- own viewport, subject to the constraints of the scrollable area.
+ The bounding box containing all \l currentResultBoundingPolygons,
+ if \c {currentPage == currentResultLink.page}; otherwise, an invalid rectangle.
*/
QRectF QQuickPdfSearchModel::currentResultBoundingRect() const
{
QRectF ret;
- const auto &results = const_cast<QQuickPdfSearchModel *>(this)->resultsOnPage(m_currentPage);
- if (m_currentResult < 0 || m_currentResult >= results.count())
+ const auto result = currentResultLink();
+ if (result.page() != m_currentPage)
return ret;
- auto rects = results[m_currentResult].rectangles();
- ret = rects.takeFirst();
- for (auto rect : rects)
- ret = ret.united(rect);
+ auto rects = result.rectangles();
+ if (!rects.isEmpty()) {
+ ret = rects.takeFirst();
+ for (auto rect : rects)
+ ret = ret.united(rect);
+ }
return ret;
}
@@ -178,11 +149,11 @@ QList<QPolygonF> QQuickPdfSearchModel::currentPageBoundingPolygons() const
}
/*!
- \qmlfunction list<list<point>> PdfSearchModel::boundingPolygonsOnPage(int page)
+ \qmlmethod list<list<point>> PdfSearchModel::boundingPolygonsOnPage(int page)
Returns a set of paths in a form that can be bound to the \c paths property of a
- \l {QtQuick::PathMultiline}{PathMultiline} instance to render a batch of
- rectangles around all the locations where search results are found:
+ \l {QtQuick::PathMultiline}{PathMultiline} instance, which is used to render a
+ batch of rectangles around all the matching locations on the \a page:
\qml
PdfDocument {
@@ -205,15 +176,15 @@ QList<QPolygonF> QQuickPdfSearchModel::currentPageBoundingPolygons() const
*/
QList<QPolygonF> QQuickPdfSearchModel::boundingPolygonsOnPage(int page)
{
- if (!document() || searchString().isEmpty() || page < 0 || page > document()->pageCount())
+ if (!document() || searchString().isEmpty() || page < 0 || page > document()->document()->pageCount())
return {};
updatePage(page);
QList<QPolygonF> ret;
- auto m = QPdfSearchModel::resultsOnPage(page);
- for (auto result : m) {
- for (auto rect : result.rectangles())
+ const auto m = QPdfSearchModel::resultsOnPage(page);
+ for (const auto &result : m) {
+ for (const auto &rect : result.rectangles())
ret << QPolygonF(rect);
}
@@ -223,16 +194,18 @@ QList<QPolygonF> QQuickPdfSearchModel::boundingPolygonsOnPage(int page)
/*!
\qmlproperty int PdfSearchModel::currentPage
- The page on which \l currentMatchGeometry should provide filtered search results.
+ The page on which \l currentResultBoundingPolygons should provide filtered
+ search results.
*/
void QQuickPdfSearchModel::setCurrentPage(int currentPage)
{
- if (m_currentPage == currentPage)
+ if (m_currentPage == currentPage || !document())
return;
+ const auto pageCount = document()->document()->pageCount();
if (currentPage < 0)
- currentPage = document()->pageCount() - 1;
- else if (currentPage >= document()->pageCount())
+ currentPage = pageCount - 1;
+ else if (currentPage >= pageCount)
currentPage = 0;
m_currentPage = currentPage;
@@ -245,51 +218,50 @@ void QQuickPdfSearchModel::setCurrentPage(int currentPage)
/*!
\qmlproperty int PdfSearchModel::currentResult
- The result index on \l currentPage for which \l currentResultBoundingPolygons
- should provide the regions to highlight.
+ The result index within the whole set of search results, for which
+ \l currentResultBoundingPolygons should provide the regions to highlight
+ if currentPage matches \c currentResultLink.page.
*/
void QQuickPdfSearchModel::setCurrentResult(int currentResult)
{
if (m_currentResult == currentResult)
return;
- int currentResultWas = currentResult;
- int currentPageWas = m_currentPage;
- if (currentResult < 0) {
- setCurrentPage(m_currentPage - 1);
- while (resultsOnPage(m_currentPage).count() == 0 && m_currentPage != currentPageWas) {
- m_suspendSignals = true;
- setCurrentPage(m_currentPage - 1);
- }
- if (m_suspendSignals) {
- emit currentPageChanged();
- m_suspendSignals = false;
- }
- const auto results = resultsOnPage(m_currentPage);
- currentResult = results.count() - 1;
+ const int currentResultWas = m_currentResult;
+ const int currentPageWas = m_currentPage;
+ const int resultCount = rowCount({});
+
+ // wrap around at the ends
+ if (currentResult >= resultCount) {
+ currentResult = 0;
+ } else if (currentResult < 0) {
+ currentResult = resultCount - 1;
+ }
+
+ const QPdfLink link = resultAtIndex(currentResult);
+ if (link.isValid()) {
+ setCurrentPage(link.page());
+ m_currentResult = currentResult;
+ emit currentResultChanged();
+ emit currentResultLinkChanged();
+ emit currentResultBoundingPolygonsChanged();
+ emit currentResultBoundingRectChanged();
+ qCDebug(qLcSearch) << "currentResult was" << currentResultWas
+ << "requested" << currentResult << "on page" << currentPageWas
+ << "->" << m_currentResult << "on page" << m_currentPage;
} else {
- const auto results = resultsOnPage(m_currentPage);
- if (currentResult >= results.count()) {
- setCurrentPage(m_currentPage + 1);
- while (resultsOnPage(m_currentPage).count() == 0 && m_currentPage != currentPageWas) {
- m_suspendSignals = true;
- setCurrentPage(m_currentPage + 1);
- }
- if (m_suspendSignals) {
- emit currentPageChanged();
- m_suspendSignals = false;
- }
- currentResult = 0;
- }
+ qWarning() << "failed to find result" << currentResult << "in range 0 ->" << resultCount;
}
- qCDebug(qLcSearch) << "currentResult was" << m_currentResult
- << "requested" << currentResultWas << "on page" << currentPageWas
- << "->" << currentResult << "on page" << m_currentPage;
+}
- m_currentResult = currentResult;
- emit currentResultChanged();
- emit currentResultBoundingPolygonsChanged();
- emit currentResultBoundingRectChanged();
+/*!
+ \qmlproperty QPdfLink PdfSearchModel::currentResultLink
+
+ The result at index \l currentResult.
+*/
+QPdfLink QQuickPdfSearchModel::currentResultLink() const
+{
+ return resultAtIndex(m_currentResult);
}
/*!
@@ -298,4 +270,13 @@ void QQuickPdfSearchModel::setCurrentResult(int currentResult)
The string to search for.
*/
+/*!
+ \since 6.8
+ \qmlproperty int PdfSearchModel::count
+
+ The number of search results found.
+*/
+
QT_END_NAMESPACE
+
+#include "moc_qquickpdfsearchmodel_p.cpp"
diff --git a/src/pdfquick/qquickpdfsearchmodel_p.h b/src/pdfquick/qquickpdfsearchmodel_p.h
index ad92d4222..699cd719f 100644
--- a/src/pdfquick/qquickpdfsearchmodel_p.h
+++ b/src/pdfquick/qquickpdfsearchmodel_p.h
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKPDFSEARCHMODEL_P_H
#define QQUICKPDFSEARCHMODEL_P_H
@@ -50,10 +17,9 @@
#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
#include <QtPdfQuick/private/qquickpdfdocument_p.h>
-#include <QtPdf/qpdfsearchmodel.h>
-#include <QtCore/qvariant.h>
-#include <QtQml/qqml.h>
+#include <QtPdf/qpdfsearchmodel.h>
+#include <QtQml/QQmlEngine>
QT_BEGIN_NAMESPACE
@@ -63,12 +29,16 @@ class Q_PDFQUICK_EXPORT QQuickPdfSearchModel : public QPdfSearchModel
Q_PROPERTY(QQuickPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged)
Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged)
Q_PROPERTY(int currentResult READ currentResult WRITE setCurrentResult NOTIFY currentResultChanged)
+ Q_PROPERTY(QPdfLink currentResultLink READ currentResultLink NOTIFY currentResultLinkChanged)
Q_PROPERTY(QList<QPolygonF> currentPageBoundingPolygons READ currentPageBoundingPolygons NOTIFY currentPageBoundingPolygonsChanged)
Q_PROPERTY(QList<QPolygonF> currentResultBoundingPolygons READ currentResultBoundingPolygons NOTIFY currentResultBoundingPolygonsChanged)
Q_PROPERTY(QRectF currentResultBoundingRect READ currentResultBoundingRect NOTIFY currentResultBoundingRectChanged)
+ QML_NAMED_ELEMENT(PdfSearchModel)
+ QML_ADDED_IN_VERSION(5, 15)
public:
explicit QQuickPdfSearchModel(QObject *parent = nullptr);
+ ~QQuickPdfSearchModel() override;
QQuickPdfDocument *document() const;
void setDocument(QQuickPdfDocument * document);
@@ -81,14 +51,15 @@ public:
int currentResult() const { return m_currentResult; }
void setCurrentResult(int currentResult);
+ QPdfLink currentResultLink() const;
QList<QPolygonF> currentPageBoundingPolygons() const;
QList<QPolygonF> currentResultBoundingPolygons() const;
QRectF currentResultBoundingRect() const;
signals:
- void documentChanged();
void currentPageChanged();
void currentResultChanged();
+ void currentResultLinkChanged();
void currentPageBoundingPolygonsChanged();
void currentResultBoundingPolygonsChanged();
void currentResultBoundingRectChanged();
diff --git a/src/pdfquick/qquickpdfselection.cpp b/src/pdfquick/qquickpdfselection.cpp
index 54a13828a..4776cb8b4 100644
--- a/src/pdfquick/qquickpdfselection.cpp
+++ b/src/pdfquick/qquickpdfselection.cpp
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpdfselection_p.h"
#include "qquickpdfdocument_p.h"
@@ -53,16 +20,17 @@ static const QRegularExpression WordDelimiter(QStringLiteral("\\s"));
/*!
\qmltype PdfSelection
- \instantiates QQuickPdfSelection
+//! \instantiates QQuickPdfSelection
\inqmlmodule QtQuick.Pdf
\ingroup pdf
+ \inherits Item
\brief A representation of a text selection within a PDF Document.
\since 5.15
PdfSelection provides the text string and its geometry within a bounding box
from one point to another.
- To modify the selection using the mouse, bind \l fromPoint and \l toPoint
+ To modify the selection using the mouse, bind \l from and \l to
to the suitable properties of an input handler so that they will be set to
the positions where the drag gesture begins and ends, respectively; and
bind the \l hold property so that it will be set to \c true during the drag
@@ -73,19 +41,24 @@ static const QRegularExpression WordDelimiter(QStringLiteral("\\s"));
it must have keyboard focus.
*/
-/*!
- Constructs a SearchModel.
-*/
QQuickPdfSelection::QQuickPdfSelection(QQuickItem *parent)
: QQuickItem(parent)
{
#if QT_CONFIG(im)
setFlags(ItemIsFocusScope | ItemAcceptsInputMethod);
- // workaround to get Copy instead of Paste on the popover menu (QTBUG-83811)
- setProperty("qt_im_readonly", QVariant(true));
#endif
}
+/*!
+ \internal
+*/
+QQuickPdfSelection::~QQuickPdfSelection() = default;
+
+/*!
+ \qmlproperty PdfDocument PdfSelection::document
+
+ This property holds the PDF document in which to select text.
+*/
QQuickPdfDocument *QQuickPdfSelection::document() const
{
return m_document;
@@ -121,8 +94,8 @@ void QQuickPdfSelection::setDocument(QQuickPdfDocument *document)
PdfSelection {
id: selection
document: doc
- fromPoint: textSelectionDrag.centroid.pressPosition
- toPoint: textSelectionDrag.centroid.position
+ from: textSelectionDrag.centroid.pressPosition
+ to: textSelectionDrag.centroid.position
hold: !textSelectionDrag.active
}
Shape {
@@ -146,27 +119,39 @@ QList<QPolygonF> QQuickPdfSelection::geometry() const
return m_geometry;
}
+/*!
+ \qmlmethod void PdfSelection::clear()
+
+ Clears the current selection.
+*/
void QQuickPdfSelection::clear()
{
m_hitPoint = QPointF();
- m_fromPoint = QPointF();
- m_toPoint = QPointF();
+ m_from = QPointF();
+ m_to = QPointF();
m_heightAtAnchor = 0;
m_heightAtCursor = 0;
m_fromCharIndex = -1;
m_toCharIndex = -1;
m_text.clear();
m_geometry.clear();
- emit fromPointChanged();
- emit toPointChanged();
+ emit fromChanged();
+ emit toChanged();
emit textChanged();
emit selectedAreaChanged();
QGuiApplication::inputMethod()->update(Qt::ImQueryInput);
}
+/*!
+ \qmlmethod void PdfSelection::selectAll()
+
+ Selects all text on the current \l page.
+*/
void QQuickPdfSelection::selectAll()
{
- QPdfSelection sel = m_document->m_doc.getAllText(m_page);
+ if (!m_document)
+ return;
+ QPdfSelection sel = m_document->document()->getAllText(m_page);
if (sel.text() != m_text) {
m_text = sel.text();
if (QGuiApplication::clipboard()->supportsSelection())
@@ -182,11 +167,11 @@ void QQuickPdfSelection::selectAll()
m_fromCharIndex = sel.startIndex();
m_toCharIndex = sel.endIndex();
if (sel.bounds().isEmpty()) {
- m_fromPoint = QPointF();
- m_toPoint = QPointF();
+ m_from = QPointF();
+ m_to = QPointF();
} else {
- m_fromPoint = sel.bounds().first().boundingRect().topLeft() * m_renderScale;
- m_toPoint = sel.bounds().last().boundingRect().bottomRight() * m_renderScale - QPointF(0, m_heightAtCursor);
+ m_from = sel.bounds().first().boundingRect().topLeft() * m_renderScale;
+ m_to = sel.bounds().last().boundingRect().bottomRight() * m_renderScale - QPointF(0, m_heightAtCursor);
}
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle);
@@ -199,21 +184,25 @@ void QQuickPdfSelection::keyReleaseEvent(QKeyEvent *ev)
qCDebug(qLcIm) << "release" << ev;
const auto &allText = pageText();
if (ev == QKeySequence::MoveToPreviousWord) {
+ if (!m_document)
+ return;
// iOS sends MoveToPreviousWord first to get to the beginning of the word,
// and then SelectNextWord to select the whole word.
- int i = allText.lastIndexOf(WordDelimiter, m_fromCharIndex - allText.length());
+ int i = allText.lastIndexOf(WordDelimiter, m_fromCharIndex - allText.size());
if (i < 0)
i = 0;
else
i += 1; // don't select the space before the word
- auto sel = m_document->m_doc.getSelectionAtIndex(m_page, i, m_text.length() + m_fromCharIndex - i);
+ auto sel = m_document->document()->getSelectionAtIndex(m_page, i, m_text.size() + m_fromCharIndex - i);
update(sel);
QGuiApplication::inputMethod()->update(Qt::ImAnchorRectangle);
} else if (ev == QKeySequence::SelectNextWord) {
+ if (!m_document)
+ return;
int i = allText.indexOf(WordDelimiter, m_toCharIndex);
if (i < 0)
- i = allText.length(); // go to the end of m_textAfter
- auto sel = m_document->m_doc.getSelectionAtIndex(m_page, m_fromCharIndex, m_text.length() + i - m_toCharIndex);
+ i = allText.size(); // go to the end of m_textAfter
+ auto sel = m_document->document()->getSelectionAtIndex(m_page, m_fromCharIndex, m_text.size() + i - m_toCharIndex);
update(sel);
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
} else if (ev == QKeySequence::Copy) {
@@ -229,7 +218,9 @@ void QQuickPdfSelection::inputMethodEvent(QInputMethodEvent *event)
qCDebug(qLcIm) << "QInputMethodEvent::Cursor: moved to" << attr.start << "len" << attr.length;
break;
case QInputMethodEvent::Selection: {
- auto sel = m_document->m_doc.getSelectionAtIndex(m_page, attr.start, attr.length);
+ if (!m_document)
+ return;
+ auto sel = m_document->document()->getSelectionAtIndex(m_page, attr.start, attr.length);
update(sel);
qCDebug(qLcIm) << "QInputMethodEvent::Selection: from" << attr.start << "len" << attr.length
<< "result:" << m_fromCharIndex << "->" << m_toCharIndex << sel.boundingRectangle();
@@ -250,16 +241,18 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query, const
if (!argument.isNull()) {
qCDebug(qLcIm) << "IM query" << query << "with arg" << argument;
if (query == Qt::ImCursorPosition) {
+ if (!m_document)
+ return {};
// If it didn't move since last time, return the same result.
if (m_hitPoint == argument.toPointF())
return inputMethodQuery(query);
m_hitPoint = argument.toPointF();
- auto tp = m_document->m_doc.d->hitTest(m_page, m_hitPoint / m_renderScale);
+ auto tp = m_document->document()->d->hitTest(m_page, m_hitPoint / m_renderScale);
qCDebug(qLcIm) << "ImCursorPosition hit testing in px" << m_hitPoint << "pt" << (m_hitPoint / m_renderScale)
<< "got char index" << tp.charIndex << "@" << tp.position << "pt," << tp.position * m_renderScale << "px";
if (tp.charIndex >= 0) {
m_toCharIndex = tp.charIndex;
- m_toPoint = tp.position * m_renderScale - QPointF(0, m_heightAtCursor);
+ m_to = tp.position * m_renderScale - QPointF(0, m_heightAtCursor);
m_heightAtCursor = tp.height * m_renderScale;
if (qFuzzyIsNull(m_heightAtAnchor))
m_heightAtAnchor = m_heightAtCursor;
@@ -292,10 +285,10 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
ret = m_toCharIndex;
break;
case Qt::ImAnchorRectangle:
- ret = QRectF(m_fromPoint, QSizeF(1, m_heightAtAnchor));
+ ret = QRectF(m_from, QSizeF(1, m_heightAtAnchor));
break;
case Qt::ImCursorRectangle:
- ret = QRectF(m_toPoint, QSizeF(1, m_heightAtCursor));
+ ret = QRectF(m_to, QSizeF(1, m_heightAtCursor));
break;
case Qt::ImSurroundingText:
ret = QVariant(pageText());
@@ -324,6 +317,7 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
case Qt::ImPlatformData:
break;
case Qt::ImReadOnly:
+ ret = true;
break;
case Qt::ImQueryInput:
case Qt::ImQueryAll:
@@ -338,7 +332,9 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
const QString &QQuickPdfSelection::pageText() const
{
if (m_pageTextDirty) {
- m_pageText = m_document->m_doc.getAllText(m_page).text();
+ if (!m_document)
+ return m_pageText;
+ m_pageText = m_document->document()->getAllText(m_page).text();
m_pageTextDirty = false;
}
return m_pageText;
@@ -348,8 +344,8 @@ void QQuickPdfSelection::resetPoints()
{
bool wasHolding = m_hold;
m_hold = false;
- setFromPoint(QPointF());
- setToPoint(QPointF());
+ setFrom(QPointF());
+ setTo(QPointF());
m_hold = wasHolding;
}
@@ -380,7 +376,7 @@ void QQuickPdfSelection::setPage(int page)
\qmlproperty real PdfSelection::renderScale
\brief The ratio from points to pixels at which the page is rendered.
- This is used to scale \l fromPoint and \l toPoint to find ranges of
+ This is used to scale \l from and \l to to find ranges of
selected characters in the document, because positions within the document
are always given in points.
*/
@@ -391,6 +387,11 @@ qreal QQuickPdfSelection::renderScale() const
void QQuickPdfSelection::setRenderScale(qreal scale)
{
+ if (qFuzzyIsNull(scale)) {
+ qWarning() << "PdfSelection.renderScale cannot be set to 0.";
+ return;
+ }
+
if (qFuzzyCompare(scale, m_renderScale))
return;
@@ -400,7 +401,7 @@ void QQuickPdfSelection::setRenderScale(qreal scale)
}
/*!
- \qmlproperty point PdfSelection::fromPoint
+ \qmlproperty point PdfSelection::from
The beginning location, in pixels from the upper-left corner of the page,
from which to find selected text. This can be bound to the
@@ -408,41 +409,41 @@ void QQuickPdfSelection::setRenderScale(qreal scale)
the position where the user presses the mouse button and begins dragging,
for example.
*/
-QPointF QQuickPdfSelection::fromPoint() const
+QPointF QQuickPdfSelection::from() const
{
- return m_fromPoint;
+ return m_from;
}
-void QQuickPdfSelection::setFromPoint(QPointF fromPoint)
+void QQuickPdfSelection::setFrom(QPointF from)
{
- if (m_hold || m_fromPoint == fromPoint)
+ if (m_hold || m_from == from)
return;
- m_fromPoint = fromPoint;
- emit fromPointChanged();
+ m_from = from;
+ emit fromChanged();
updateResults();
}
/*!
- \qmlproperty point PdfSelection::toPoint
+ \qmlproperty point PdfSelection::to
The ending location, in pixels from the upper-left corner of the page,
from which to find selected text. This can be bound to the
\c centroid.position of a \l DragHandler to end selection of text at the
position where the user is currently dragging the mouse, for example.
*/
-QPointF QQuickPdfSelection::toPoint() const
+QPointF QQuickPdfSelection::to() const
{
- return m_toPoint;
+ return m_to;
}
-void QQuickPdfSelection::setToPoint(QPointF toPoint)
+void QQuickPdfSelection::setTo(QPointF to)
{
- if (m_hold || m_toPoint == toPoint)
+ if (m_hold || m_to == to)
return;
- m_toPoint = toPoint;
- emit toPointChanged();
+ m_to = to;
+ emit toChanged();
updateResults();
}
@@ -450,7 +451,7 @@ void QQuickPdfSelection::setToPoint(QPointF toPoint)
\qmlproperty bool PdfSelection::hold
Controls whether to hold the existing selection regardless of changes to
- \l fromPoint and \l toPoint. This property can be set to \c true when the mouse
+ \l from and \l to. This property can be set to \c true when the mouse
or touchpoint is released, so that the selection is not lost due to the
point bindings changing.
*/
@@ -494,8 +495,8 @@ void QQuickPdfSelection::updateResults()
{
if (!m_document)
return;
- QPdfSelection sel = m_document->document().getSelection(m_page,
- m_fromPoint / m_renderScale, m_toPoint / m_renderScale);
+ QPdfSelection sel = m_document->document()->getSelection(m_page,
+ m_from / m_renderScale, m_to / m_renderScale);
update(sel, true);
}
@@ -519,12 +520,12 @@ void QQuickPdfSelection::update(const QPdfSelection &sel, bool textAndGeometryOn
m_fromCharIndex = sel.startIndex();
m_toCharIndex = sel.endIndex();
if (sel.bounds().isEmpty()) {
- m_fromPoint = sel.boundingRectangle().topLeft() * m_renderScale;
- m_toPoint = m_fromPoint;
+ m_from = sel.boundingRectangle().topLeft() * m_renderScale;
+ m_to = m_from;
} else {
Qt::InputMethodQueries toUpdate = {};
QRectF firstLineBounds = sel.bounds().first().boundingRect();
- m_fromPoint = firstLineBounds.topLeft() * m_renderScale;
+ m_from = firstLineBounds.topLeft() * m_renderScale;
if (!qFuzzyCompare(m_heightAtAnchor, firstLineBounds.height())) {
m_heightAtAnchor = firstLineBounds.height() * m_renderScale;
toUpdate.setFlag(Qt::ImAnchorRectangle);
@@ -534,10 +535,12 @@ void QQuickPdfSelection::update(const QPdfSelection &sel, bool textAndGeometryOn
m_heightAtCursor = lastLineBounds.height() * m_renderScale;
toUpdate.setFlag(Qt::ImCursorRectangle);
}
- m_toPoint = lastLineBounds.topRight() * m_renderScale;
+ m_to = lastLineBounds.topRight() * m_renderScale;
if (toUpdate)
QGuiApplication::inputMethod()->update(toUpdate);
}
}
QT_END_NAMESPACE
+
+#include "moc_qquickpdfselection_p.cpp"
diff --git a/src/pdfquick/qquickpdfselection_p.h b/src/pdfquick/qquickpdfselection_p.h
index b364a6c03..4f633a467 100644
--- a/src/pdfquick/qquickpdfselection_p.h
+++ b/src/pdfquick/qquickpdfselection_p.h
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKPDFSELECTION_P_H
#define QQUICKPDFSELECTION_P_H
@@ -50,11 +17,12 @@
#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
#include <QtPdfQuick/private/qquickpdfdocument_p.h>
-#include <QPointF>
-#include <QPolygonF>
-#include <QVariant>
-#include <QtQml/qqml.h>
-#include <QtQuick/qquickitem.h>
+
+#include <QtCore/QPointF>
+#include <QtCore/QVariant>
+#include <QtGui/QPolygonF>
+#include <QtQml/QQmlEngine>
+#include <QtQuick/QQuickItem>
QT_BEGIN_NAMESPACE
class QPdfSelection;
@@ -65,15 +33,18 @@ class Q_PDFQUICK_EXPORT QQuickPdfSelection : public QQuickItem
Q_PROPERTY(QQuickPdfDocument *document READ document WRITE setDocument NOTIFY documentChanged)
Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged)
Q_PROPERTY(qreal renderScale READ renderScale WRITE setRenderScale NOTIFY renderScaleChanged)
- Q_PROPERTY(QPointF fromPoint READ fromPoint WRITE setFromPoint NOTIFY fromPointChanged)
- Q_PROPERTY(QPointF toPoint READ toPoint WRITE setToPoint NOTIFY toPointChanged)
+ Q_PROPERTY(QPointF from READ from WRITE setFrom NOTIFY fromChanged)
+ Q_PROPERTY(QPointF to READ to WRITE setTo NOTIFY toChanged)
Q_PROPERTY(bool hold READ hold WRITE setHold NOTIFY holdChanged)
Q_PROPERTY(QString text READ text NOTIFY textChanged)
Q_PROPERTY(QList<QPolygonF> geometry READ geometry NOTIFY selectedAreaChanged)
+ QML_NAMED_ELEMENT(PdfSelection)
+ QML_ADDED_IN_VERSION(5, 15)
public:
explicit QQuickPdfSelection(QQuickItem *parent = nullptr);
+ ~QQuickPdfSelection() override;
QQuickPdfDocument *document() const;
void setDocument(QQuickPdfDocument * document);
@@ -81,10 +52,10 @@ public:
void setPage(int page);
qreal renderScale() const;
void setRenderScale(qreal scale);
- QPointF fromPoint() const;
- void setFromPoint(QPointF fromPoint);
- QPointF toPoint() const;
- void setToPoint(QPointF toPoint);
+ QPointF from() const;
+ void setFrom(QPointF from);
+ QPointF to() const;
+ void setTo(QPointF to);
bool hold() const;
void setHold(bool hold);
@@ -101,8 +72,8 @@ signals:
void documentChanged();
void pageChanged();
void renderScaleChanged();
- void fromPointChanged();
- void toPointChanged();
+ void fromChanged();
+ void toChanged();
void holdChanged();
void textChanged();
void selectedAreaChanged();
@@ -124,8 +95,8 @@ private:
private:
QQuickPdfDocument *m_document = nullptr;
mutable QPointF m_hitPoint;
- QPointF m_fromPoint;
- mutable QPointF m_toPoint;
+ QPointF m_from;
+ mutable QPointF m_to;
qreal m_renderScale = 1;
mutable qreal m_heightAtAnchor = 0;
mutable qreal m_heightAtCursor = 0;
diff --git a/src/pdfquick/qquicktableviewextra.cpp b/src/pdfquick/qquicktableviewextra.cpp
deleted file mode 100644
index 017764a95..000000000
--- a/src/pdfquick/qquicktableviewextra.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qquicktableviewextra_p.h"
-#include <QtQml>
-#include <QQmlContext>
-
-Q_LOGGING_CATEGORY(qLcTVE, "qt.pdf.tableextra")
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \internal
- \qmltype TableViewExtra
- \instantiates QQuickTableViewExtra
- \inqmlmodule QtQuick.Pdf
- \ingroup pdf
- \brief A helper class with missing TableView functions
- \since 5.15
-
- TableViewExtra provides equivalents for some functions that will be added
- to TableView in Qt 6.
-*/
-
-QQuickTableViewExtra::QQuickTableViewExtra(QObject *parent) : QObject(parent)
-{
-}
-
-QPoint QQuickTableViewExtra::cellAtPos(qreal x, qreal y) const
-{
- QPointF position(x, y);
- return m_tableView->cellAtPos(position);
-}
-
-QQuickItem *QQuickTableViewExtra::itemAtCell(const QPoint &cell) const
-{
- return m_tableView->itemAtCell(cell);
-}
-
-void QQuickTableViewExtra::positionViewAtCell(const QPoint &cell, Qt::Alignment alignment, const QPointF &offset)
-{
- m_tableView->positionViewAtCell(cell, alignment, offset);
-}
-
-QT_END_NAMESPACE
diff --git a/src/pdfquick/qquicktableviewextra_p.h b/src/pdfquick/qquicktableviewextra_p.h
deleted file mode 100644
index 30eed696d..000000000
--- a/src/pdfquick/qquicktableviewextra_p.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKTABLEVIEWEXTRA_P_H
-#define QQUICKTABLEVIEWEXTRA_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtPdfQuick/private/qtpdfquickglobal_p.h>
-#include <QtQuick/private/qquicktableview_p.h>
-#include <QPointF>
-#include <QPolygonF>
-#include <QVariant>
-#include <QtQml/qqml.h>
-#include <QtQuick/qquickitem.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_PDFQUICK_EXPORT QQuickTableViewExtra : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QQuickTableView *tableView READ tableView WRITE setTableView)
-
-public:
- QQuickTableViewExtra(QObject *parent = nullptr);
-
- QQuickTableView * tableView() const { return m_tableView; }
- void setTableView(QQuickTableView * tableView) { m_tableView = tableView; }
-
- Q_INVOKABLE QPoint cellAtPos(qreal x, qreal y) const;
- Q_INVOKABLE QQuickItem *itemAtCell(int column, int row) const {
- return itemAtCell(QPoint(column, row));
- }
- Q_INVOKABLE QQuickItem *itemAtCell(const QPoint &cell) const;
- Q_INVOKABLE void positionViewAtCell(int column, int row, Qt::Alignment alignment, const QPointF &offset = QPointF()) {
- positionViewAtCell(QPoint(column, row), alignment, offset);
- }
- Q_INVOKABLE void positionViewAtCell(const QPoint &cell, Qt::Alignment alignment, const QPointF &offset);
- Q_INVOKABLE void positionViewAtRow(int row, Qt::Alignment alignment, qreal offset = 0) {
- positionViewAtCell(QPoint(0, row), alignment & Qt::AlignVertical_Mask, QPointF(0, offset));
- }
-
-private:
- QQuickTableView *m_tableView = nullptr;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QQuickTableViewExtra)
-
-#endif // QQUICKTABLEVIEWEXTRA_P_H
diff --git a/src/pdfquick/qtpdfquickglobal_p.h b/src/pdfquick/qtpdfquickglobal_p.h
index 567b10094..7b5d629ed 100644
--- a/src/pdfquick/qtpdfquickglobal_p.h
+++ b/src/pdfquick/qtpdfquickglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine 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$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTPDFQUICKGLOBAL_H
#define QTPDFQUICKGLOBAL_H