From 6104c716c7677cf705787a0be4ffb0adc2b8b5b8 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 29 Jan 2020 22:17:37 +0100 Subject: doc: rename QML type Document -> PdfDocument I would prefer to use the "import as" mechanism to allow the user to customize prefixes rather than hard-coding them, actually; but currently every QML type in the QtPDF module has a hard-coded Pdf prefix. Change-Id: I4c00e7891c58e028280599d6089a821b9e285c1a Reviewed-by: Leena Miettinen --- src/pdf/quick/qquickpdfdocument.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/pdf/quick/qquickpdfdocument.cpp') diff --git a/src/pdf/quick/qquickpdfdocument.cpp b/src/pdf/quick/qquickpdfdocument.cpp index 73b3d4537..6eb9d3ae4 100644 --- a/src/pdf/quick/qquickpdfdocument.cpp +++ b/src/pdf/quick/qquickpdfdocument.cpp @@ -43,14 +43,14 @@ QT_BEGIN_NAMESPACE /*! - \qmltype Document + \qmltype PdfDocument \instantiates QQuickPdfDocument \inqmlmodule QtQuick.Pdf \ingroup pdf \brief A representation of a PDF document. \since 5.15 - A Document provides access to PDF document meta-information. + PdfDocument provides access to PDF document meta-information. It is not necessary for rendering, as it is enough to use an \l Image with source set to the URL of the PDF. */ @@ -78,7 +78,7 @@ void QQuickPdfDocument::componentComplete() } /*! - \qmlproperty url Document::source + \qmlproperty url PdfDocument::source This property holds a URL pointing to the PDF file to be loaded. @@ -95,7 +95,7 @@ void QQuickPdfDocument::setSource(QUrl source) } /*! - \qmlproperty string Document::error + \qmlproperty string PdfDocument::error This property holds a translated string representation of the current error, if any. @@ -130,7 +130,7 @@ QString QQuickPdfDocument::error() const } /*! - \qmlproperty bool Document::password + \qmlproperty bool PdfDocument::password This property holds the document password. If the passwordRequired() signal is emitted, the UI should prompt the user and then set this @@ -146,13 +146,13 @@ void QQuickPdfDocument::setPassword(const QString &password) } /*! - \qmlproperty int Document::pageCount + \qmlproperty int PdfDocument::pageCount This property holds the number of pages the PDF contains. */ /*! - \qmlsignal Document::passwordRequired() + \qmlsignal PdfDocument::passwordRequired() This signal is emitted when the PDF requires a password in order to open. The UI in a typical PDF viewer should prompt the user for the password @@ -160,7 +160,7 @@ void QQuickPdfDocument::setPassword(const QString &password) */ /*! - \qmlmethod size Document::pagePointSize(int page) + \qmlmethod size PdfDocument::pagePointSize(int page) Returns the size of the given \a page in points. */ @@ -170,59 +170,59 @@ QSizeF QQuickPdfDocument::pagePointSize(int page) const } /*! - \qmlproperty string Document::title + \qmlproperty string PdfDocument::title This property holds the document's title. A typical viewer UI can bind this to the \c Window.title property. */ /*! - \qmlproperty string Document::author + \qmlproperty string PdfDocument::author This property holds the name of the person who created the document. */ /*! - \qmlproperty string Document::subject + \qmlproperty string PdfDocument::subject This property holds the subject of the document. */ /*! - \qmlproperty string Document::keywords + \qmlproperty string PdfDocument::keywords This property holds the keywords associated with the document. */ /*! - \qmlproperty string Document::creator + \qmlproperty string PdfDocument::creator If the document was converted to PDF from another format, this property holds the name of the software that created the original document. */ /*! - \qmlproperty string Document::producer + \qmlproperty string PdfDocument::producer If the document was converted to PDF from another format, this property holds the name of the software that converted it to PDF. */ /*! - \qmlproperty string Document::creationDate + \qmlproperty string PdfDocument::creationDate This property holds the date and time the document was created. */ /*! - \qmlproperty string Document::modificationDate + \qmlproperty string PdfDocument::modificationDate This property holds the date and time the document was most recently modified. */ /*! - \qmlproperty enum Document::status + \qmlproperty enum PdfDocument::status This property tells the current status of the document. The possible values are: -- cgit v1.2.3 From 1acd9ad2bfa1c54f19fa8a71fb41e8a90233f76b Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 19 Feb 2020 17:47:01 +0100 Subject: 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 --- src/pdf/quick/qquickpdfdocument.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pdf/quick/qquickpdfdocument.cpp') diff --git a/src/pdf/quick/qquickpdfdocument.cpp b/src/pdf/quick/qquickpdfdocument.cpp index 6eb9d3ae4..1cfd9a9af 100644 --- a/src/pdf/quick/qquickpdfdocument.cpp +++ b/src/pdf/quick/qquickpdfdocument.cpp @@ -91,7 +91,10 @@ void QQuickPdfDocument::setSource(QUrl source) m_source = source; emit sourceChanged(); - m_doc.load(source.path()); + if (source.scheme() == QLatin1String("qrc")) + m_doc.load(QLatin1Char(':') + source.path()); + else + m_doc.load(source.path()); } /*! -- cgit v1.2.3 From f467edc97e66727be7fa3747913e4e01672d4b71 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 18 Feb 2020 21:42:35 +0100 Subject: PdfMultiPageView: use TableView; horz. scroll; control page position TableView is missing some features compared to ListView; so finding out where we currently are (which row) and programmatic positioning on a specific y coordinate of a specific row require some workarounds for now, including helpers in PdfDocument. TableView also assumes (and sporadically enforces) that all cells in a column have the same width. So we need a placeholder Item for each page. This also helps with rotation: the placeholder is now as wide as the window or the image, whichever is wider, and the "paper" is centered within; thus there's always room to rotate it. There's still some problem with setting contentY in goToPage() after the page has been zoomed to a size larger than the window: the values look correct, but it scrolls too far. But on the plus side, horizontal scrolling works. So now we attempt to control the horizontal position too: NavigationStack tracks it, and can go back to a previous position; and links can in theory jump to specific positions and zoom levels, scrolling horizontally such that a specific x coordinate is visible. Includes minor UI tweaks to make it look better on iOS. Change-Id: I643d8ef48ef815aeb49cae77dcb84c3682563d56 Reviewed-by: Shawn Rutledge --- src/pdf/quick/qquickpdfdocument.cpp | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/pdf/quick/qquickpdfdocument.cpp') diff --git a/src/pdf/quick/qquickpdfdocument.cpp b/src/pdf/quick/qquickpdfdocument.cpp index 1cfd9a9af..3d5f0fa10 100644 --- a/src/pdf/quick/qquickpdfdocument.cpp +++ b/src/pdf/quick/qquickpdfdocument.cpp @@ -90,6 +90,7 @@ void QQuickPdfDocument::setSource(QUrl source) return; m_source = source; + m_maxPageWidthHeight = QSizeF(); emit sourceChanged(); if (source.scheme() == QLatin1String("qrc")) m_doc.load(QLatin1Char(':') + source.path()); @@ -172,6 +173,71 @@ QSizeF QQuickPdfDocument::pagePointSize(int page) const return m_doc.pageSize(page); } +qreal QQuickPdfDocument::maxPageWidth() const +{ + const_cast(this)->updateMaxPageSize(); + return m_maxPageWidthHeight.width(); +} + +qreal QQuickPdfDocument::maxPageHeight() const +{ + const_cast(this)->updateMaxPageSize(); + return m_maxPageWidthHeight.height(); +} + +/*! + \internal + \qmlmethod size PdfDocument::heightSumBeforePage(int page) + + Returns the sum of the heights, in points, of all sets of \a facingPages + pages from 0 to the given \a page, exclusive. + + That is, if the pages were laid out end-to-end in adjacent sets of + \a facingPages, what would be the distance in points from the top of the + first page to the top of the given page. +*/ +// Workaround for lack of something analogous to ListView.positionViewAtIndex() in TableView +qreal QQuickPdfDocument::heightSumBeforePage(int page, qreal spacing, int facingPages) const +{ + qreal ret = 0; + for (int i = 0; i < page; i+= facingPages) { + if (i + facingPages > page) + break; + qreal facingPagesHeight = 0; + for (int j = i; j < i + facingPages; ++j) + facingPagesHeight = qMax(facingPagesHeight, pagePointSize(j).height()); + ret += facingPagesHeight + spacing; + } + return ret; +} + +void QQuickPdfDocument::updateMaxPageSize() +{ + if (m_maxPageWidthHeight.isValid()) + return; + qreal w = 0; + qreal h = 0; + const int count = pageCount(); + for (int i = 0; i < count; ++i) { + auto size = pagePointSize(i); + w = qMax(w, size.width()); + h = qMax(w, size.height()); + } + m_maxPageWidthHeight = QSizeF(w, h); +} + +/*! + \qmlproperty real PdfDocument::maxPageWidth + + This property holds the width of the widest page in the document, in points. +*/ + +/*! + \qmlproperty real PdfDocument::maxPageHeight + + This property holds the height of the tallest page in the document, in points. +*/ + /*! \qmlproperty string PdfDocument::title -- cgit v1.2.3