summaryrefslogtreecommitdiffstats
path: root/examples/pdf/pdfviewer
Commit message (Collapse)AuthorAgeFilesLines
* doc: Add docs for the pdfviewer exampleShawn Rutledge2024-01-1921-626/+0
| | | | | | | | | | | This example exists to show a simpler viewer using PdfScrollablePageView rather than PdfMultiPageView. Most users will probably prefer the latter, so we don't highlight this one. Pick-to: 6.7 Task-number: QTBUG-81560 Change-Id: Ia601b8c8ec0cb9002aa118917720a37b4f8095a5 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* PDF Quick examples: select text in search field when pressing Ctrl-FShawn Rutledge2024-01-061-1/+4
| | | | | | | | | | | | It's better for usability in case the user is doing repeated searches: press control-F and start typing to search for different text, rather than needing to do something else to select or delete the existing text in the search field. Fixes: QTBUG-120447 Pick-to: 6.2 6.5 6.6 6.7 Change-Id: I8d5a519a631c406dff91198b23a022856609fa4c Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Add PdfSearchModel.count; disable search up/down buttons if emptyShawn Rutledge2023-12-301-0/+2
| | | | | | | | | | | | | | | A crash was possible if there are no search results and the user presses the up/down buttons alongside the search field on the toolbar. That was easily fixed (in a previous patch); but actually those buttons should be disabled if there are no results to navigate. To do that, we need a notifying property rather than depending on the invokable QAIM::rowCount(). Follow the usual pattern for a one-dimensional model: add a `count` property in the subclass (as in XmlListModel, FolderListModel, CalendarModel, and a few others). Task-number: QTBUG-119776 Change-Id: I51c75b58f3a440c1c470794518a572b384376ea7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Polish the QML/PdfViewer exampleFriedemann Kleint2022-09-082-8/+21
| | | | | | | | | | | - Use QCommandLineParser - Use QmlEngine::setInitialProperties() instead of context properties and make "source" a required property of type url - Use startup documents from resource Pick-to: 6.4 Change-Id: Idaad82be4d7cf862de96240af031ed317a401266 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Change the license of all CMakeLists.txt and *.cmake files to BSDLucie Gérard2022-08-261-1/+1
| | | | | | Task-number: QTBUG-105718 Change-Id: I2ad190e5536cdbdc8d2656e61892545d66911a02 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Add license headers to cmake filesLucie Gérard2022-07-071-0/+3
| | | | | | | | | | | | CMakeLists.txt and .cmake files of significant size (more than 2 lines according to our check in tst_license.pl) now have the copyright and license header. Existing copyright statements remain intact Task-number: QTBUG-88621 Change-Id: I118bd63694cfe2c9a413af4a38828a31727f8e86 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-222-98/+4
| | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I869ffda1080e283f231eb0dc4477b260f2054d99 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Redefine PdfSearchModel.currentResult as document-based; use PdfLinkShawn Rutledge2022-06-041-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PdfSearchModel.currentResult is now the index within the whole list of search results, rather than starting over from 0 on each page. This simplifies some code. The way that PdfMultiPageView uses PdfSearchModel, the currentPage property is read-only: it tells the page of currentResult (which we need in the view, because each page has the ability to show a current-search-result highlight shape, but only one page actually needs to show it). The controls in a viewer to iterate search results (up and down arrows in the footer) simply increment and derement currentResult; the currentPage property gets updated to tell the view which page currently holds currentResult; and the ListView highlight follows along in the sidebar too, because ListView.currentIndex is now bound to searchModel.currentResult. But in PdfScrollablePageView, we still need to bind the currentPage property, to get the currentPageBoundingPolygons property updated when we switch pages. Since that viewer only sees one page at a time, it's much more declarative to do it that way, rather than calling the invokable boundingPolygonsOnPage(int) function. Bindings get updated on their own; whereas in PdfMultiPageView it's a bit inelegant that we need to call boundingPolygonsOnPage() repeatedly, at the right times so that the highlights are never shown in the wrong places at the wrong time. It could be avoided if we had a separate per-page model object to filter the results from the main PdfSearchModel; but that would add significant API complexity, and perhaps be too confusing for anyone who tries to re-implement a QML-based viewer component. The current search result highlight now stays on the page where the user left it: scrolling manually to another page will no longer choose a current result on the new page, as it did before. This is more consistent with typical applications. A currentResultLink property is added, to make it easy to call PdfPageNavigator.jump(link), thus passing along the QPdfLink.rectangles. The same link object gets re-emitted in the PdfPageNavigator.jumped signal to tell the view to scroll in such a way as to get those rectangles visible in the viewport, via TableView.positionViewAtCell(). There are a couple of drive-by fixes: QQuickPdfSearchModel::documentChanged() doesn't need to be declared, because we are using the signal inherited from QPdfSearchModel. And const-correctness is improved in the implementation of boundingPolygonsOnPage(). [ChangeLog][QtPDF] PdfSearchModel.currentResult is now the result index within the whole set of search results rather than on currentPage; and changing currentPage no longer makes currentResult change. In the views, this means the current highlighted search result stays on the same page even when the user views a different page. Change-Id: I96957f50e703f62101b3d3c708ff5f27b162cd8d Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Renumber pages in test.pdfShawn Rutledge2022-05-311-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Give them unique labels. This was done with pdftk: $ pdftk resources/test.pdf update_info_utf8 update output test.pdf where the file "update" contains PageLabelBegin PageLabelNewIndex: 1 PageLabelStart: 1 PageLabelPrefix: Qt PageLabelNumStyle: NoNumber PageLabelBegin PageLabelNewIndex: 2 PageLabelStart: 1 PageLabelNumStyle: DecimalArabicNumerals PageLabelBegin PageLabelNewIndex: 3 PageLabelStart: 1 PageLabelNumStyle: LowercaseRomanNumerals The instructions to do this came from https://emacs.stackexchange.com/questions/58315/edit-pdf-page-labels-in-pdf-tools Task-number: QTBUG-102271 Change-Id: I97df7ca538690baf3329fcbef371dcd92c4d8966 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QtQuick.Pdf: automatically close the error dialog if the error disappearsShawn Rutledge2022-03-081-1/+1
| | | | | | | | | | | When the user has not yet entered a password, document.status == Error; but we pop up the password prompt dialog on top of the error dialog. After the user has entered it, either it's correct and the error goes away, or we need to tell the user that it's incorrect, so the dialog should stay open. Change-Id: Ib3332f543b23fdf50ccd0df0c7e79cdc95f2e8da Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* PDF viewer and manual test: support password-protected documentsShawn Rutledge2022-03-071-2/+23
| | | | | | | | | | | | | | | The multipage example was OK already; this adds the same password-prompt dialog to the single-page-at-a-time pdfviewer example and to the withdoc.qml manual test. Also, the dialogs seem to size themselves better if we explicitly set the contentItem properties. And an error dialog should not have an OK button but a Close button: the error is not OK, but the example does not provide a way to try to fix it either. Fixes: QTBUG-83988 Fixes: QTBUG-96574 Change-Id: I9d8c3cbe1f955cea4319982869ec9180d7c8666c Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Improve examples CMakeLists.txtKai Köhne2022-02-251-7/+4
| | | | | | | | | | | | | | | | | - Remove "# generated from xyz.pro" comment from pro2cmake - Remove automatic use of CMAKE_AUTORCC - Only opt into CMAKE_AUTOUIC if .ui files are involved - Remove explicit setting of CMAKE_INCLUDE_CURRENT_DIR - Combine multiple find_package(Qt6 ... calls) - use REQUIRED COMPONENTS - sort components alphabetically - Fix wrong indentations - Use (only) one empty line after multi-line commands Pick-to: 6.3 Change-Id: I09083474432ce171e8ee1e28120b062f2ef3c052 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtPdf: fix qml issuesShawn Rutledge2022-02-221-5/+1
| | | | | | | | | | | | | - required properties - unused imports - nullish coalescing - issues found by qmllint (despite all the noise) Reverts 99db09404787901647213abceda74befc7efa8f1 Task-number: QTBUG-82873 Change-Id: I0042d2eaeacba58adcf280c37b9668f8d76d0f93 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* PDF viewer examples: use QtQuick.Dialogs FileDialogShawn Rutledge2022-01-111-3/+3
| | | | | | | | | Qt.labs.platform is becoming obsolete, and creates a widgets dependency. QtQuick.Dialogs uses platform dialogs when available. Pick-to: 6.2 6.3 Change-Id: I9b608e28cc7b9a99d0aaeec2aa24fee9d569dfe8 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
* Minor. Cleanup qt6_add_resources usageMichal Klocek2021-10-281-1/+1
| | | | | | | | We should not use qt6 prefixed functions in examples. Pick-to: 6.2 Change-Id: Ibf2618ef4f64b560decb219527d619aad680f216 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Add QtPdf to cmake buildMichal Klocek2021-08-172-24/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Port QtPdf to Qt6: * QtPdf,QtPdfWidgets,QtPdfQuick libs * QtPdfQuickPlugin, QtPdfPlugin (imageformat) plugins * widget and quick examples * qtpdf tests To fit gn cmake integration and new repo layout code is a bit reshuffled. Compared to qmke build following features are not ported yet: * ios fat libs * qtbase 3rdparty static dependencies WebEngine build can be skipped with setting QT_FEATURE_qtwebengine_build=OFF Note this patch needs follow up for 6.2 branch to disable qtpdf builds by default, since this should not part of qt 6.2 release. Pick-to: 6.2 Task-number: QTBUG-95353 Change-Id: I4dd9f3934bdd478fb6d2fa686074a24d91f09953 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix some compiler warningsPeter Varga2021-06-101-1/+0
| | | | | | | | | | | | | - Remove deprecated Qt::AA_EnableHighDpiScaling and Qt::AA_UseHighDpiPixmaps from examples. High-DPI scaling is always enabled. - Reorder initialization of members of QWebEngineDownloadRequestPrivate. Also remove m_ prefix from public members' name. - Remove unused parameters from methods of DummyDelegate. - Add missing overrides in auto tests. Pick-to: 6.2 Change-Id: I18d6973b8bee574b37b73fbaaa8d57002ac8ba2d Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Compile pdf examplesMichal Klocek2020-10-062-3/+3
| | | | | | | | Fix typo in examples.pro and update related pro files. Drop dependency on widgets in qml examples. Change-Id: I571069e5b42cc0d0d94d54ce157a6e8636275cae Reviewed-by: Michael Brüning <michael.bruning@qt.io>
* Support text selection handles in PDF viewsShawn Rutledge2020-04-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Testing only on iOS so far; QtPdf doesn't work on Android because of QTBUG-83459, so we can only hope that this might perhaps be cross-platform, if only text selection handles actually existed on all platforms. As usual, text selection begins with a long-press; the iOS platform plugin intercepts that, and we get QInputMethodEvent::Cursor. There is no cursor, but we use the opportunity to do hit-testing, because the Cursor event is the only way that we receive the pixel location where the user is interacting. Then a popover menu appears, which contains Select and Select All, and either Copy or Paste depending on the qt_im_readonly property workaround. You don't get handles until you choose Select, which will select a word. That makes the popover menu disappear. You can use the toolbar button to copy to the clipboard. After that, you can drag either handle. inputMethodQuery(query, argument) is only ever called with ImCursorPosition regardless which handle is being dragged, so it doesn't make sense to change the selection there, even though that would be easy if we were given that information. Instead, the iOS platform figures out the character range for itself and sends a QInputMethodEvent::Selection event to tell us which text to select. And yet it still doesn't move the handles without being told: QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle) makes that happen. Then the popover menu will appear again, and now you can use the Copy function on it as an alternative way to copy text to the clipboard. By default, when the user does the initial long-press to start selecting text, the popover menu has Select, Select All, and Paste. In editable controls there is a second possible menu that normally has Cut, Copy, Paste and Delete. We are not able to enter that mode. So as a workaround, to substitute Copy instead of Paste, we set the qt_im_readonly property so that QIOSTextResponder::canPerformAction() can detect it and make the substition. Of course that won't work without the patch to 5.15; so you still get a useless Paste action on earlier Qt versions. Selecting a word via the Select popover menu item happens because iOS sends QKeySequence::MoveToPreviousWord and then QKeySequence::SelectNextWord. We spend time calling getSelectionAtIndex() twice because of that. With an actual keyboard, it should be possible to use keystrokes to extend the selection, but it doesn't seem to work yet with shift-arrows on a physical bluetooth keyboard on iOS. Select All on the popover menu works via inputMethodEvent() with attr QInputMethodEvent::Selection. Copy sends the standard copy key sequence, so keyReleaseEvent() handles it. We must rename the geometryChanged signal to selectedAreaChanged now that we're inheriting from QQuickItem, to avoid shadowing QQuickItem::geometryChanged. For this kind of text selection to work even when the rendering is scaled, it became necessary to inform PdfSelection of the rendering scale; so a renderScale property is added. Thus it is sensible (and a nice simplification in QML code) to use it for the fromPoint and toPoint properties, such that those are now expressed in pixels rather than points. Fixes: QTBUG-82441 Task-number: QTBUG-83811 Change-Id: I16ecd2db55c6a834be6139ce4f3aae23446fed54 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Workaround for failing import QtQml in PDF views on iOSShawn Rutledge2020-03-161-0/+1
| | | | | | | | | The QtQml import isn't working in any QML dependencies unless it's detected because of having been included in the main QML file. Task-number: QTBUG-82873 Change-Id: I2ed2ca439651c40089d667255effb1155af58a01 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* PdfSelection: add selectAll() function; use in examplesShawn Rutledge2020-03-113-0/+21
| | | | | | | | The usual shortcut (control-A) now selects all text on the current page, it is highlighted, and it can be copied to the clipboard. Change-Id: I5e6d9cae675862808f8b9027cb47024ca65cf2fd Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PDF single-page example: shift content right as the search drawer opensShawn Rutledge2020-02-261-0/+1
| | | | | | | | This was done in 0b6a4d94945a975390b2574e6aff2568ebb7f061 for the multipage example. Change-Id: Ia5b51b9239521ab4d65e41aaebe52d178e75932d Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PdfSearchModel: provide ContextBefore and ContextAfterShawn Rutledge2020-02-261-1/+25
| | | | | | | | | | | | | | ...as separate roles, to make alignment easier, and to avoid hard-coding HTML tags in the Context role as it was before. But the strings in these context roles are not always adjacent to the search results in geometric coordinates sometimes, in some PDF files, despite having adjacent character indices. I.e. the "next" character after the search string, or the "previous" character before it, could be anywhere on the page. Change-Id: Ief0a490b64fdb3c3ca98506926650648b609ece1 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PDF single-page example: move search field to the footerShawn Rutledge2020-02-201-71/+71
| | | | | | | | As with a2be3a7a79dc4fabe8675ea80a6ba550e0e4deec, this makes the search feature more discoverable and touch-friendly. Change-Id: I47e37273c583121d60985cc27c22f56e6d655ab0 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add PdfScrollablePageView, use it in the pdfviewer exampleShawn Rutledge2020-02-201-45/+30
| | | | | | | | | PdfPageView might be useful in some cases, but we need to get feature parity with PdfMultiPageView as much as possible, including scrollbars. Including them in the view is convenient, but also less flexible. Change-Id: Ibbe6a090a5f5b1d340124986fe49672d682ddedb Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QtPdf examples: use test.pdf from resources if no file givenShawn Rutledge2020-02-195-3/+7
| | | | | | | | | | | | | | | | | | 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>
* Enable mouse wheel scrolling in single-page PdfPageViewShawn Rutledge2020-02-171-0/+16
| | | | | Change-Id: I20512187dcc872b2e0429968e9ad2a9899aee6c2 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Rearrange PdfPageView.qmlShawn Rutledge2020-02-171-6/+5
| | | | | | | | | | | | Now it looks more similar to PdfMultiPageView.qml: public properties and functions are grouped by functionality, implementation details are "below the fold", and properties and functions that we don't want to expose as API are nested inside inner items. Also fixed ColumnLayout attached properties. Change-Id: Iafe6f983a34ca6bac9b0d4f3a26aba5a426e0232 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PdfSearchModel: be QALM and find search results on all pagesShawn Rutledge2020-02-174-31/+111
| | | | | | | | | | | | | | It's a QAbstractListModel, so now PdfMultiPageView has a ListView in a left-side Drawer showing all results found so far. - In PdfMultiPageView, multiple pages exist at once, so it makes sense to use the same searchmodel for all. - It's faster and saves memory. - Search results on each page can be cached. - It's possible to show search results in a ListView or QListView. Change-Id: I66fba6975954a09a4d23262be87ff8cc25ee7478 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add QPdfDestination; NavigationStack stores page, location and zoomShawn Rutledge2020-02-111-2/+1
| | | | | | | | | | | | Push/back/forward behavior seems more correct now, but still no autotest yet. QPdfDestination might be useful to represent locations of search results, for link destinations and maybe named destinations too. Fixes: QTBUG-77512 Change-Id: I113b2c535a2cd302106e6546104c64e12985d387 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add multipage example to pdf.pro; work with 5.14; fix main.cppShawn Rutledge2020-02-042-6/+6
| | | | | | | | | | - build the multipage example by default - don't import anything that won't work with Qt 5.14 - set application attributes before creating an instance (to fix the warning about that) Change-Id: I265f49ca75cae1908d4c23848cba8c42e5e3824b Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add PdfNavigationStack for forward/back navigationShawn Rutledge2020-02-031-4/+27
| | | | | | | Works well enough to use, but needs autotests and at least one fix. Change-Id: I2114b9fb3b5ddf7cfe2106d4a4fbc7d74852c61d Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PdfPageView: Add zoom-to-fit and zoom-to-width featuresShawn Rutledge2020-02-034-1/+41
| | | | | Change-Id: I40b92000a4def105d22a3bd10d0544b0b0f0fe1e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add QPdfSelection and QQuickPdfSelectionShawn Rutledge2020-01-303-0/+24
| | | | | | | | So now you can select text by mouse-drag and copy it to the clipboard. Task-number: QTBUG-77509 Change-Id: I689ee4158974de8bc541c319a5a5cc2f8f3c2ae6 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
* Use SpinBox for page navigation to get jump-to-page featureShawn Rutledge2020-01-301-13/+13
| | | | | Change-Id: Ic4c7d1a7458995415452e899b3dc369c9fe574f4 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add rotation actions to the QML pdf viewer exampleShawn Rutledge2020-01-234-0/+28
| | | | | | Task-number: QTBUG-77514 Change-Id: Ifa7515dae18b278e038c2e5fad46492ca158b044 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
* Add QPdfSearchModel, QML PdfSearchModel and PdfPageViewShawn Rutledge2020-01-2311-0/+377
This enables searching a PDF for a text string and getting the boundaries of the areas where it is found. The boundaries are returned as polygons intended to be rendered with PathMultiline. PdfPageView is a QML component intended to be a drop-in viewer for use in applications that need the most common PDF viewing functionality. More advanced applications are free to use it as a starting point for customization. Task-number: QTBUG-77507 Task-number: QTBUG-77514 Change-Id: Id08ac30224e41b6cdfb9300cc4288d5750259f78 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>