diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-18 21:42:35 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-02-20 09:48:59 +0100 |
commit | f467edc97e66727be7fa3747913e4e01672d4b71 (patch) | |
tree | d55afd400b398585006bbdf092230b053a3358da /src/pdf/quick/qquickpdfdocument.cpp | |
parent | 1acd9ad2bfa1c54f19fa8a71fb41e8a90233f76b (diff) |
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 <shawn.rutledge@qt.io>
Diffstat (limited to 'src/pdf/quick/qquickpdfdocument.cpp')
-rw-r--r-- | src/pdf/quick/qquickpdfdocument.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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<QQuickPdfDocument *>(this)->updateMaxPageSize(); + return m_maxPageWidthHeight.width(); +} + +qreal QQuickPdfDocument::maxPageHeight() const +{ + const_cast<QQuickPdfDocument *>(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 |