Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qpdflink.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
"qpdflink.h"
5
#
include
"qpdflink_p.h"
6
#
include
"qpdflinkmodel_p.h"
7
#
include
<
QGuiApplication
>
8
#
include
<
QDebug
>
9
10
QT_BEGIN_NAMESPACE
11
12
/*!
13
\class QPdfLink
14
\since 6.4
15
\inmodule QtPdf
16
17
\brief The QPdfLink class defines a link between a region on a page
18
(such as a hyperlink or a search result) and a destination
19
(page, location on the page, and zoom level at which to view it).
20
*/
21
22
/*!
23
Constructs an invalid Destination.
24
25
\sa valid
26
*/
27
QPdfLink::QPdfLink() :
28
QPdfLink(
new
QPdfLinkPrivate()) { }
29
30
QPdfLink
::QPdfLink(
int
page, QPointF location, qreal zoom)
31
: QPdfLink(
new
QPdfLinkPrivate(page, location, zoom))
32
{
33
}
34
35
QPdfLink
::QPdfLink(
int
page, QList<QRectF> rects, QString text,
36
QString contextBefore, QString contextAfter)
37
: QPdfLink(
new
QPdfLinkPrivate(page, std::move(rects), std::move(text),
38
std::move(contextBefore),
39
std::move(contextAfter)))
40
{
41
}
42
43
QPdfLink
::QPdfLink(QPdfLinkPrivate *d) : d(d) {}
44
45
QPdfLink
::~
QPdfLink
() =
default
;
46
QPdfLink
::QPdfLink(
const
QPdfLink
&other)
noexcept
=
default
;
47
QPdfLink
::QPdfLink(
QPdfLink
&&other)
noexcept
=
default
;
48
QPdfLink
&
QPdfLink
::operator=(
const
QPdfLink
&other) =
default
;
49
50
/*!
51
\property QPdfLink::valid
52
53
This property holds whether the link is valid.
54
*/
55
bool
QPdfLink
::
isValid
()
const
56
{
57
return
d->page >= 0;
58
}
59
60
/*!
61
\property QPdfLink::page
62
63
This property holds the page number.
64
If the link is a search result, it is the page number on which the result is found;
65
if the link is a hyperlink, it is the destination page number.
66
*/
67
int
QPdfLink
::
page
()
const
68
{
69
return
d->page;
70
}
71
72
/*!
73
\property QPdfLink::location
74
75
This property holds the location on the \l page, in units of points.
76
If the link is a search result, it is the location where the result is found;
77
if the link is a hyperlink, it is the destination location.
78
*/
79
QPointF
QPdfLink
::location()
const
80
{
81
return
d->location;
82
}
83
84
/*!
85
\property QPdfLink::zoom
86
87
This property holds the suggested magnification level, where 1.0 means default scale
88
(1 pixel = 1 point). If the link is a search result, this value is not used.
89
*/
90
qreal
QPdfLink
::zoom()
const
91
{
92
return
d->zoom;
93
}
94
95
/*!
96
\property QPdfLink::url
97
98
This property holds the destination URL if the link is an external hyperlink;
99
otherwise, it's empty.
100
*/
101
QUrl
QPdfLink
::url()
const
102
{
103
return
d->url;
104
}
105
106
/*!
107
\property QPdfLink::contextBefore
108
109
This property holds adjacent text found on the page before the search string.
110
If the link is a hyperlink, this string is empty.
111
112
\sa QPdfSearchModel::resultsOnPage(), QPdfSearchModel::resultAtIndex()
113
*/
114
QString
QPdfLink
::contextBefore()
const
115
{
116
return
d->contextBefore;
117
}
118
119
/*!
120
\property QPdfLink::contextAfter
121
122
This property holds adjacent text found on the page after the search string.
123
If the link is a hyperlink, this string is empty.
124
125
\sa QPdfSearchModel::resultsOnPage(), QPdfSearchModel::resultAtIndex()
126
*/
127
QString
QPdfLink
::contextAfter()
const
128
{
129
return
d->contextAfter;
130
}
131
132
/*!
133
\property QPdfLink::rectangles
134
135
This property holds the region (set of rectangles) occupied by the link or
136
search result on the page where it was found. If the text wraps around to
137
multiple lines on the page, there may be multiple rectangles:
138
139
\image wrapping-search-result.png {PDF viewer with search results panel
140
showing entries for "the code" and highlighted result on page}
141
142
\sa QPdfSearchModel::resultsOnPage(), QPdfSearchModel::resultAtIndex()
143
*/
144
QList<QRectF>
QPdfLink
::rectangles()
const
145
{
146
return
d->rects;
147
}
148
149
/*!
150
Returns a translated representation for display.
151
152
\sa copyToClipboard()
153
*/
154
QString
QPdfLink
::toString()
const
155
{
156
if
(d->page <= 0)
157
return
d->url.toString();
158
return
QPdfLinkModel::tr(
"Page %1 location %2, %3 zoom %4"
)
159
.arg(d->page).arg(d->location.x(), 0,
'f'
, 1).arg(d->location.y(), 0,
'f'
, 1)
160
.arg(d->zoom, 0,
'f'
, 0);
161
}
162
163
/*!
164
Copies the toString() representation of the link to the
165
\l {QGuiApplication::clipboard()}{system clipboard} depending on the \a mode given.
166
*/
167
void
QPdfLink
::copyToClipboard(QClipboard::Mode mode)
const
168
{
169
QGuiApplication::clipboard()->setText(toString(), mode);
170
}
171
172
#
ifndef
QT_NO_DEBUG_STREAM
173
QDebug operator<<(QDebug dbg,
const
QPdfLink
&link)
174
{
175
QDebugStateSaver saver(dbg);
176
dbg.nospace();
177
dbg <<
"QPdfLink(page="
<< link.page()
178
<<
" location="
<< link.location()
179
<<
" zoom="
<< link.zoom()
180
<<
" contextBefore="
<< link.contextBefore()
181
<<
" contextAfter="
<< link.contextAfter()
182
<<
" rects="
<< link.rectangles();
183
dbg <<
')'
;
184
return
dbg;
185
}
186
#
endif
187
188
QT_END_NAMESPACE
189
190
#
include
"moc_qpdflink.cpp"
QPdfLink
The QPdfLink class defines a link between a region on a page (such as a hyperlink or a search result)...
Definition
qpdflink.h:21
QPdfLink::~QPdfLink
Q_PDF_EXPORT ~QPdfLink()
QPdfLink::page
Q_PDF_EXPORT int page() const
Definition
qpdflink.cpp:67
QPdfLink::isValid
Q_PDF_EXPORT bool isValid() const
Definition
qpdflink.cpp:55
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtwebengine
src
pdf
qpdflink.cpp
Generated on
for Qt by
1.18.0