From 24cd9f79bf7cf21e275b73ded63ee46bcc706db3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 17 Feb 2020 16:42:56 +0100 Subject: Rearrange PdfPageView.qml Now it looks more similar to PdfMultiPageView.qml: public properties and functions are grouped by functionality, implementation details are "below the fold", and properties and functions that we don't want to expose as API are nested inside inner items. Also fixed ColumnLayout attached properties. Change-Id: Iafe6f983a34ca6bac9b0d4f3a26aba5a426e0232 Reviewed-by: Shawn Rutledge --- examples/pdf/multipage/viewer.qml | 4 +- examples/pdf/pdfviewer/viewer.qml | 11 ++-- src/pdf/quick/qml/PdfPageView.qml | 113 +++++++++++++++++++------------------- 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 { -- cgit v1.2.3