diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-19 17:47:01 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-19 18:21:00 +0100 |
commit | 1acd9ad2bfa1c54f19fa8a71fb41e8a90233f76b (patch) | |
tree | c1561556ef91ffe8a0ccd90aed16095a176fdf7a /examples/pdf/pdfviewer | |
parent | a2be3a7a79dc4fabe8675ea80a6ba550e0e4deec (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/pdfviewer')
-rw-r--r-- | examples/pdf/pdfviewer/main.cpp | 2 | ||||
-rw-r--r-- | examples/pdf/pdfviewer/pdfviewer.pro | 2 | ||||
-rw-r--r-- | examples/pdf/pdfviewer/resources/test.pdf | bin | 0 -> 80045 bytes | |||
-rw-r--r-- | examples/pdf/pdfviewer/viewer.qml | 3 | ||||
-rw-r--r-- | examples/pdf/pdfviewer/viewer.qrc | 3 |
5 files changed, 7 insertions, 3 deletions
diff --git a/examples/pdf/pdfviewer/main.cpp b/examples/pdf/pdfviewer/main.cpp index 639b11825..5f65e3061 100644 --- a/examples/pdf/pdfviewer/main.cpp +++ b/examples/pdf/pdfviewer/main.cpp @@ -64,6 +64,8 @@ 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/pdfviewer/pdfviewer.pro b/examples/pdf/pdfviewer/pdfviewer.pro index 697349cee..b8817c9be 100644 --- a/examples/pdf/pdfviewer/pdfviewer.pro +++ b/examples/pdf/pdfviewer/pdfviewer.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/pdfviewer/resources/test.pdf b/examples/pdf/pdfviewer/resources/test.pdf Binary files differnew file mode 100644 index 000000000..a9dc1bc29 --- /dev/null +++ b/examples/pdf/pdfviewer/resources/test.pdf diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml index 586a822a0..a2bccab44 100644 --- a/examples/pdf/pdfviewer/viewer.qml +++ b/examples/pdf/pdfviewer/viewer.qml @@ -63,7 +63,7 @@ ApplicationWindow { color: "lightgrey" title: document.title visible: true - property alias source: document.source // for main.cpp + property string source // for main.cpp property real scaleStep: Math.sqrt(2) header: ToolBar { @@ -204,6 +204,7 @@ ApplicationWindow { x: searchDrawer.position * searchDrawer.width // TODO binding gets broken during centering document: PdfDocument { id: document + source: Qt.resolvedUrl(root.source) onStatusChanged: if (status === PdfDocument.Error) errorDialog.open() } searchString: searchField.text diff --git a/examples/pdf/pdfviewer/viewer.qrc b/examples/pdf/pdfviewer/viewer.qrc index 9698a2689..1b6fa52f7 100644 --- a/examples/pdf/pdfviewer/viewer.qrc +++ b/examples/pdf/pdfviewer/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> |