summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/pdf/multipage/viewer.qml4
-rw-r--r--examples/pdf/pdfviewer/viewer.qml11
-rw-r--r--src/pdf/quick/qml/PdfPageView.qml113
3 files changed, 64 insertions, 64 deletions
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml
index 8f102a3c1..3a6347f5a 100644
--- a/examples/pdf/multipage/viewer.qml
+++ b/examples/pdf/multipage/viewer.qml
@@ -299,8 +299,8 @@ ApplicationWindow {
}
ListView {
id: searchResultsList
- ColumnLayout.fillWidth: true
- ColumnLayout.fillHeight: true
+ Layout.fillWidth: true
+ Layout.fillHeight: true
clip: true
model: view.searchModel
ScrollBar.vertical: ScrollBar { }
diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml
index e94642c5e..c63485dd3 100644
--- a/examples/pdf/pdfviewer/viewer.qml
+++ b/examples/pdf/pdfviewer/viewer.qml
@@ -271,8 +271,8 @@ ApplicationWindow {
}
ListView {
id: searchResultsList
- ColumnLayout.fillWidth: true
- ColumnLayout.fillHeight: true
+ Layout.fillWidth: true
+ Layout.fillHeight: true
clip: true
model: pageView.searchModel
ScrollBar.vertical: ScrollBar { }
@@ -292,10 +292,9 @@ ApplicationWindow {
footer: Label {
property size implicitPointSize: document.pagePointSize(pageView.currentPage)
- text: "page " + (pageView.currentPage + 1) + " of " + pageView.pageCount +
+ text: "page " + (pageView.currentPage + 1) + " of " + document.pageCount +
" scale " + pageView.renderScale.toFixed(2) +
- " sourceSize " + pageView.sourceSize.width.toFixed(1) + "x" + pageView.sourceSize.height.toFixed(1) +
- " original " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1)
- visible: pageView.pageCount > 0
+ " original " + implicitPointSize.width.toFixed(1) + "x" + implicitPointSize.height.toFixed(1) + "pts"
+ visible: document.status === PdfDocument.Ready
}
}
diff --git a/src/pdf/quick/qml/PdfPageView.qml b/src/pdf/quick/qml/PdfPageView.qml
index f4d7da0af..ec3cd78e0 100644
--- a/src/pdf/quick/qml/PdfPageView.qml
+++ b/src/pdf/quick/qml/PdfPageView.qml
@@ -39,19 +39,18 @@ import QtQuick.Pdf 5.15
import QtQuick.Shapes 1.14
Rectangle {
- id: paper
- width: image.width
- height: image.height
-
// public API
// TODO 5.15: required property
- property var document: null
- property real renderScale: 1
- property alias sourceSize: image.sourceSize
- property alias currentPage: navigationStack.currentPage
- property alias pageCount: image.frameCount
- property alias selectedText: selection.text
+ property var document: undefined
property alias status: image.status
+
+ property alias selectedText: selection.text
+ 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() }
@@ -59,34 +58,33 @@ Rectangle {
function goToPage(page) { goToLocation(page, Qt.point(0, 0), 0) }
function goToLocation(page, location, zoom) {
if (zoom > 0)
- paper.renderScale = zoom
+ root.renderScale = zoom
navigationStack.push(page, location, zoom)
}
- property real __pageScale: image.paintedWidth / document.pagePointSize(navigationStack.currentPage).width
-
+ // page scaling
+ property real renderScale: 1
+ property alias sourceSize: image.sourceSize
function resetScale() {
image.sourceSize.width = 0
image.sourceSize.height = 0
- paper.x = 0
- paper.y = 0
- paper.scale = 1
+ root.x = 0
+ root.y = 0
+ root.scale = 1
}
-
function scaleToWidth(width, height) {
- var halfRotation = Math.abs(paper.rotation % 180)
+ var halfRotation = Math.abs(root.rotation % 180)
image.sourceSize = Qt.size((halfRotation > 45 && halfRotation < 135) ? height : width, 0)
- paper.x = 0
- paper.y = 0
+ root.x = 0
+ root.y = 0
image.centerInSize = Qt.size(width, height)
image.centerOnLoad = true
image.vCenterOnLoad = (halfRotation > 45 && halfRotation < 135)
- paper.scale = 1
+ root.scale = 1
}
-
function scaleToPage(width, height) {
var windowAspect = width / height
- var halfRotation = Math.abs(paper.rotation % 180)
+ var halfRotation = Math.abs(root.rotation % 180)
var pagePointSize = document.pagePointSize(navigationStack.currentPage)
if (halfRotation > 45 && halfRotation < 135) {
// rotated 90 or 270ยบ
@@ -107,7 +105,7 @@ Rectangle {
image.centerInSize = Qt.size(width, height)
image.centerOnLoad = true
image.vCenterOnLoad = true
- paper.scale = 1
+ root.scale = 1
}
// text search
@@ -116,29 +114,31 @@ Rectangle {
function searchBack() { --searchModel.currentResult }
function searchForward() { ++searchModel.currentResult }
+ // implementation
+ id: root
+ width: image.width
+ height: image.height
+
PdfSelection {
id: selection
- document: paper.document
+ document: root.document
page: navigationStack.currentPage
- fromPoint: Qt.point(textSelectionDrag.centroid.pressPosition.x / paper.__pageScale, textSelectionDrag.centroid.pressPosition.y / paper.__pageScale)
- toPoint: Qt.point(textSelectionDrag.centroid.position.x / paper.__pageScale, textSelectionDrag.centroid.position.y / paper.__pageScale)
+ 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
}
- function copySelectionToClipboard() {
- selection.copyToClipboard()
- }
PdfSearchModel {
id: searchModel
- document: paper.document === undefined ? null : paper.document
- currentPage: navigationStack.currentPage
- onCurrentPageChanged: paper.goToPage(currentPage)
+ 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: paper.renderScale = currentZoom
+ onCurrentZoomChanged: root.renderScale = currentZoom
// TODO deal with horizontal location (need WheelHandler or Flickable probably)
}
@@ -151,27 +151,28 @@ Rectangle {
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) {
- paper.x = (centerInSize.width - image.implicitWidth) / 2
- paper.y = vCenterOnLoad ? (centerInSize.height - image.implicitHeight) / 2 : 0
+ root.x = (centerInSize.width - image.implicitWidth) / 2
+ root.y = vCenterOnLoad ? (centerInSize.height - image.implicitHeight) / 2 : 0
centerOnLoad = false
vCenterOnLoad = false
}
}
- function reRenderIfNecessary() {
- var newSourceWidth = image.sourceSize.width * paper.scale
- var ratio = newSourceWidth / image.sourceSize.width
- if (ratio > 1.1 || ratio < 0.9) {
- image.sourceSize.width = newSourceWidth
- image.sourceSize.height = 0
- paper.scale = 1
- }
- }
onRenderScaleChanged: {
image.sourceSize.width = document.pagePointSize(navigationStack.currentPage).width * renderScale
image.sourceSize.height = 0
- paper.scale = 1
+ root.scale = 1
}
Shape {
@@ -182,7 +183,7 @@ Rectangle {
strokeWidth: 1
strokeColor: "cyan"
fillColor: "steelblue"
- scale: Qt.size(paper.__pageScale, paper.__pageScale)
+ scale: Qt.size(image.pageScale, image.pageScale)
PathMultiline {
paths: searchModel.currentPageBoundingPolygons
}
@@ -191,14 +192,14 @@ Rectangle {
strokeWidth: 1
strokeColor: "orange"
fillColor: "cyan"
- scale: Qt.size(paper.__pageScale, paper.__pageScale)
+ scale: Qt.size(image.pageScale, image.pageScale)
PathMultiline {
paths: searchModel.currentResultBoundingPolygons
}
}
ShapePath {
fillColor: "orange"
- scale: Qt.size(paper.__pageScale, paper.__pageScale)
+ scale: Qt.size(image.pageScale, image.pageScale)
PathMultiline {
paths: selection.geometry
}
@@ -208,22 +209,22 @@ Rectangle {
Repeater {
model: PdfLinkModel {
id: linkModel
- document: paper.document
+ document: root.document
page: navigationStack.currentPage
}
delegate: Rectangle {
color: "transparent"
border.color: "lightgrey"
- x: rect.x * paper.__pageScale
- y: rect.y * paper.__pageScale
- width: rect.width * paper.__pageScale
- height: rect.height * paper.__pageScale
+ 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), paper.renderScale)
+ navigationStack.push(page, Qt.point(0, 0), root.renderScale)
else
Qt.openUrlExternally(url)
}
@@ -237,7 +238,7 @@ Rectangle {
maximumScale: 10
minimumRotation: 0
maximumRotation: 0
- onActiveChanged: if (!active) paper.reRenderIfNecessary()
+ onActiveChanged: if (!active) image.reRenderIfNecessary()
grabPermissions: PinchHandler.TakeOverForbidden // don't allow takeover if pinch has started
}
DragHandler {