summaryrefslogtreecommitdiffstats
path: root/src/pdfquick/PdfMultiPageView.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdfquick/PdfMultiPageView.qml')
-rw-r--r--src/pdfquick/PdfMultiPageView.qml90
1 files changed, 54 insertions, 36 deletions
diff --git a/src/pdfquick/PdfMultiPageView.qml b/src/pdfquick/PdfMultiPageView.qml
index 309088085..194d7866e 100644
--- a/src/pdfquick/PdfMultiPageView.qml
+++ b/src/pdfquick/PdfMultiPageView.qml
@@ -1,5 +1,8 @@
// 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
@@ -56,8 +59,8 @@ Item {
*/
function selectAll() {
const currentItem = tableView.itemAtCell(tableView.cellAtPos(root.width / 2, root.height / 2))
- if (currentItem)
- currentItem.selection.selectAll()
+ const pdfSelection = currentItem?.selection as PdfSelection
+ pdfSelection?.selectAll()
}
/*!
@@ -70,9 +73,9 @@ Item {
*/
function copySelectionToClipboard() {
const currentItem = tableView.itemAtCell(tableView.cellAtPos(root.width / 2, root.height / 2))
- console.log(lcMPV, "currentItem", currentItem, "sel", currentItem.selection.text)
- if (currentItem)
- currentItem.selection.copyToClipboard()
+ const pdfSelection = currentItem?.selection as PdfSelection
+ console.log(lcMPV, "currentItem", currentItem, "sel", pdfSelection?.text)
+ pdfSelection?.copyToClipboard()
}
// --------------------------------
@@ -159,6 +162,13 @@ Item {
\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
@@ -172,8 +182,6 @@ Item {
This property holds the \l {QtQuick::Image::status}{rendering status} of
the \l {currentPage}{current page}.
-
- \sa PdfPageImage::status
*/
property int currentPageRenderingStatus: Image.Null
@@ -185,8 +193,6 @@ Item {
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.
-
- \sa PdfPageImage::status
*/
property real renderScale: 1
@@ -197,8 +203,6 @@ Item {
The default value is \c 0 degrees (that is, no rotation relative to the
orientation of the pages as stored in the PDF file).
-
- \sa PdfPageImage::rotation
*/
property real pageRotation: 0
@@ -264,8 +268,8 @@ Item {
\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
- \l {QtQuick.Controls::TextField::text}{text} property of a TextField.
+ for. It is typically used in a binding to the \c text property of a
+ TextField.
\sa searchModel
*/
@@ -299,29 +303,40 @@ Item {
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: modelInUse && root.document ? 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
+ 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: document?.status === PdfDocument.Ready ? document.pagePointSize(0) : Qt.size(1, 1)
- property real pageHolderWidth: Math.max(root.width, ((rot90 ? document?.maxPageHeight : document?.maxPageWidth) ?? 0) * root.renderScale)
- columnWidthProvider: function(col) { return document ? pageHolderWidth + vscroll.width + 2 : 0 }
- rowHeightProvider: function(row) { return (rot90 ? document.pagePointSize(row).width : document.pagePointSize(row).height) * root.renderScale }
+ 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
@@ -336,12 +351,12 @@ Item {
height: image.height
rotation: root.pageRotation
anchors.centerIn: pinch.active ? undefined : parent
- property size pagePointSize: document.pagePointSize(index)
+ property size pagePointSize: root.document.pagePointSize(pageHolder.index)
property real pageScale: image.paintedWidth / pagePointSize.width
PdfPageImage {
id: image
document: root.document
- currentFrame: index
+ currentFrame: pageHolder.index
asynchronous: true
fillMode: Image.PreserveAspectFit
width: paper.pagePointSize.width * root.renderScale
@@ -355,7 +370,7 @@ Item {
searchHighlights.update()
}
onStatusChanged: {
- if (index === pageNavigator.currentPage)
+ if (pageHolder.index === pageNavigator.currentPage)
root.currentPageRenderingStatus = status
}
}
@@ -371,7 +386,7 @@ Item {
id: searchHighlights
function update() {
// paths could be a binding, but we need to be able to "kick" it sometimes
- paths = searchModel.boundingPolygonsOnPage(index)
+ paths = searchModel.boundingPolygonsOnPage(pageHolder.index)
}
}
}
@@ -392,7 +407,7 @@ Item {
}
Shape {
anchors.fill: parent
- visible: image.status === Image.Ready && searchModel.currentPage === index
+ visible: image.status === Image.Ready && searchModel.currentPage === pageHolder.index
ShapePath {
strokeWidth: style.currentSearchResultStrokeWidth
strokeColor: style.currentSearchResultStrokeColor
@@ -405,11 +420,10 @@ Item {
}
PinchHandler {
id: pinch
- minimumScale: 0.1
- maximumScale: root.renderScale < 4 ? 2 : 1
+ minimumScale: tableView.minScale / root.renderScale
+ maximumScale: Math.max(1, tableView.maxScale / root.renderScale)
minimumRotation: root.pageRotation
maximumRotation: root.pageRotation
- enabled: image.sourceSize.width < 5000
onActiveChanged:
if (active) {
paper.z = 10
@@ -420,12 +434,16 @@ Item {
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", index, "with centroid", pinch.centroid.position, centroidInPoints, "wrt flickable", centroidInFlickable,
+ 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
@@ -533,8 +551,8 @@ Item {
// and don't force layout either, because positionViewAtCell() will do that
if (pageNavigator.jumping)
return
- // make TableView rebuild from scratch, because otherwise it doesn't know the delegates are changing size
- tableView.rebuild()
+ // 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) {