summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2020-01-27 14:45:07 +0100
committerMichal Klocek <michal.klocek@qt.io>2020-01-27 13:54:33 +0000
commiteda1b89972f8a3c87d8929ec4bcea20aabb78ab6 (patch)
tree87d7f98634b1f072cbcfb95998dc1850d7ac7491 /examples
parentfe9de69e014457de39ddb09c5773f546613e9727 (diff)
parenta06650f819ef164e6ec83d69957bd60d77574a16 (diff)
Merge remote-tracking branch 'origin/wip/qtpdf' into 5.15
Initial merge of QtPdf into QtWebEngine. Fixes: QTBUG-69519 Change-Id: I48dc25a59f2c161bb231bd0fa60392eb70fe4e7d
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro4
-rw-r--r--examples/pdf/pdf.pro3
-rw-r--r--examples/pdf/pdfviewer/main.cpp70
-rw-r--r--examples/pdf/pdfviewer/pdfviewer.pro14
-rw-r--r--examples/pdf/pdfviewer/resources/document-open.svg13
-rw-r--r--examples/pdf/pdfviewer/resources/edit-clear.svg15
-rw-r--r--examples/pdf/pdfviewer/resources/go-next-view-page.svg13
-rw-r--r--examples/pdf/pdfviewer/resources/go-previous-view-page.svg13
-rw-r--r--examples/pdf/pdfviewer/resources/rotate-left.svg6
-rw-r--r--examples/pdf/pdfviewer/resources/rotate-right.svg6
-rw-r--r--examples/pdf/pdfviewer/resources/zoom-in.svg13
-rw-r--r--examples/pdf/pdfviewer/resources/zoom-original.svg13
-rw-r--r--examples/pdf/pdfviewer/resources/zoom-out.svg13
-rw-r--r--examples/pdf/pdfviewer/viewer.qml202
-rw-r--r--examples/pdf/pdfviewer/viewer.qrc14
-rw-r--r--examples/pdfwidgets/pdfviewer/images/busy.pngbin0 -> 172 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/fileopen.pngbin0 -> 1771 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-next-24.pngbin0 -> 782 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-previous-24.pngbin0 -> 797 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-in-24.pngbin0 -> 1302 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-in-32.pngbin0 -> 1873 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-out-24.pngbin0 -> 1247 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-out-32.pngbin0 -> 1749 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/main.cpp51
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.cpp162
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.h90
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.ui281
-rw-r--r--examples/pdfwidgets/pdfviewer/pageselector.cpp111
-rw-r--r--examples/pdfwidgets/pdfviewer/pageselector.h72
-rw-r--r--examples/pdfwidgets/pdfviewer/pdfviewer.pro23
-rw-r--r--examples/pdfwidgets/pdfviewer/resources.qrc12
-rw-r--r--examples/pdfwidgets/pdfviewer/zoomselector.cpp97
-rw-r--r--examples/pdfwidgets/pdfviewer/zoomselector.h63
-rw-r--r--examples/pdfwidgets/pdfwidgets.pro2
34 files changed, 1376 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index 3dac9b0b7..b4f411aeb 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -3,3 +3,7 @@ TEMPLATE=subdirs
qtHaveModule(webengine): SUBDIRS += webengine
qtHaveModule(webenginewidgets): SUBDIRS += webenginewidgets
+
+qtHaveModule(pdfwidgets): SUBDIRS += pdfwidgets
+
+qtHaveModule(quick): qtHaveModule(pdf): qtHaveModule(pdfwidgets): SUBDIRS += pdf
diff --git a/examples/pdf/pdf.pro b/examples/pdf/pdf.pro
new file mode 100644
index 000000000..45df33e46
--- /dev/null
+++ b/examples/pdf/pdf.pro
@@ -0,0 +1,3 @@
+TEMPLATE=subdirs
+
+SUBDIRS += pdfviewer
diff --git a/examples/pdf/pdfviewer/main.cpp b/examples/pdf/pdfviewer/main.cpp
new file mode 100644
index 000000000..6b94a3de1
--- /dev/null
+++ b/examples/pdf/pdfviewer/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://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$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QQmlApplicationEngine>
+
+int main(int argc, char* argv[])
+{
+ QApplication app(argc, argv);
+ QCoreApplication::setApplicationName("Qt Quick PDF Viewer Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
+ QQmlApplicationEngine engine;
+ engine.load(QUrl(QStringLiteral("qrc:///pdfviewer/viewer.qml")));
+ if (app.arguments().count() > 1) {
+ QUrl toLoad = QUrl::fromUserInput(app.arguments().at(1));
+ engine.rootObjects().first()->setProperty("source", toLoad);
+ }
+
+ return app.exec();
+}
diff --git a/examples/pdf/pdfviewer/pdfviewer.pro b/examples/pdf/pdfviewer/pdfviewer.pro
new file mode 100644
index 000000000..697349cee
--- /dev/null
+++ b/examples/pdf/pdfviewer/pdfviewer.pro
@@ -0,0 +1,14 @@
+TEMPLATE = app
+
+QT += qml quick pdf widgets
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ viewer.qrc
+EXAMPLE_FILES = \
+ viewer.qml
+
+target.path = $$[QT_INSTALL_EXAMPLES]/pdf/pdfviewer
+INSTALLS += target
+
diff --git a/examples/pdf/pdfviewer/resources/document-open.svg b/examples/pdf/pdfviewer/resources/document-open.svg
new file mode 100644
index 000000000..bf23123a3
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/document-open.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="m4 4v24h24l-1-1h-22v-13h5l3-3h14v16l1 1v-21h-10l-3-3z"
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/edit-clear.svg b/examples/pdf/pdfviewer/resources/edit-clear.svg
new file mode 100644
index 000000000..1c35aaf04
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/edit-clear.svg
@@ -0,0 +1,15 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path
+ style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 8 3 L 0.94335938 10.056641 L 0 11 L 0.94335938 11.943359 L 8 19 L 20.333984 19 L 22 19 L 22 3 L 20.333984 3 L 8 3 z M 11.320312 7 L 14 9.6796875 L 16.679688 7 L 18 8.3203125 L 15.320312 11 L 18 13.679688 L 16.679688 15 L 14 12.320312 L 11.320312 15 L 10 13.679688 L 12.679688 11 L 10 8.3203125 L 11.320312 7 z "
+ class="ColorScheme-Text"
+ transform="translate(1,1)"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/go-next-view-page.svg b/examples/pdf/pdfviewer/resources/go-next-view-page.svg
new file mode 100644
index 000000000..e453ddbec
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/go-next-view-page.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 8.7070312 4 L 8 4.7070312 L 14.125 10.832031 L 15.292969 12 L 14.125 13.167969 L 8 19.292969 L 8.7070312 20 L 14.832031 13.875 L 16.707031 12 L 14.832031 10.125 L 8.7070312 4 z "
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/go-previous-view-page.svg b/examples/pdf/pdfviewer/resources/go-previous-view-page.svg
new file mode 100644
index 000000000..b032309e9
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/go-previous-view-page.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 15.292969 4 L 9.1679688 10.125 L 7.2929688 12 L 9.1679688 13.875 L 15.292969 20 L 16 19.292969 L 9.875 13.167969 L 8.7070312 12 L 9.875 10.832031 L 16 4.7070312 L 15.292969 4 z "
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/rotate-left.svg b/examples/pdf/pdfviewer/resources/rotate-left.svg
new file mode 100644
index 000000000..90ce53c9d
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/rotate-left.svg
@@ -0,0 +1,6 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
+ <g color="#000" font-weight="400" fill="#474747">
+ <path d="M2 9v1c0 .265.093.53.281.719l3.72 3.719 3.718-3.72c.188-.187.281-.453.281-.718V9H9c-.265 0-.53.093-.719.281l-2.28 2.281-2.282-2.28A1.015 1.015 0 0 0 3 9z"/>
+ <path d="M8.5 3A3.515 3.515 0 0 0 5 6.5V12h2V6.5C7 5.66 7.66 5 8.5 5H13V3z"/>
+ </g>
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/rotate-right.svg b/examples/pdf/pdfviewer/resources/rotate-right.svg
new file mode 100644
index 000000000..7383d1c84
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/rotate-right.svg
@@ -0,0 +1,6 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
+ <g font-weight="400" fill="#474747">
+ <path d="M3 3v2h4.5C8.34 5 9 5.66 9 6.5V12h2V6.5C11 4.579 9.421 3 7.5 3z"/>
+ <path d="M6 9h1c.257 0 .529.13.719.313L10 11.592l2.281-2.28C12.471 9.13 12.743 9 13 9h1v1c0 .31-.09.552-.281.75L10 14.406 6.281 10.75C6.091 10.552 6 10.31 6 10z"/>
+ </g>
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/zoom-in.svg b/examples/pdf/pdfviewer/resources/zoom-in.svg
new file mode 100644
index 000000000..efdc9f17d
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/zoom-in.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 4 4 L 4 6 L 5 6 L 5 5 L 6 5 L 6 4 L 4 4 z M 9 4 L 9 5 L 11 5 L 11 4 L 9 4 z M 13 4 L 13 5 L 15 5 L 15 4 L 13 4 z M 18 4 L 18 5 L 19 5 L 19 6 L 20 6 L 20 4 L 18 4 z M 12 8 L 12 9 L 14.292969 9 L 11 12.292969 L 11.707031 13 L 15 9.7070312 L 15 12 L 16 12 L 16 8 L 15 8 L 12 8 z M 4 9 L 4 11 L 5 11 L 5 9 L 4 9 z M 19 9 L 19 11 L 20 11 L 20 9 L 19 9 z M 19 13 L 19 15 L 20 15 L 20 13 L 19 13 z M 4 14 L 4 20 L 10 20 L 10 14 L 4 14 z M 5 15 L 9 15 L 9 19 L 5 19 L 5 15 z M 19 18 L 19 19 L 18 19 L 18 20 L 20 20 L 20 18 L 19 18 z "
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/zoom-original.svg b/examples/pdf/pdfviewer/resources/zoom-original.svg
new file mode 100644
index 000000000..1b4080a03
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/zoom-original.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 4 4 L 4 5 L 4 7 L 5 7 L 5 5 L 7 5 L 7 4 L 5 4 L 4 4 z M 17 4 L 17 5 L 19 5 L 19 7 L 20 7 L 20 5 L 20 4 L 19 4 L 17 4 z M 6 6 L 6 18 L 18 18 L 18 6 L 6 6 z M 7 7 L 17 7 L 17 17 L 7 17 L 7 7 z M 4 17 L 4 19 L 4 20 L 7 20 L 7 19 L 5 19 L 5 17 L 4 17 z M 19 17 L 19 19 L 17 19 L 17 20 L 20 20 L 20 17 L 19 17 z "
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/resources/zoom-out.svg b/examples/pdf/pdfviewer/resources/zoom-out.svg
new file mode 100644
index 000000000..fcde9e526
--- /dev/null
+++ b/examples/pdf/pdfviewer/resources/zoom-out.svg
@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <defs id="defs3051">
+ <style type="text/css" id="current-color-scheme">
+ .ColorScheme-Text {
+ color:#232629;
+ }
+ </style>
+ </defs>
+ <path style="fill:currentColor;fill-opacity:1;stroke:none"
+ d="M 4 4 L 4 11 L 5 11 L 5 5 L 19 5 L 19 19 L 13 19 L 13 20 L 20 20 L 20 19 L 20 5 L 20 4 L 5 4 L 4 4 z M 15.292969 8 L 12 11.292969 L 12 9 L 11 9 L 11 13 L 12 13 L 15 13 L 15 12 L 12.707031 12 L 16 8.7070312 L 15.292969 8 z M 4 14 L 4 16 L 5 16 L 5 15 L 6 15 L 6 14 L 4 14 z M 8 14 L 8 15 L 9 15 L 9 16 L 10 16 L 10 14 L 8 14 z M 4 18 L 4 20 L 6 20 L 6 19 L 5 19 L 5 18 L 4 18 z M 9 18 L 9 19 L 8 19 L 8 20 L 10 20 L 10 18 L 9 18 z "
+ class="ColorScheme-Text"
+ />
+</svg>
diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml
new file mode 100644
index 000000000..adc2a4b5b
--- /dev/null
+++ b/examples/pdf/pdfviewer/viewer.qml
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 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$
+**
+****************************************************************************/
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import QtQuick.Pdf 5.15
+import QtQuick.Shapes 1.15
+import QtQuick.Window 2.15
+import Qt.labs.platform 1.1 as Platform
+
+ApplicationWindow {
+ id: root
+ width: 800
+ height: 640
+ color: "lightgrey"
+ title: document.title
+ visible: true
+ property alias source: document.source // for main.cpp
+ property real scaleStep: Math.sqrt(2)
+
+ header: ToolBar {
+ RowLayout {
+ anchors.fill: parent
+ anchors.rightMargin: 6
+ ToolButton {
+ action: Action {
+ shortcut: StandardKey.Open
+ icon.source: "resources/document-open.svg"
+ onTriggered: fileDialog.open()
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: StandardKey.ZoomIn
+ enabled: pageView.sourceSize.width < 10000
+ icon.source: "resources/zoom-in.svg"
+ onTriggered: pageView.renderScale *= root.scaleStep
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: StandardKey.ZoomOut
+ enabled: pageView.sourceSize.width > 50
+ icon.source: "resources/zoom-out.svg"
+ onTriggered: pageView.renderScale /= root.scaleStep
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: "Ctrl+0"
+ icon.source: "resources/zoom-original.svg"
+ onTriggered: pageView.renderScale = 1
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: "Ctrl+L"
+ icon.source: "resources/rotate-left.svg"
+ onTriggered: pageView.rotation -= 90
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: "Ctrl+R"
+ icon.source: "resources/rotate-right.svg"
+ onTriggered: pageView.rotation += 90
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: StandardKey.MoveToPreviousPage
+ icon.source: "resources/go-previous-view-page.svg"
+ enabled: pageView.currentPage > 0
+ onTriggered: pageView.currentPage--
+ }
+ }
+ ToolButton {
+ action: Action {
+ shortcut: StandardKey.MoveToNextPage
+ icon.source: "resources/go-next-view-page.svg"
+ enabled: pageView.currentPage < pageView.pageCount - 1
+ onTriggered: pageView.currentPage++
+ }
+ }
+ TextField {
+ id: searchField
+ placeholderText: "search"
+ Layout.minimumWidth: 200
+ Layout.fillWidth: true
+ Image {
+ visible: searchField.text !== ""
+ source: "resources/edit-clear.svg"
+ anchors {
+ right: parent.right
+ top: parent.top
+ bottom: parent.bottom
+ margins: 3
+ rightMargin: 5
+ }
+ TapHandler {
+ onTapped: searchField.clear()
+ }
+ }
+ }
+ Shortcut {
+ sequence: StandardKey.Find
+ onActivated: searchField.forceActiveFocus()
+ }
+ Shortcut {
+ sequence: StandardKey.Quit
+ onActivated: Qt.quit()
+ }
+ }
+ }
+
+ Platform.FileDialog {
+ id: fileDialog
+ title: "Open a PDF file"
+ nameFilters: [ "PDF files (*.pdf)" ]
+ onAccepted: document.source = file
+ }
+
+ Dialog {
+ id: errorDialog
+ title: "Error loading " + document.source
+ standardButtons: Dialog.Ok
+ modal: true
+ closePolicy: Popup.CloseOnEscape
+ anchors.centerIn: parent
+ width: 300
+
+ Label {
+ id: errorField
+ text: document.error
+ }
+ }
+
+ PdfPageView {
+ id: pageView
+ document: PdfDocument {
+ id: document
+ onStatusChanged: if (status === PdfDocument.Error) errorDialog.open()
+ }
+ searchString: searchField.text
+ }
+
+ footer: Label {
+ property size implicitPointSize: document.pagePointSize(pageView.currentPage)
+ text: "page " + (pageView.currentPage + 1) + " of " + pageView.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
+ }
+}
diff --git a/examples/pdf/pdfviewer/viewer.qrc b/examples/pdf/pdfviewer/viewer.qrc
new file mode 100644
index 000000000..78f9c8d30
--- /dev/null
+++ b/examples/pdf/pdfviewer/viewer.qrc
@@ -0,0 +1,14 @@
+<RCC>
+ <qresource prefix="/pdfviewer">
+ <file>viewer.qml</file>
+ <file>resources/edit-clear.svg</file>
+ <file>resources/go-next-view-page.svg</file>
+ <file>resources/go-previous-view-page.svg</file>
+ <file>resources/rotate-left.svg</file>
+ <file>resources/rotate-right.svg</file>
+ <file>resources/zoom-in.svg</file>
+ <file>resources/zoom-original.svg</file>
+ <file>resources/zoom-out.svg</file>
+ <file>resources/document-open.svg</file>
+ </qresource>
+</RCC>
diff --git a/examples/pdfwidgets/pdfviewer/images/busy.png b/examples/pdfwidgets/pdfviewer/images/busy.png
new file mode 100644
index 000000000..69056c479
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/busy.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/fileopen.png b/examples/pdfwidgets/pdfviewer/images/fileopen.png
new file mode 100644
index 000000000..33e0d6394
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/fileopen.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-next-24.png b/examples/pdfwidgets/pdfviewer/images/go-next-24.png
new file mode 100644
index 000000000..9a55ef3d8
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-next-24.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-previous-24.png b/examples/pdfwidgets/pdfviewer/images/go-previous-24.png
new file mode 100644
index 000000000..2ea769eb8
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-previous-24.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png b/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png
new file mode 100644
index 000000000..d29b142b6
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png b/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png
new file mode 100644
index 000000000..34d70af37
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png b/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png
new file mode 100644
index 000000000..19703474f
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png b/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png
new file mode 100644
index 000000000..b83220661
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/main.cpp b/examples/pdfwidgets/pdfviewer/main.cpp
new file mode 100644
index 000000000..20fa6f8cd
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QUrl>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ QStringList args = a.arguments();
+ w.show();
+ if (args.length() > 1)
+ w.open(QUrl::fromLocalFile(args[1]));
+
+ return a.exec();
+}
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.cpp b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
new file mode 100644
index 000000000..5f9bf389f
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include "pageselector.h"
+#include "zoomselector.h"
+
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QPdfBookmarkModel>
+#include <QPdfDocument>
+#include <QPdfPageNavigation>
+#include <QtMath>
+
+const qreal zoomMultiplier = qSqrt(2.0);
+
+Q_LOGGING_CATEGORY(lcExample, "qt.examples.pdfviewer")
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+ , ui(new Ui::MainWindow)
+ , m_zoomSelector(new ZoomSelector(this))
+ , m_pageSelector(new PageSelector(this))
+ , m_document(new QPdfDocument(this))
+{
+ ui->setupUi(this);
+
+ m_zoomSelector->setMaximumWidth(150);
+ ui->mainToolBar->insertWidget(ui->actionZoom_In, m_zoomSelector);
+
+ m_pageSelector->setMaximumWidth(150);
+ ui->mainToolBar->addWidget(m_pageSelector);
+
+ m_pageSelector->setPageNavigation(ui->pdfView->pageNavigation());
+
+ connect(m_zoomSelector, &ZoomSelector::zoomModeChanged, ui->pdfView, &QPdfView::setZoomMode);
+ connect(m_zoomSelector, &ZoomSelector::zoomFactorChanged, ui->pdfView, &QPdfView::setZoomFactor);
+ m_zoomSelector->reset();
+
+ QPdfBookmarkModel *bookmarkModel = new QPdfBookmarkModel(this);
+ bookmarkModel->setDocument(m_document);
+
+ ui->bookmarkView->setModel(bookmarkModel);
+ connect(ui->bookmarkView, SIGNAL(activated(QModelIndex)), this, SLOT(bookmarkSelected(QModelIndex)));
+
+ ui->tabWidget->setTabEnabled(1, false); // disable 'Pages' tab for now
+
+ ui->pdfView->setDocument(m_document);
+
+ connect(ui->pdfView, &QPdfView::zoomFactorChanged,
+ m_zoomSelector, &ZoomSelector::setZoomFactor);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::open(const QUrl &docLocation)
+{
+ if (docLocation.isLocalFile()) {
+ m_document->load(docLocation.toLocalFile());
+ const auto documentTitle = m_document->metaData(QPdfDocument::Title).toString();
+ setWindowTitle(!documentTitle.isEmpty() ? documentTitle : QStringLiteral("PDF Viewer"));
+ } else {
+ qCDebug(lcExample) << docLocation << "is not a valid local file";
+ QMessageBox::critical(this, tr("Failed to open"), tr("%1 is not a valid local file").arg(docLocation.toString()));
+ }
+ qCDebug(lcExample) << docLocation;
+}
+
+void MainWindow::bookmarkSelected(const QModelIndex &index)
+{
+ if (!index.isValid())
+ return;
+
+ const int page = index.data(QPdfBookmarkModel::PageNumberRole).toInt();
+ ui->pdfView->pageNavigation()->setCurrentPage(page);
+}
+
+void MainWindow::on_actionOpen_triggered()
+{
+ QUrl toOpen = QFileDialog::getOpenFileUrl(this, tr("Choose a PDF"), QUrl(), "Portable Documents (*.pdf)");
+ if (toOpen.isValid())
+ open(toOpen);
+}
+
+void MainWindow::on_actionQuit_triggered()
+{
+ QApplication::quit();
+}
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this, tr("About PdfViewer"),
+ tr("An example using QPdfDocument"));
+}
+
+void MainWindow::on_actionAbout_Qt_triggered()
+{
+ QMessageBox::aboutQt(this);
+}
+
+void MainWindow::on_actionZoom_In_triggered()
+{
+ ui->pdfView->setZoomFactor(ui->pdfView->zoomFactor() * zoomMultiplier);
+}
+
+void MainWindow::on_actionZoom_Out_triggered()
+{
+ ui->pdfView->setZoomFactor(ui->pdfView->zoomFactor() / zoomMultiplier);
+}
+
+void MainWindow::on_actionPrevious_Page_triggered()
+{
+ ui->pdfView->pageNavigation()->goToPreviousPage();
+}
+
+void MainWindow::on_actionNext_Page_triggered()
+{
+ ui->pdfView->pageNavigation()->goToNextPage();
+}
+
+void MainWindow::on_actionContinuous_triggered()
+{
+ ui->pdfView->setPageMode(ui->actionContinuous->isChecked() ? QPdfView::MultiPage : QPdfView::SinglePage);
+}
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.h b/examples/pdfwidgets/pdfviewer/mainwindow.h
new file mode 100644
index 000000000..afdfcade4
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QLoggingCategory>
+#include <QMainWindow>
+
+Q_DECLARE_LOGGING_CATEGORY(lcExample)
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+class MainWindow;
+}
+
+class QPdfDocument;
+class QPdfView;
+QT_END_NAMESPACE
+
+class PageSelector;
+class ZoomSelector;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
+
+public slots:
+ void open(const QUrl &docLocation);
+
+private slots:
+ void bookmarkSelected(const QModelIndex &index);
+
+ // action handlers
+ void on_actionOpen_triggered();
+ void on_actionQuit_triggered();
+ void on_actionAbout_triggered();
+ void on_actionAbout_Qt_triggered();
+ void on_actionZoom_In_triggered();
+ void on_actionZoom_Out_triggered();
+ void on_actionPrevious_Page_triggered();
+ void on_actionNext_Page_triggered();
+ void on_actionContinuous_triggered();
+
+private:
+ Ui::MainWindow *ui;
+ ZoomSelector *m_zoomSelector;
+ PageSelector *m_pageSelector;
+
+ QPdfDocument *m_document;
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.ui b/examples/pdfwidgets/pdfviewer/mainwindow.ui
new file mode 100644
index 000000000..2651525a5
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.ui
@@ -0,0 +1,281 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>700</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>PDF Viewer</string>
+ </property>
+ <property name="unifiedTitleAndToolBarOnMac">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="tabPosition">
+ <enum>QTabWidget::West</enum>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <property name="documentMode">
+ <bool>false</bool>
+ </property>
+ <widget class="QWidget" name="bookmarkTab">
+ <attribute name="title">
+ <string>Bookmarks</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>2</number>
+ </property>
+ <property name="topMargin">
+ <number>2</number>
+ </property>
+ <property name="rightMargin">
+ <number>2</number>
+ </property>
+ <property name="bottomMargin">
+ <number>2</number>
+ </property>
+ <item>
+ <widget class="QTreeView" name="bookmarkView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="headerHidden">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="pagesTab">
+ <attribute name="title">
+ <string>Pages</string>
+ </attribute>
+ </widget>
+ </widget>
+ <widget class="QPdfView" name="pdfView" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>10</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>700</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ <addaction name="actionOpen"/>
+ <addaction name="actionQuit"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ <addaction name="actionAbout_Qt"/>
+ </widget>
+ <widget class="QMenu" name="menuView">
+ <property name="title">
+ <string>View</string>
+ </property>
+ <addaction name="actionZoom_In"/>
+ <addaction name="actionZoom_Out"/>
+ <addaction name="actionPrevious_Page"/>
+ <addaction name="actionNext_Page"/>
+ <addaction name="separator"/>
+ <addaction name="actionContinuous"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuView"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <property name="movable">
+ <bool>false</bool>
+ </property>
+ <property name="floatable">
+ <bool>false</bool>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionOpen"/>
+ <addaction name="separator"/>
+ <addaction name="actionZoom_Out"/>
+ <addaction name="actionZoom_In"/>
+ <addaction name="separator"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionOpen">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icons/images/fileopen.png</normaloff>:/icons/images/fileopen.png</iconset>
+ </property>
+ <property name="text">
+ <string>Open...</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionQuit">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>About</string>
+ </property>
+ </action>
+ <action name="actionAbout_Qt">
+ <property name="text">
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="actionZoom_In">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icons/images/zoom-in-24.png</normaloff>:/icons/images/zoom-in-24.png</iconset>
+ </property>
+ <property name="text">
+ <string>Zoom In</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+=</string>
+ </property>
+ </action>
+ <action name="actionZoom_Out">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icons/images/zoom-out-24.png</normaloff>:/icons/images/zoom-out-24.png</iconset>
+ </property>
+ <property name="text">
+ <string>Zoom Out</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+-</string>
+ </property>
+ </action>
+ <action name="actionPrevious_Page">
+ <property name="text">
+ <string>Previous Page</string>
+ </property>
+ <property name="shortcut">
+ <string>PgUp</string>
+ </property>
+ </action>
+ <action name="actionNext_Page">
+ <property name="text">
+ <string>Next Page</string>
+ </property>
+ <property name="shortcut">
+ <string>PgDown</string>
+ </property>
+ </action>
+ <action name="actionContinuous">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Continuous</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>QPdfView</class>
+ <extends>QWidget</extends>
+ <header location="global">qpdfview.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="resources.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/examples/pdfwidgets/pdfviewer/pageselector.cpp b/examples/pdfwidgets/pdfviewer/pageselector.cpp
new file mode 100644
index 000000000..cd3c4ba0e
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/pageselector.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pageselector.h"
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPdfPageNavigation>
+#include <QToolButton>
+
+PageSelector::PageSelector(QWidget *parent)
+ : QWidget(parent)
+ , m_pageNavigation(nullptr)
+{
+ QHBoxLayout *layout = new QHBoxLayout(this);
+
+ m_previousPageButton = new QToolButton(this);
+ m_previousPageButton->setText("<");
+ m_previousPageButton->setEnabled(false);
+
+ m_pageNumberEdit = new QLineEdit(this);
+ m_pageNumberEdit->setAlignment(Qt::AlignRight);
+
+ m_pageCountLabel = new QLabel(this);
+ m_pageCountLabel->setText("0");
+
+ m_nextPageButton = new QToolButton(this);
+ m_nextPageButton->setText(">");
+ m_nextPageButton->setEnabled(false);
+
+ layout->addWidget(m_previousPageButton);
+ layout->addWidget(m_pageNumberEdit);
+ layout->addWidget(m_pageCountLabel);
+ layout->addWidget(m_nextPageButton);
+}
+
+void PageSelector::setPageNavigation(QPdfPageNavigation *pageNavigation)
+{
+ m_pageNavigation = pageNavigation;
+
+ connect(m_previousPageButton, &QToolButton::clicked, m_pageNavigation, &QPdfPageNavigation::goToPreviousPage);
+ connect(m_pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged, m_previousPageButton, &QToolButton::setEnabled);
+
+ connect(m_pageNavigation, &QPdfPageNavigation::currentPageChanged, this, &PageSelector::onCurrentPageChanged);
+ connect(m_pageNavigation, &QPdfPageNavigation::pageCountChanged, this, [this](int pageCount){ m_pageCountLabel->setText(QString::fromLatin1("/ %1").arg(pageCount)); });
+
+ connect(m_pageNumberEdit, &QLineEdit::editingFinished, this, &PageSelector::pageNumberEdited);
+
+ connect(m_nextPageButton, &QToolButton::clicked, m_pageNavigation, &QPdfPageNavigation::goToNextPage);
+ connect(m_pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged, m_nextPageButton, &QToolButton::setEnabled);
+
+ onCurrentPageChanged(m_pageNavigation->currentPage());
+}
+
+void PageSelector::onCurrentPageChanged(int page)
+{
+ if (m_pageNavigation->pageCount() == 0)
+ m_pageNumberEdit->setText(QString::number(0));
+ else
+ m_pageNumberEdit->setText(QString::number(page + 1));
+}
+
+void PageSelector::pageNumberEdited()
+{
+ if (!m_pageNavigation)
+ return;
+
+ const QString text = m_pageNumberEdit->text();
+
+ bool ok = false;
+ const int pageNumber = text.toInt(&ok);
+
+ if (!ok)
+ onCurrentPageChanged(m_pageNavigation->currentPage());
+ else
+ m_pageNavigation->setCurrentPage(qBound(0, pageNumber - 1, m_pageNavigation->pageCount() - 1));
+}
diff --git a/examples/pdfwidgets/pdfviewer/pageselector.h b/examples/pdfwidgets/pdfviewer/pageselector.h
new file mode 100644
index 000000000..7a7283f99
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/pageselector.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PAGESELECTOR_H
+#define PAGESELECTOR_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QPdfDocument;
+class QPdfPageNavigation;
+class QToolButton;
+QT_END_NAMESPACE
+
+class PageSelector : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit PageSelector(QWidget *parent = nullptr);
+
+ void setPageNavigation(QPdfPageNavigation *pageNavigation);
+
+private slots:
+ void onCurrentPageChanged(int page);
+ void pageNumberEdited();
+
+private:
+ QPdfPageNavigation *m_pageNavigation;
+
+ QLineEdit *m_pageNumberEdit;
+ QLabel *m_pageCountLabel;
+ QToolButton *m_previousPageButton;
+ QToolButton *m_nextPageButton;
+};
+
+#endif // PAGESELECTOR_H
diff --git a/examples/pdfwidgets/pdfviewer/pdfviewer.pro b/examples/pdfwidgets/pdfviewer/pdfviewer.pro
new file mode 100644
index 000000000..ad0607ea5
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/pdfviewer.pro
@@ -0,0 +1,23 @@
+TEMPLATE = app
+TARGET = pdfviewer
+QT += core gui widgets pdfwidgets
+
+SOURCES += \
+ main.cpp \
+ mainwindow.cpp \
+ pageselector.cpp \
+ zoomselector.cpp
+
+HEADERS += \
+ mainwindow.h \
+ pageselector.h \
+ zoomselector.h
+
+FORMS += \
+ mainwindow.ui
+
+RESOURCES += \
+ resources.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/pdfwidgets/pdfviewer
+INSTALLS += target
diff --git a/examples/pdfwidgets/pdfviewer/resources.qrc b/examples/pdfwidgets/pdfviewer/resources.qrc
new file mode 100644
index 000000000..02d9655b4
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/resources.qrc
@@ -0,0 +1,12 @@
+<RCC>
+ <qresource prefix="/icons">
+ <file>images/fileopen.png</file>
+ <file>images/go-next-24.png</file>
+ <file>images/go-previous-24.png</file>
+ <file>images/zoom-in-24.png</file>
+ <file>images/zoom-in-32.png</file>
+ <file>images/zoom-out-24.png</file>
+ <file>images/zoom-out-32.png</file>
+ <file>images/busy.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/pdfwidgets/pdfviewer/zoomselector.cpp b/examples/pdfwidgets/pdfviewer/zoomselector.cpp
new file mode 100644
index 000000000..0205489aa
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/zoomselector.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "zoomselector.h"
+
+#include <QLineEdit>
+
+ZoomSelector::ZoomSelector(QWidget *parent)
+ : QComboBox(parent)
+{
+ setEditable(true);
+
+ addItem(QLatin1String("Fit Width"));
+ addItem(QLatin1String("Fit Page"));
+ addItem(QLatin1String("12%"));
+ addItem(QLatin1String("25%"));
+ addItem(QLatin1String("33%"));
+ addItem(QLatin1String("50%"));
+ addItem(QLatin1String("66%"));
+ addItem(QLatin1String("75%"));
+ addItem(QLatin1String("100%"));
+ addItem(QLatin1String("125%"));
+ addItem(QLatin1String("150%"));
+ addItem(QLatin1String("200%"));
+ addItem(QLatin1String("400%"));
+
+ connect(this, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
+ this, &ZoomSelector::onCurrentTextChanged);
+
+ connect(lineEdit(), &QLineEdit::editingFinished,
+ this, [this](){onCurrentTextChanged(lineEdit()->text()); });
+}
+
+void ZoomSelector::setZoomFactor(qreal zoomFactor)
+{
+ setCurrentText(QString::number(qRound(zoomFactor * 100)) + QLatin1String("%"));
+}
+
+void ZoomSelector::reset()
+{
+ setCurrentIndex(8); // 100%
+}
+
+void ZoomSelector::onCurrentTextChanged(const QString &text)
+{
+ if (text == QLatin1String("Fit Width")) {
+ emit zoomModeChanged(QPdfView::FitToWidth);
+ } else if (text == QLatin1String("Fit Page")) {
+ emit zoomModeChanged(QPdfView::FitInView);
+ } else {
+ qreal factor = 1.0;
+
+ QString withoutPercent(text);
+ withoutPercent.remove(QLatin1Char('%'));
+
+ bool ok = false;
+ const int zoomLevel = withoutPercent.toInt(&ok);
+ if (ok)
+ factor = zoomLevel / 100.0;
+
+ emit zoomModeChanged(QPdfView::CustomZoom);
+ emit zoomFactorChanged(factor);
+ }
+}
diff --git a/examples/pdfwidgets/pdfviewer/zoomselector.h b/examples/pdfwidgets/pdfviewer/zoomselector.h
new file mode 100644
index 000000000..c58d09970
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/zoomselector.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPDF module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ZOOMSELECTOR_H
+#define ZOOMSELECTOR_H
+
+#include <QComboBox>
+#include <QPdfView>
+
+class ZoomSelector : public QComboBox
+{
+ Q_OBJECT
+
+public:
+ explicit ZoomSelector(QWidget *parent = nullptr);
+
+public slots:
+ void setZoomFactor(qreal zoomFactor);
+
+ void reset();
+
+signals:
+ void zoomModeChanged(QPdfView::ZoomMode zoomMode);
+ void zoomFactorChanged(qreal zoomFactor);
+
+private slots:
+ void onCurrentTextChanged(const QString &text);
+};
+
+#endif // ZOOMSELECTOR_H
diff --git a/examples/pdfwidgets/pdfwidgets.pro b/examples/pdfwidgets/pdfwidgets.pro
new file mode 100644
index 000000000..a12dc5b86
--- /dev/null
+++ b/examples/pdfwidgets/pdfwidgets.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += pdfviewer