summaryrefslogtreecommitdiffstats
path: root/examples/pdf/multipage
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-02-19 17:47:01 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-02-19 18:21:00 +0100
commit1acd9ad2bfa1c54f19fa8a71fb41e8a90233f76b (patch)
treec1561556ef91ffe8a0ccd90aed16095a176fdf7a /examples/pdf/multipage
parenta2be3a7a79dc4fabe8675ea80a6ba550e0e4deec (diff)
QtPdf examples: use test.pdf from resources if no file given
On iOS, the native FileDialog doesn't work, sharing doesn't work, and packaging files along with the application requires manual effort; so a PDF file in resources seems to be the easiest alternative to make the examples demo-able. QPdfDocument wants a file path, because it uses QFile; but we like to use URLs in Qt Quick. So it's a bit of an impedance mismatch, there are several choices about when and where to do the conversion, and it's hard to say which way is more correct. This way happens to work for now. Also do the rest of the things necessary to get this working on iOS. Change-Id: Icb8614d5eed2510f101aefba534ef80cf890518f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/pdf/multipage')
-rw-r--r--examples/pdf/multipage/main.cpp3
-rw-r--r--examples/pdf/multipage/multipage.pro2
-rw-r--r--examples/pdf/multipage/resources/test.pdfbin0 -> 80045 bytes
-rw-r--r--examples/pdf/multipage/viewer.qml3
-rw-r--r--examples/pdf/multipage/viewer.qrc3
5 files changed, 8 insertions, 3 deletions
diff --git a/examples/pdf/multipage/main.cpp b/examples/pdf/multipage/main.cpp
index 7b766d77e..35aaa8c64 100644
--- a/examples/pdf/multipage/main.cpp
+++ b/examples/pdf/multipage/main.cpp
@@ -64,7 +64,10 @@ int main(int argc, char* argv[])
if (app.arguments().count() > 1) {
QUrl toLoad = QUrl::fromUserInput(app.arguments().at(1));
engine.rootObjects().first()->setProperty("source", toLoad);
+ } else {
+ engine.rootObjects().first()->setProperty("source", QStringLiteral("resources/test.pdf"));
}
+
return app.exec();
}
diff --git a/examples/pdf/multipage/multipage.pro b/examples/pdf/multipage/multipage.pro
index 5fff58fe1..5df9e653d 100644
--- a/examples/pdf/multipage/multipage.pro
+++ b/examples/pdf/multipage/multipage.pro
@@ -1,6 +1,6 @@
TEMPLATE = app
-QT += qml quick pdf widgets
+QT += qml quick pdf widgets svg
SOURCES += main.cpp
diff --git a/examples/pdf/multipage/resources/test.pdf b/examples/pdf/multipage/resources/test.pdf
new file mode 100644
index 000000000..a9dc1bc29
--- /dev/null
+++ b/examples/pdf/multipage/resources/test.pdf
Binary files differ
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml
index ba54065b7..ac6d2cd9a 100644
--- a/examples/pdf/multipage/viewer.qml
+++ b/examples/pdf/multipage/viewer.qml
@@ -62,7 +62,7 @@ ApplicationWindow {
color: "lightgrey"
title: document.title
visible: true
- property alias source: document.source // for main.cpp
+ property string source // for main.cpp
header: ToolBar {
RowLayout {
@@ -221,6 +221,7 @@ ApplicationWindow {
PdfDocument {
id: document
+ source: Qt.resolvedUrl(root.source)
onStatusChanged: {
if (status === PdfDocument.Error) errorDialog.open()
view.document = (status === PdfDocument.Ready ? document : undefined)
diff --git a/examples/pdf/multipage/viewer.qrc b/examples/pdf/multipage/viewer.qrc
index 9698a2689..1b6fa52f7 100644
--- a/examples/pdf/multipage/viewer.qrc
+++ b/examples/pdf/multipage/viewer.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/pdfviewer">
<file>viewer.qml</file>
+ <file>resources/document-open.svg</file>
<file>resources/edit-clear.svg</file>
<file>resources/edit-copy.svg</file>
<file>resources/go-down-search.svg</file>
@@ -9,11 +10,11 @@
<file>resources/go-up-search.svg</file>
<file>resources/rotate-left.svg</file>
<file>resources/rotate-right.svg</file>
+ <file>resources/test.pdf</file>
<file>resources/zoom-in.svg</file>
<file>resources/zoom-fit-best.svg</file>
<file>resources/zoom-fit-width.svg</file>
<file>resources/zoom-original.svg</file>
<file>resources/zoom-out.svg</file>
- <file>resources/document-open.svg</file>
</qresource>
</RCC>