diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-06-03 07:56:23 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-06-04 20:55:31 +0200 |
commit | fd39e1eeedd71f8511373d399507a0ddeedf592c (patch) | |
tree | 8df349d903f4a35ee71b7e9569e9f7c41c7f28da /src/pdf/qpdflink.cpp | |
parent | 0de16e9a20366b02b544e2279461612c69cdf11b (diff) |
Add link role to QPdfLinkModel, providing a QPdfLink instance
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>
Diffstat (limited to 'src/pdf/qpdflink.cpp')
-rw-r--r-- | src/pdf/qpdflink.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pdf/qpdflink.cpp b/src/pdf/qpdflink.cpp index 091a29729..94d4e741d 100644 --- a/src/pdf/qpdflink.cpp +++ b/src/pdf/qpdflink.cpp @@ -39,6 +39,8 @@ #include "qpdflink.h" #include "qpdflink_p.h" +#include "qpdflinkmodel_p.h" +#include <QGuiApplication> QT_BEGIN_NAMESPACE @@ -126,6 +128,17 @@ qreal QPdfLink::zoom() const } /*! + \property QPdfLink::url + + This property holds the destination URL if the link is an external hyperlink; + otherwise, it's empty. +*/ +QUrl QPdfLink::url() const +{ + return d->url; +} + +/*! \property QPdfLink::contextBefore This property holds adjacent text found on the page before the search string. @@ -167,6 +180,30 @@ QList<QRectF> QPdfLink::rectangles() const return d->rects; } +/*! + Returns a translated representation for display. + + \sa copyToClipboard() +*/ +QString QPdfLink::toString() const +{ + static const QString format = QPdfLinkModel::tr("page %1 location %2,%3 zoom %4"); + return d->page > 0 ? format.arg(QString::number(d->page), + QString::number(d->location.x()), + QString::number(d->location.y()), + QString::number(d->zoom)) + : d->url.toString(); +} + +/*! + Copies the toString() representation of the link to the + \l {QGuiApplication::clipboard()}{system clipboard} depending on the \a mode given. +*/ +void QPdfLink::copyToClipboard(QClipboard::Mode mode) const +{ + QGuiApplication::clipboard()->setText(toString(), mode); +} + QDebug operator<<(QDebug dbg, const QPdfLink &link) { QDebugStateSaver saver(dbg); |