diff options
Diffstat (limited to 'src/pdfquick/PdfPageView.qml')
-rw-r--r-- | src/pdfquick/PdfPageView.qml | 129 |
1 files changed, 45 insertions, 84 deletions
diff --git a/src/pdfquick/PdfPageView.qml b/src/pdfquick/PdfPageView.qml index eac4fb520..e1d97f57b 100644 --- a/src/pdfquick/PdfPageView.qml +++ b/src/pdfquick/PdfPageView.qml @@ -1,45 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2022 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtPDF module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// 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 -import Qt.labs.animation /*! \qmltype PdfPageView @@ -64,7 +30,7 @@ Rectangle { A PdfDocument object with a valid \c source URL is required: - \snippet multipageview.qml 0 + \snippet pdfpageview.qml 0 */ required property PdfDocument document @@ -73,8 +39,6 @@ Rectangle { This property holds the \l {QtQuick::Image::status}{rendering status} of the \l {currentPage}{current page}. - - \sa PdfPageImage::status */ property alias status: image.status @@ -124,9 +88,9 @@ Rectangle { \c onCurrentPageChanged script) to update the part of the user interface that shows the current page number, such as a \l SpinBox. - \sa PdfNavigationStack::currentPage + \sa PdfPageNavigator::currentPage */ - property alias currentPage: navigationStack.currentPage + property alias currentPage: pageNavigator.currentPage /*! \qmlproperty bool PdfPageView::backEnabled @@ -135,9 +99,9 @@ Rectangle { This property indicates if it is possible to go back in the navigation history to a previous-viewed page. - \sa PdfNavigationStack::backAvailable, back() + \sa PdfPageNavigator::backAvailable, back() */ - property alias backEnabled: navigationStack.backAvailable + property alias backEnabled: pageNavigator.backAvailable /*! \qmlproperty bool PdfPageView::forwardEnabled @@ -146,9 +110,9 @@ Rectangle { This property indicates if it is possible to go to next location in the navigation history. - \sa PdfNavigationStack::forwardAvailable, forward() + \sa PdfPageNavigator::forwardAvailable, forward() */ - property alias forwardEnabled: navigationStack.forwardAvailable + property alias forwardEnabled: pageNavigator.forwardAvailable /*! \qmlmethod void PdfPageView::back() @@ -157,9 +121,9 @@ Rectangle { recently; or does nothing if there is no previous location on the navigation stack. - \sa PdfNavigationStack::back(), currentPage, backEnabled + \sa PdfPageNavigator::back(), currentPage, backEnabled */ - function back() { navigationStack.back() } + function back() { pageNavigator.back() } /*! \qmlmethod void PdfPageView::forward() @@ -168,16 +132,16 @@ Rectangle { method was called; or does nothing if there is no "next" location on the navigation stack. - \sa PdfNavigationStack::forward(), currentPage + \sa PdfPageNavigator::forward(), currentPage */ - function forward() { navigationStack.forward() } + function forward() { pageNavigator.forward() } /*! \qmlmethod void PdfPageView::goToPage(int page) Changes the view to the \a page, if possible. - \sa PdfNavigationStack::jump(), currentPage + \sa PdfPageNavigator::jump(), currentPage */ function goToPage(page) { goToLocation(page, Qt.point(0, 0), 0) } @@ -187,12 +151,12 @@ Rectangle { Scrolls the view to the \a location on the \a page, if possible, and sets the \a zoom level. - \sa PdfNavigationStack::jump(), currentPage + \sa PdfPageNavigator::jump(), currentPage */ function goToLocation(page, location, zoom) { if (zoom > 0) root.renderScale = zoom - navigationStack.jump(page, location, zoom) + pageNavigator.jump(page, location, zoom) } // -------------------------------- @@ -213,8 +177,6 @@ Rectangle { 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 @@ -223,7 +185,7 @@ Rectangle { This property holds the scaled width and height of the full-frame image. - \sa PdfPageImage::sourceSize + \sa {QtQuick::Image::sourceSize}{Image.sourceSize} */ property alias sourceSize: image.sourceSize @@ -260,13 +222,13 @@ Rectangle { 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. + 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(navigationStack.currentPage) + const pagePointSize = document.pagePointSize(pageNavigator.currentPage) const pageAspect = pagePointSize.height / pagePointSize.width if (halfRotation > 45 && halfRotation < 135) { // rotated 90 or 270ยบ @@ -305,8 +267,8 @@ Rectangle { \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 - \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 */ @@ -339,9 +301,9 @@ Rectangle { 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) + 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 } @@ -351,14 +313,14 @@ Rectangle { onCurrentPageChanged: root.goToPage(currentPage) } - PdfNavigationStack { - id: navigationStack + PdfPageNavigator { + id: pageNavigator onCurrentPageChanged: searchModel.currentPage = currentPage onCurrentZoomChanged: root.renderScale = currentZoom property url documentSource: root.document.source onDocumentSourceChanged: { - navigationStack.clear() + pageNavigator.clear() root.goToPage(0) } } @@ -366,13 +328,13 @@ Rectangle { PdfPageImage { id: image document: root.document - currentPage: navigationStack.currentPage + 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(navigationStack.currentPage).width + 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 @@ -391,7 +353,7 @@ Rectangle { } } onRenderScaleChanged: { - image.sourceSize.width = document.pagePointSize(navigationStack.currentPage).width * renderScale + image.sourceSize.width = document.pagePointSize(pageNavigator.currentPage).width * renderScale image.sourceSize.height = 0 root.scale = 1 } @@ -431,22 +393,21 @@ Rectangle { model: PdfLinkModel { id: linkModel document: root.document - page: navigationStack.currentPage + page: pageNavigator.currentPage } - delegate: Item { - x: rect.x * image.pageScale - y: rect.y * image.pageScale - width: rect.width * image.pageScale - height: rect.height * image.pageScale - HoverHandler { cursorShape: Qt.PointingHandCursor } - TapHandler { - onTapped: { - if (page >= 0) - navigationStack.jump(page, Qt.point(0, 0), root.renderScale) + 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) } - } } } |