Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpdfpagenavigator.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpdfpagenavigator.h"
5#include "qpdfdocument.h"
6#include "qpdflink_p.h"
7
8#include <QtCore/qloggingcategory.h>
9#include <QtCore/qpointer.h>
10
12
13Q_LOGGING_CATEGORY(qLcNav, "qt.pdf.pagenavigator")
14
16{
17 QPdfPageNavigator *q = nullptr;
18
19 QList<QExplicitlySharedDataPointer<QPdfLinkPrivate>> pageHistory;
20 int currentHistoryIndex = 0;
21 bool changing = false;
22};
23
42 : QObject(parent), d(new QPdfPageNavigatorPrivate)
43{
44 d->q = this;
45 clear();
46}
47
54
64{
65 if (d->currentHistoryIndex >= d->pageHistory.size() - 1)
66 return;
67 const bool backAvailableWas = backAvailable();
68 const bool forwardAvailableWas = forwardAvailable();
69 QPointF currentLocationWas = currentLocation();
70 qreal currentZoomWas = currentZoom();
72 d->changing = true;
74 if (currentZoomWas != currentZoom())
77 if (currentLocationWas != currentLocation())
79 if (!backAvailableWas)
81 if (forwardAvailableWas != forwardAvailable())
83 d->changing = false;
84 qCDebug(qLcNav) << "forward: index" << d->currentHistoryIndex << "page" << currentPage()
85 << "@" << currentLocation() << "zoom" << currentZoom();
86}
87
94{
95 if (d->currentHistoryIndex <= 0)
96 return;
97 const bool backAvailableWas = backAvailable();
98 const bool forwardAvailableWas = forwardAvailable();
99 QPointF currentLocationWas = currentLocation();
100 qreal currentZoomWas = currentZoom();
102 d->changing = true;
104 if (currentZoomWas != currentZoom())
107 if (currentLocationWas != currentLocation())
109 if (backAvailableWas != backAvailable())
111 if (!forwardAvailableWas)
113 d->changing = false;
114 qCDebug(qLcNav) << "back: index" << d->currentHistoryIndex << "page" << currentPage()
115 << "@" << currentLocation() << "zoom" << currentZoom();
116}
124{
126 return -1; // only until ctor or clear() runs
127 return d->pageHistory.at(d->currentHistoryIndex)->page;
128}
129
143
151{
153 return 1;
154 return d->pageHistory.at(d->currentHistoryIndex)->zoom;
155}
156
163
169{
170 d->pageHistory.clear();
171 d->currentHistoryIndex = 0;
172 // Begin with an implicit jump to page 0, so that
173 // backAvailable() will become true after jump() is called one more time.
174 d->pageHistory.append(QExplicitlySharedDataPointer<QPdfLinkPrivate>(new QPdfLinkPrivate(0, {}, 1)));
175}
176
190{
191 const bool zoomChange = !qFuzzyCompare(destination.zoom(), currentZoom());
192 const bool pageChange = (destination.page() != currentPage());
193 const bool locationChange = (destination.location() != currentLocation());
194 const bool backAvailableWas = backAvailable();
195 const bool forwardAvailableWas = forwardAvailable();
196 if (!d->changing) {
197 if (d->currentHistoryIndex >= 0 && forwardAvailableWas)
201 }
202 if (zoomChange)
204 if (pageChange)
206 if (locationChange)
208 if (d->changing)
209 return;
210 if (backAvailableWas != backAvailable())
212 if (forwardAvailableWas != forwardAvailable())
215 qCDebug(qLcNav) << "push: index" << d->currentHistoryIndex << destination << "-> history" <<
216 [this]() {
218 for (auto d : d->pageHistory)
219 ret << QString::number(d->page);
220 return ret.join(QLatin1Char(','));
221 }();
222}
223
242{
243 if (page == currentPage() && location == currentLocation() && zoom == currentZoom())
244 return;
245 if (qFuzzyIsNull(zoom))
246 zoom = currentZoom();
247 const bool zoomChange = !qFuzzyCompare(zoom, currentZoom());
248 const bool pageChange = (page != currentPage());
249 const bool locationChange = (location != currentLocation());
250 const bool backAvailableWas = backAvailable();
251 const bool forwardAvailableWas = forwardAvailable();
252 if (!d->changing) {
253 if (d->currentHistoryIndex >= 0 && forwardAvailableWas)
255 d->pageHistory.append(QExplicitlySharedDataPointer<QPdfLinkPrivate>(new QPdfLinkPrivate(page, location, zoom)));
257 }
258 if (zoomChange)
260 if (pageChange)
262 if (locationChange)
264 if (d->changing)
265 return;
266 if (backAvailableWas != backAvailable())
268 if (forwardAvailableWas != forwardAvailable())
271 qCDebug(qLcNav) << "push: index" << d->currentHistoryIndex << "page" << page
272 << "@" << location << "zoom" << zoom << "-> history" <<
273 [this]() {
275 for (auto d : d->pageHistory)
276 ret << QString::number(d->page);
277 return ret.join(QLatin1Char(','));
278 }();
279}
280
295{
297 return;
298 int currentPageWas = currentPage();
299 QPointF currentLocationWas = currentLocation();
300 qreal currentZoomWas = currentZoom();
301 if (page == currentPageWas && location == currentLocationWas && zoom == currentZoomWas)
302 return;
303 d->pageHistory[d->currentHistoryIndex]->page = page;
304 d->pageHistory[d->currentHistoryIndex]->location = location;
305 d->pageHistory[d->currentHistoryIndex]->zoom = zoom;
306 if (currentZoomWas != zoom)
308 if (currentPageWas != page)
310 if (currentLocationWas != location)
312 qCDebug(qLcNav) << "update: index" << d->currentHistoryIndex << "page" << page
313 << "@" << location << "zoom" << zoom << "-> history" <<
314 [this]() {
316 for (auto d : d->pageHistory)
317 ret << QString::number(d->page);
318 return ret.join(QLatin1Char(','));
319 }();
320}
321
330{
331 return d->currentHistoryIndex > 0;
332}
333
342{
343 return d->currentHistoryIndex < d->pageHistory.size() - 1;
344}
345
361
362#include "moc_qpdfpagenavigator.cpp"
T * data() const noexcept
Returns a pointer to the shared data object.
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void remove(qsizetype i, qsizetype n=1)
Definition qlist.h:794
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
\inmodule QtCore
Definition qobject.h:103
QPointF location
Definition qpdflink_p.h:43
Navigation history within a PDF document.
void back()
Pops the stack, updates the \l currentPage, \l currentLocation and \l currentZoom properties to the m...
void forward()
Goes back to the page, location and zoom level that was being viewed before back() was called,...
QPointF currentLocation
This property holds the current location on the page that is being viewed (the location that was last...
void currentPageChanged(int page)
int currentPage
This property holds the current page that is being viewed.
~QPdfPageNavigator() override
Destroys the page navigation stack.
void backAvailableChanged(bool available)
void jump(QPdfLink destination)
Adds the given destination to the history of visited locations.
void currentLocationChanged(QPointF location)
bool backAvailable
\readonly
QPdfLink currentLink() const
void update(int page, const QPointF &location, qreal zoom)
Modifies the current destination, consisting of page, location and zoom.
qreal currentZoom
This property holds the magnification scale (1 logical pixel = 1 point) on the page that is being vie...
void clear()
Clear the history and restore \l currentPage, \l currentLocation and \l currentZoom to their default ...
void currentZoomChanged(qreal zoom)
bool forwardAvailable
\readonly
void forwardAvailableChanged(bool available)
void jumped(QPdfLink current)
This signal is emitted when an abrupt jump occurs, to the current page index, location on the page,...
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
return ret
GLint location
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
double qreal
Definition qtypes.h:187
QByteArray page
[45]
\inmodule QtCore \reentrant
Definition qchar.h:18
QList< QExplicitlySharedDataPointer< QPdfLinkPrivate > > pageHistory