summaryrefslogtreecommitdiff
path: root/src/pdfquick
Commit message (Collapse)AuthorAgeFilesLines
* QtPdf: Support more schemas when loading documents with qmlMichal Klocek2023-03-201-4/+2
| | | | | | | | | | This is follow up after efbb12954cf6e58, use same handling as for reloading on password change. Pick-to: 6.5 Fixes: QTBUG-87275 Change-Id: I1046f57f61346a2cbc03f50ca453209a855ea561 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Fix not working password test for QPdfQuickMichal Klocek2023-03-021-3/+4
| | | | | | | | | | | | | In qml url can have different schemas like 'qrc' 'file' 'assets'. Make correct conversion so file can be loaded. Note check isLocalFile() is not true for qrc scheme. Fixes: QTBUG-106072 Pick-to: 6.5.0 6.5 6.4 Change-Id: I4dcc969e4c6d9b3f58ea5d81d20d8e81b55edfde Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Port from container::count() and length() to size() - V4Marc Mutz2022-10-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); a.k.a qt-port-to-std-compatible-api V4 with config Scope: 'Container'. Change-Id: I3e6fef8eca212da0c4f0b464545ba96183b4476f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Remove qLcNav logging category from qquickpdfpagenavigator.cppShawn Rutledge2022-09-091-2/+0
| | | | | | | | | | It's not used in QQuickPdfPageNavigator, and causes a linker warning about a duplicate symbol, especially in static builds. Pick-to: 6.4 Fixes: QTBUG-106361 Change-Id: I128c10a1aead1aa9a761dc091c626488fc195d12 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PdfSelection: mark read-only for IM to avoid showing virtual keyboardShawn Rutledge2022-09-091-2/+1
| | | | | | | | | | | | | | | | | | | | | The Qt::ImReadOnly query enum is new in 6.2 (qtbase c80f262258b7846bf199887bcfdbb6dcfda6ad6f and aae4d52cbb79c61161271473ab5c3a1ba1086e01). It was added to the switch statement in 79d04aa9e3e9aa84d7378260519f9e9a6759dc41 but needs to return `true` to mark this Item as read-only, so that the keyboard will not open when it gets focus. The menu still gets populated with Select and Select All on long-press, and then Copy after a selection is made. That's all we need. The qt_im_readonly property was a sort of private API for Qt 5, and should no longer be needed (albeit the implementation is still in Qt 6 so far). Pick-to: 6.4 Task-number: QTBUG-83811 Fixes: QTBUG-106358 Change-Id: I677363be545d07884dffdfc10d6fdbd488cf2cf0 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* PdfSelection: check m_document before accessingShawn Rutledge2022-09-071-0/+12
| | | | | | | | | | The document is a property that the user needs to bind. If initializing it has been neglected or delayed somehow, we shouldn't crash. Pick-to: 6.4 6.4.0 Fixes: QTBUG-106355 Change-Id: I8e99b4bb84d868b694886058d56166fb3c4eabff Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Pdf[Multi|Scrollable]PageView: enforce zoom limits, don't get stuckShawn Rutledge2022-09-062-6/+8
| | | | | | | | | | | | | | Handlers must not get disabled because the zoom range is beyond limits: rather, let PinchHandler's minimumScale and maximumScale enforce them. So far, PdfMultiPageView and PdfScrollablePageView do not have other ways of zooming (like a WheelHandler for control-mouse-wheel), so we don't need BoundaryRule. But the limits applied by PinchHandler are "hard" limits: you bump up against them instantly, with no easing curve. Pick-to: 6.4 Fixes: QTBUG-104769 Change-Id: I4eb785e572816d1b80ea9c8f4f5b9c925594afac Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@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>
* Doc: Fix linking issues on Qt PDF documentationTopi Reinio2022-07-054-27/+11
| | | | | | | | | | | | | These warnings were not captured by the documentation testing in CI. Fix or remove links to properties from inherited QML types, and remove \sa entries that are already linked to in the documentation. Fix incorrect \inqmlmodule argument for PdfPageImage. Pick-to: 6.4 Change-Id: If2c14d468a6dc3cd464ca4de1f4e39ad48d4d326 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-2223-862/+46
| | | | | | | | | | | 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>
* doc: Add docs for PdfStyleShawn Rutledge2022-06-061-0/+57
| | | | | | | Pick-to: 6.3 Task-number: QTBUG-81560 Change-Id: Ib0485618a1d5cdafcad928f0b05996f242ef9bd4 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Fix issues in PdfLinkDelegateShawn Rutledge2022-06-041-3/+8
| | | | | | | | | | - gesturePolicy must be set to take an exclusive grab, to avoid letting events propagate to another TapHandler in TableView - behavior was incorrect on the touchscreen - fixed doc warnings about the undocumented link arguments Change-Id: Ic438383b6b6d67936ce2b88b84ef131f41e0d2fb Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Add PdfLinkDelegate instead of link decoration style propertiesShawn Rutledge2022-06-048-81/+121
| | | | | | | | | | | | | | | | This simplifies PdfStyle somewhat. PdfLinkDelegate could still be replaced or augmented via file selectors, but we don't expect to need to, since link delegates are already non-visual. [ChangeLog][QtPDF] A PdfLinkDelegate will now be instantiated on top of each hyperlink in the PdfMultiPageView, PdfScrollablePageView and PdfPageView components, for event handling and to provide tapped() and contextMenuRequested() signals. It is non-visual by default, but can be customized, for example to draw underlines under hyperlinks if the PDF documents are not expected to have them already. Change-Id: Ib3726e7220a0c3858db564ca8d53a04625a11950 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Rename QPdfLinkModel::Role::Rect to RectangleShawn Rutledge2022-06-044-19/+22
| | | | | | | Roles are not abbreviated in general; this doesn't need to be either. Change-Id: I55a6fcbc4818d7363f1184b660948da4943c110b Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Add link role to QPdfLinkModel, providing a QPdfLink instanceShawn Rutledge2022-06-041-8/+0
| | | | | | | | | | | | | | | | | | | | | | We want to call PdfPageNavigator.jump(link) when a link is clicked; therefore PdfLinkModel needs to provide this object; therefore it makes sense to store the links as QPdfLink instances, and get rid of the redundant internal Link object type. But QPdfLink did not have storage for a QUrl until now. The textStart and textCharCount fields sounded useful, but in practice were set and not used. QPdfLink gains toString() and copyToClipboard() methods. Also removed some unused cruft in qquickpdflinkmodel. [ChangeLog][QtPDF] PdfLinkModel now provides a QPdfLink object for each link. QPdfLink now contains everything necessary to render delegates for links and search results, and handle clicking links; and there is a copyToClipboard() method for use in context menus, which will copy the text returned trom toString(), which is also invokable. Change-Id: Ifa5abe6df8f8d6f9ef98971044c26691ec4b9a36 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Redefine PdfSearchModel.currentResult as document-based; use PdfLinkShawn Rutledge2022-06-044-62/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Use QPdfLink in PageNavigator jump() / jumped(); QML viewsShawn Rutledge2022-06-043-20/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One reason for this is to use the new tableView.positionViewAtCell(.., TableView.Contain, offset, rect) to do less scrolling when iterating search results. Now in that case, the QPdfLink object contains correct rectangles, so that we can scale the first one and pass it directly to positionViewAtCell(). When clicking a hyperlink, the destination is a point rather than a rectangle; but positionViewAtCell with a subRect works better than calling it with just an offset, so we construct a small rectangle for that purpose. It's important that the QPdfLink object emitted in the jumped() signal must not contain any rectangles in this case, so that we can distinguish a hyperlink destination from a search-result destination. The QPdfLink object from PdfLinkModel has its own rectangle, but that's the place where the user clicks. When clicked, the view calls pageNavigator.jump(page, location, zoom), rather than the jump(QPdfLink) overload, so that rectangle is not passed along. In an onJumped() handler, we expect the rectangles to be the destination, if present; otherwise we fall back to using the location property, which is always the destination, never the source. In both cases, we need to grow the destination rectangle by jumpLocationMargin, because the offset argument to positionViewAtCell() is an offset, not a margin. But since the rectangle needs to be scaled from points to pixels anyway (according to the current renderScale), it's not much more trouble to add the margin. It looks better to avoid having a search result and its highlight rectangle banging up against the corner of the viewport: the margin lets the user see a bit of context on the page, and the highlight looks more distinct by being spaced out away from the edge. And since the margin gets added to the rectangle's edges, it makes more sense to use the (qreal) point type rather than vector2d. To make it possible to emit a QPdfLink object and access its properties in QML, it's now registered as a QML type. Fixes: QTBUG-102740 Change-Id: I74ccd11a106c5e49a0ce94eef9cf2d50992923b4 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Rename QQuickPdfSelection fromPoint/toPoint properties to from and toShawn Rutledge2022-06-045-53/+53
| | | | | | | It was a suggestion during API review. Change-Id: I54425bbebb90b05a2cee1cb00d51c4d61edb8784 Reviewed-by: Doris Verria <doris.verria@qt.io>
* Replace usage of currentPage with currentFrameShawn Rutledge2022-06-021-2/+2
| | | | | | | Amends 038b361c452feb41106867f20b2484c1f384b0d1 Change-Id: I417822f27d5a57749754bf043594aad8a220b63f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Rename QPdfDocument::pageSize() to QPdfDocument::pagePointSize()Shawn Rutledge2022-05-312-6/+1
| | | | | | | | It is in fact the size in points (1/72 of an inch), so we might as well be consistent about the naming between QML and C++ APIs. Change-Id: I8f8b05eeecc635a4d105558959834ae0e15add81 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Include moc filesAllan Sandfeld Jensen2022-05-317-0/+14
| | | | | | | | Faster to build and gives smaller binaries Fixes: QTBUG-103291 Change-Id: Iab52995e03c13a4c5b185750028c449a19d98d93 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Remove PdfPageView.currentPage propertyShawn Rutledge2022-05-314-4/+3
| | | | | | | It was just an alias for currentFrame. Change-Id: Ib16f579b1905cf5fe43496553ebde054d474a7c7 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Rename QPdfNavigationStack to QPdfPageNavigator; QML type tooShawn Rutledge2022-05-276-109/+109
| | | | | | | | | | | | | | | | | This might reduce some confusion about the fact that the back/forward "stack" isn't strictly a stack in the data structure sense: it's more like QUndoStack. It causes a QML source incompatibility relative to Qt 5, but keeps the C++ class name the same as it has been in QtPdf for a long time. Amends 3ad445f9f24a9d3f259ed1781460a63346a728e4 [ChangeLog][QtPDF] The PdfNavigationStack QML type has been renamed to PdfPageNavigator, matching the C++ type QPdfPageNavigator. These remember navigation history within a document, and are helpful to implement back/forward buttons similar to those on a web browser in both Qt Quick and widget-based viewer applications. Change-Id: Id8dc17aa416bb7064b1f0f300a47c07c83b7f47e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QPdfDocument: use enum classesShawn Rutledge2022-05-242-17/+17
| | | | | Change-Id: Iad3f8da130abe86a464d63323920a2a39d6fa955 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* doc: Add docs for PdfScrollablePageView and PdfPageViewShawn Rutledge2022-04-292-2/+438
| | | | | | | | Pick-to: 6.3 Task-number: QTBUG-81560 Change-Id: Ib91da92942311f65e3a2a40eb08c5a7f053419b4 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* PdfMultiPageView: fix PdfNavigationStack.onJumped horizontal scrollingShawn Rutledge2022-04-221-3/+1
| | | | | | | | | | | | | | | xOffsetLimit should not be divided by 2: it's meant to be the farthest that we can scroll to the right without going beyond the page edge. Since we still have the tableView.rebuild() workaround function, remove some calls to forceLayout() that seem not to help with anything, but just caused a warning: Cannot do an immediate re-layout during an ongoing layout! Pick-to: 6.3 Fixes: QTBUG-102742 Change-Id: I57f419467e01fc92c12e5d74262d8fa878ce1c79 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* PdfMultiPageView: re-layout when size changesShawn Rutledge2022-04-221-0/+2
| | | | | | Fixes: QTBUG-102746 Change-Id: I75528f86a2c8b3d61f73929ea64a1ce2f5e54167 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QtPDF: Get styles working again; remove visible hyperlink adornmentsShawn Rutledge2022-04-205-37/+30
| | | | | | | | | | | | | | | | | | | | | | | Update to versionless imports. The color type comes from the QtQuick import now. Add the styles to CMakeLists.txt so they get installed. Use SystemPalette rather than instantiating a Control. We'd probably better just assume that the PDF has hyperlinks decorated however the author wanted, rather than risking redundant underlines. Declare linkUnderscoreStrokeWidth: -1 since the ShapePath.strokeWidth docs tell us "When set to a negative value, no stroking occurs." But the user can turn them back on using a custom style. Update the screenshot: avoid showing off how bad the underscores looked. PdfPageView doesn't depend on Controls and doesn't import styles: it simply loses the light-grey rectangles around links. The cursor change still informs the user when the mouse is hovering a link. Pick-to: 6.3 Fixes: QTBUG-102303 Change-Id: Ifa4f9982bfaaf0e2e46230e8dbe30a5db7c9f592 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* doc: Add more docs to PdfPageImage and PdfSelectionShawn Rutledge2022-04-172-0/+23
| | | | | Change-Id: I939c6988436b2168b5df5a7b662eb09364832823 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add manual tests for PdfPageViewShawn Rutledge2022-04-121-24/+7
| | | | | | | | | | | | | | | | | | | | Before ff13e6532975b5372280c02061cb1b7227cf6699 the pdfviewer example used PdfPageView; but from then until now, it was not used anywhere. Now there's a manual test, slightly more refined than it was then. PdfPageView no longer takes care of its own positioning (scrolling or panning by whatever means): the user has the responsibility for that (as in the pdfPageView manual test). But it still does its own pinch zoom and text selection, so it's not completely devoid of event handlers. This also makes it suitable for the the multipleDocuments manual test, which creates a fullscreen transparent MDI window with fake windows inside, one per document opened. Worked around some issues by having PdfPageView as the top-level item in the Component. Fixes: QTBUG-102295 Change-Id: Iedb9ed7d15fa3461c07bd5d6ea54a30c20f747da Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* PdfQuick: deal with loading a different documentShawn Rutledge2022-04-124-1/+25
| | | | | | | | | When loading a new document, clear the navigation stack, reset the view to the upper-left corner, and clear the special device in PdfPageImage. Task-number: QTBUG-102294 Change-Id: I275b46f8958d4e8abe3814c1f358df5969c36d4d Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* doc: fix QtPDF doc warnings and mistakesShawn Rutledge2022-04-083-4/+5
| | | | | Change-Id: Id2ce2bd8852c4051edd29bf474bac216ba14f2b5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Move QQuickPdfNavStack core into QPdfNavigationStack; use in QPdfViewShawn Rutledge2022-04-086-192/+40
| | | | | | | | | | | | | | | QQuickPdfNavigationStack was implemented independently until now, but users will need the same functionality in widget-based PDF viewers. QPdfPageNavigation on the other hand may have eventually had the same aspiration, but was just a glorified up/down counter thus far, with questionable API; so we get rid of it, and make the API for page navigation as much the same as possible between Quick and Widgets. We rename push() to jump() along with removing the emitJumped argument. Now jump() always emits (so we have to be more careful when to call it). Change-Id: Icb07158a351e29b81e58ec037cd323bc0f54a1a1 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* doc: begin adding docs for MultiPageView component and exampleShawn Rutledge2022-04-072-8/+223
| | | | | | | Pick-to: 6.3 Task-number: QTBUG-81560 Change-Id: I062e022a97c146e9a746b6d6358868bfe0c0a7d7 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Expose PdfBookmarkModel to QML; use with TreeView in manual testShawn Rutledge2022-04-064-0/+180
| | | | | | | | | | | | | | | | | | | | | | | | | - TreeViewDelegate uses Qt::DisplayRole by default, so we need it to map to the text we want to display, in the roleNames() hash. But asking explicitly for the TitleRole is OK too (as before). - In QML, the document property must be a QQuickPdfDocument, whereas in C++ QPdfDocument is used directly; so we shadow the document property for QML. Therefore QML_EXTENDED(QPdfBookmarkModel) does not work: we need real inheritance to get real property shadowing. - Added tests/manual/quick/pdf/bookmarks.qml with a TreeView - Clicking the TreeViewDelegate expands the subtree if there is one; but it also goes to the destination in the PDF, whether there is a subtree or not. But this can be fixed in TreeViewDelegate. - Added tests/manual/quick/pdf/bookmarks-list.qml to test the case with structureMode: PdfBookmarkModel.ListMode (using ListView) test.pdf is uninteresting for this purpose: there is only one bookmark; but you can run these tests with an optional argument like this: qml bookmarks.qml -style Material -- ~/path/to/some.pdf qml bookmarks-list.qml -- ~/path/to/some.pdf Change-Id: I65d12a3d9b8ef0f0fa2bc99003430324fd759dcb Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Use QML_EXTENDED to "inherit" QPdfDocument props, enums and signalsShawn Rutledge2022-04-066-85/+77
| | | | | | | | | | | | | | | | | | | | | In QML we want to treat the status values like Error and Ready as if the enum were declared in QQuickPdfDocument, even though it's really from the non-QML type QPdfDocument. This is needed because QQuickPdfDocument doesn't inherit QPdfDocument (9968e2578f96081d2a242340620fcb2b96d9a1d3 could've done direct inheritance, but we sometimes value separation of QML API from C++ API). So we now de-duplicate other properties and signals too. It's as if from QML's perspective, PdfDocument inherits everything from QPdfDocument (including the properties pageCount, password and status), although in C++ it's not like that. Make all properties FINAL because we don't expect anybody to subclass QQuickPdfDocument. Fixes: QTBUG-100839 Change-Id: Idbb0d620443020d7168cba8f090d1f344a9b3296 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Combine QPdfDestination and QPdfSearchResult into QPdfLinkShawn Rutledge2022-03-242-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Inheritance was a decent way to model this, conceptually. A hyperlink is modeled like the HTML kind: a region covering the source material that the user will click on, and a destination where we will jump when they click it; whereas a search result has the same information plus the text before and after the search text, so that we can show some context in a ListView with search results. By going this way, we need to document which fields we use which way under which conditions. But, we have a rule that value types cannot use inheritance, just in case the user would ever try to use them polymorphically (in spite of the other rule that we never pass value types by pointer, and thus there is no actual polymorphism), or just in case the destructor of the base class would not be called when a subclass value goes out of scope. Anyway, perhaps an upside is that this resembles a link in Xanadu, or in a fully-normalized database schema: an object that fully describes both ends of a connection, and thus is able to traverse either direction, in theory. (Although we don't really use it that way. The link-following behavior in a PDF viewer tends to be one-way, as in a web browser.) When using QAbstractItemModel (as in QPdfSearchModel and QPdfLinkModel), the cells in the "database" are accessed separately via the data() function, so there is no need for a transport object to hold a whole "row". That's OK for item views; but we need this link object for the purpose of less-clumsy C++ API, as a return value from a few functions. For example when implementing a viewer in QML, we use Repeater to instantiate Items for each hyperlink (decorations and a TapHandler), and Repeater uses the QAIM interface. But when implementing a widget-based viewer, it's better to call a hit-testing function like QPdfLinkModel::linkAt(pos) to find out whether a link exists at a particular mouse location; and that function can return a QPdfLink. In this case, the link will not contain contextBefore and contextAfter, because the viewer doesn't need them, and it's difficult to find this text in the PDF model. But QPdfSearchModel::resultsOnPage() and reultAtIndex() return link objects that do contain the context strings. We don't expect users to have made much use of these classes in C++ so far, because we prioritized QML API (which this change does not affect), and did not yet document how to use QPdfSearchModel and QPdfLinkModel in widget-based viewers. Fixes: QTBUG-98886 Change-Id: Ie68f9b893a342d145abac0b143e9254827c70bd7 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* PDF C++ classes: mark destructors with override keywordShawn Rutledge2022-03-181-1/+1
| | | | | | Fixes: QTBUG-98890 Change-Id: I30ceaeb978e430cf6dbad659023d012688c77b21 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* doc: PdfDocument qmlproperty type correctionsShawn Rutledge2022-03-161-3/+3
| | | | | | Pick-to: 6.3 Change-Id: Id2c880a73f9524749fa256a15cc3e05a6b26ee39 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove PdfDocument::heightSumBeforePageShawn Rutledge2022-03-162-27/+0
| | | | | | | | | It was a workaround for missing features in Qt 5's TableView, but it's no longer needed now. Pick-to: 6.3 Change-Id: I7318c0be83a2189bd594066e36b66a5dc09a0f20 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QtPdf: hide "debug" properties; qt.pdf.(single|multi]pageview log catsShawn Rutledge2022-03-162-32/+29
| | | | | | | | | | | | | The property "debug" was not nice API, but I have not gotten in the habit of using logging categories from QML. This is much nicer. The "debug" property is still useful to turn on some visual debugging features, but it's better to hide it rather than keeping it exposed and needing to document it. Pick-to: 6.3 Change-Id: I5ec4156e6d4e7ccd0f406fe62ee810f4401561ec Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* multipage PDF viewer example: simplify, and fix more qmllint warningsShawn Rutledge2022-03-101-1/+1
| | | | | | | | | | - no need for the document.onStatusChanged handler - no need for empty-argument function() { ... } in onSignal handlers - unqualified access and so on - scale the search field margins and erase-button a bit better Change-Id: Ice8a41e4cc1fb0385046aa1867fdb4b1400234b6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQuick.Pdf: fix rendering on high-dpi screensShawn Rutledge2022-03-073-3/+4
| | | | | | | | | | Default scale is 1 point = 1 pixel, but that means logical pixels, since we have that facade everywhere else in Qt. We use image.sourceSize to make it render more pixels than it otherwise would, according to devicePixelRatio. Change-Id: I3ff05f050c9b60c14b8208d61717e796ddd56220 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Multipage PDF viewer: use TableView.columnWidthProviderShawn Rutledge2022-03-071-3/+2
| | | | | | | This doesn't actually fix anything AFAICT. Change-Id: Id5a20a409ae1f6d2e992221dd22bef2c3ddf9200 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Multipage PDF viewer: fix horizontal scrollingShawn Rutledge2022-03-071-1/+1
| | | | | | | | The ?? operator has lower precedence than *, apparently, so we need parens. Amends 170fc1c2cb43318817552f1a1bed42b5cdc6eb36 Change-Id: I0ff2c7ce408043e7a1d3f862dd3e591c9bea5336 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Add QQuickPdfPageImage and use in the PDF viewer componentsShawn Rutledge2022-03-038-11/+274
| | | | | | | | | | | | | | | | | | | | | | | Image works fine, except that if QPdfIOHandler is not given an already-allocated QPdfDocument instance, it needs to construct its own. So we now have QPdfFile: a subclass of QFile acting as a wrapper, to carry the document instance (that the user has most likely declared) down into QPdfIOHandler::load(QIODevice *). Thus, in nontrivial PDF-viewing use cases, there is now usually only one multi-purpose document instance. And this takes care of viewing password-protected PDFs in the multipage example, because we already prompt for it and set the document.password property. In trivial use cases, it's OK to continue using Image, and QPdfIOHandler will still construct its own QPdfDocument instance if the QIODevice cannot be cast to a QPdfFile. Task-number: QTBUG-77506 Task-number: QTBUG-83988 Task-number: QTBUG-96574 Change-Id: I3adfa54c30b0baa5dedebcf3bc759758f136b757 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtPdf: fix qml issuesShawn Rutledge2022-02-223-21/+36
| | | | | | | | | | | | | - 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>
* QtPDF QML: replace var with const where possibleShawn Rutledge2022-02-223-52/+50
| | | | | Change-Id: I63b0602bb3bb7161b87da2d8378b17b47dd872c5 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
* Make QtPdf a proper generated moduleShawn Rutledge2022-02-228-62/+7
| | | | | | | | | | | | | | | | | | | | - remove plugins.qmltypes, because it's generated automatically since d32563a3365fd9432993590e6ac9817fe6f6bd41 - plugin code is also generated, so we don't need plugin-related CMake commands - QtQuick is a dependency; auto means forward the import version to the dependency. - QtQuick.Controls is only needed in bundled qml files, and we expect tooling to find it from import statements. It's not declared as a cmake dependency because we don't use it from C++. - move qml files into the source directory so that the implicit import matches the module directory - move style-specific PdfStyle.qml files into directories beginning with capital letters, since we are moving them anyway, and the styles now have capitalized names Change-Id: If517ce30d0e22fb0354272cd2002841fd2783cfc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>