diff options
Diffstat (limited to 'examples/pdf/multipage/viewer.qml')
-rw-r--r-- | examples/pdf/multipage/viewer.qml | 129 |
1 files changed, 48 insertions, 81 deletions
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml index ff6eb7fc5..55ca2994a 100644 --- a/examples/pdf/multipage/viewer.qml +++ b/examples/pdf/multipage/viewer.qml @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2022 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtQuick.Controls import QtQuick.Dialogs @@ -69,7 +22,7 @@ ApplicationWindow { ToolButton { action: Action { shortcut: StandardKey.Open - icon.source: "qrc:/pdfviewer/resources/document-open.svg" + icon.source: "qrc:/multipage/resources/document-open.svg" onTriggered: fileDialog.open() } } @@ -77,7 +30,7 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomIn enabled: view.renderScale < 10 - icon.source: "qrc:/pdfviewer/resources/zoom-in.svg" + icon.source: "qrc:/multipage/resources/zoom-in.svg" onTriggered: view.renderScale *= Math.sqrt(2) } } @@ -85,46 +38,46 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomOut enabled: view.renderScale > 0.1 - icon.source: "qrc:/pdfviewer/resources/zoom-out.svg" + icon.source: "qrc:/multipage/resources/zoom-out.svg" onTriggered: view.renderScale /= Math.sqrt(2) } } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/zoom-fit-width.svg" + icon.source: "qrc:/multipage/resources/zoom-fit-width.svg" onTriggered: view.scaleToWidth(root.contentItem.width, root.contentItem.height) } } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/zoom-fit-best.svg" + icon.source: "qrc:/multipage/resources/zoom-fit-best.svg" onTriggered: view.scaleToPage(root.contentItem.width, root.contentItem.height) } } ToolButton { action: Action { shortcut: "Ctrl+0" - icon.source: "qrc:/pdfviewer/resources/zoom-original.svg" + icon.source: "qrc:/multipage/resources/zoom-original.svg" onTriggered: view.resetScale() } } ToolButton { action: Action { shortcut: "Ctrl+L" - icon.source: "qrc:/pdfviewer/resources/rotate-left.svg" + icon.source: "qrc:/multipage/resources/rotate-left.svg" onTriggered: view.pageRotation -= 90 } } ToolButton { action: Action { shortcut: "Ctrl+R" - icon.source: "qrc:/pdfviewer/resources/rotate-right.svg" + icon.source: "qrc:/multipage/resources/rotate-right.svg" onTriggered: view.pageRotation += 90 } } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/go-previous-view-page.svg" + icon.source: "qrc:/multipage/resources/go-previous-view-page.svg" enabled: view.backEnabled onTriggered: view.back() } @@ -149,7 +102,7 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/go-next-view-page.svg" + icon.source: "qrc:/multipage/resources/go-next-view-page.svg" enabled: view.forwardEnabled onTriggered: view.forward() } @@ -160,21 +113,24 @@ ApplicationWindow { ToolButton { action: Action { shortcut: StandardKey.SelectAll - icon.source: "qrc:/pdfviewer/resources/edit-select-all.svg" + icon.source: "qrc:/multipage/resources/edit-select-all.svg" onTriggered: view.selectAll() } } ToolButton { action: Action { shortcut: StandardKey.Copy - icon.source: "qrc:/pdfviewer/resources/edit-copy.svg" + icon.source: "qrc:/multipage/resources/edit-copy.svg" enabled: view.selectedText !== "" onTriggered: view.copySelectionToClipboard() } } Shortcut { sequence: StandardKey.Find - onActivated: searchField.forceActiveFocus() + onActivated: { + searchField.forceActiveFocus() + searchField.selectAll() + } } Shortcut { sequence: StandardKey.Quit @@ -241,6 +197,19 @@ ApplicationWindow { onCurrentPageChanged: currentPageSB.value = view.currentPage + 1 } + DropArea { + anchors.fill: parent + keys: ["text/uri-list"] + onEntered: (drag) => { + drag.accepted = (drag.proposedAction === Qt.MoveAction || drag.proposedAction === Qt.CopyAction) && + drag.hasUrls && drag.urls[0].endsWith("pdf") + } + onDropped: (drop) => { + doc.source = drop.urls[0] + drop.acceptProposedAction() + } + } + Drawer { id: sidebar edge: Qt.LeftEdge @@ -308,13 +277,12 @@ ApplicationWindow { id: searchResultsList implicitHeight: parent.height model: view.searchModel + currentIndex: view.searchModel.currentResult ScrollBar.vertical: ScrollBar { } delegate: ItemDelegate { id: resultDelegate required property int index required property int page - required property int indexOnPage - required property point location required property string contextBefore required property string contextAfter width: parent ? parent.width : 0 @@ -344,11 +312,7 @@ ApplicationWindow { } } highlighted: ListView.isCurrentItem - onClicked: { - searchResultsList.currentIndex = resultDelegate.index - view.goToLocation(resultDelegate.page, resultDelegate.location, 0) - view.searchModel.currentResult = resultDelegate.indexOnPage - } + onClicked: view.searchModel.currentResult = resultDelegate.index } } TreeView { @@ -371,11 +335,13 @@ ApplicationWindow { id: thumbnailsView implicitWidth: parent.width implicitHeight: parent.height - model: doc.pageCount + model: doc.pageModel cellWidth: width / 2 cellHeight: cellWidth + 10 delegate: Item { required property int index + required property string label + required property size pointSize width: thumbnailsView.cellWidth height: thumbnailsView.cellHeight Rectangle { @@ -387,14 +353,13 @@ ApplicationWindow { PdfPageImage { id: image document: doc - currentPage: index + currentFrame: index asynchronous: true fillMode: Image.PreserveAspectFit - property size naturalSize: doc.pagePointSize(index) - property bool landscape: naturalSize.width > naturalSize.height + property bool landscape: pointSize.width > pointSize.height width: landscape ? thumbnailsView.cellWidth - 6 - : height * naturalSize.width / naturalSize.height - height: landscape ? width * naturalSize.height / naturalSize.width + : height * pointSize.width / pointSize.height + height: landscape ? width * pointSize.height / pointSize.width : thumbnailsView.cellHeight - 14 sourceSize.width: width sourceSize.height: height @@ -404,7 +369,7 @@ ApplicationWindow { id: pageNumber anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter - text: "Page " + (image.currentFrame + 1) + text: label } TapHandler { onTapped: view.goToPage(index) @@ -425,7 +390,7 @@ ApplicationWindow { id: sidebarOpenAction checkable: true checked: sidebar.opened - icon.source: checked ? "qrc:/pdfviewer/resources/sidebar-collapse-left.svg" : "qrc:/pdfviewer/resources/sidebar-expand-left.svg" + icon.source: checked ? "qrc:/multipage/resources/sidebar-collapse-left.svg" : "qrc:/multipage/resources/sidebar-expand-left.svg" onTriggered: sidebar.open() } ToolTip.visible: enabled && hovered @@ -434,8 +399,9 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/go-up-search.svg" + icon.source: "qrc:/multipage/resources/go-up-search.svg" shortcut: StandardKey.FindPrevious + enabled: view.searchModel.count > 0 onTriggered: view.searchBack() } ToolTip.visible: enabled && hovered @@ -450,11 +416,11 @@ ApplicationWindow { Layout.bottomMargin: 3 onAccepted: { sidebar.open() - sidebarTabs.setCurrentIndex(0) + sidebarTabs.setCurrentIndex(1) } Image { visible: searchField.text !== "" - source: "qrc:/pdfviewer/resources/edit-clear.svg" + source: "qrc:/multipage/resources/edit-clear.svg" sourceSize.height: searchField.height - 6 anchors { right: parent.right @@ -468,8 +434,9 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "qrc:/pdfviewer/resources/go-down-search.svg" + icon.source: "qrc:/multipage/resources/go-down-search.svg" shortcut: StandardKey.FindNext + enabled: view.searchModel.count > 0 onTriggered: view.searchForward() } ToolTip.visible: enabled && hovered |