Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpdfselection.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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
6#include <QGuiApplication>
7
9
10/*!
11 \class QPdfSelection
12 \since 5.15
13 \inmodule QtPdf
14
15 \brief The QPdfSelection class defines a range of text that has been selected
16 on one page in a PDF document, and its geometric boundaries.
17
18 \sa QPdfDocument::getSelection()
19*/
20
21/*!
22 Constructs an invalid selection.
23
24 \sa valid
25*/
26QPdfSelection::QPdfSelection()
27 : d(new QPdfSelectionPrivate())
28{
29}
30
31/*!
32 \internal
33 Constructs a selection including the range of characters that make up the
34 \a text string, and which take up space on the page within the polygon
35 regions given in \a bounds.
36*/
37QPdfSelection::QPdfSelection(const QString &text, QList<QPolygonF> bounds, QRectF boundingRect, int startIndex, int endIndex)
38 : d(new QPdfSelectionPrivate(text, bounds, boundingRect, startIndex, endIndex))
39{
40}
41
42QPdfSelection::QPdfSelection(QPdfSelectionPrivate *d)
43 : d(d)
44{
45}
46
47QPdfSelection::~QPdfSelection() = default;
48QPdfSelection::QPdfSelection(const QPdfSelection &other) = default;
49QPdfSelection::QPdfSelection(QPdfSelection &&other) noexcept = default;
50QPdfSelection &QPdfSelection::operator=(const QPdfSelection &other) = default;
51
52/*!
53 \property QPdfSelection::valid
54
55 This property holds whether the selection is valid.
56*/
57bool QPdfSelection::isValid() const
58{
59 return !d->bounds.isEmpty();
60}
61
62/*!
63 \property QPdfSelection::bounds
64
65 This property holds a set of regions that the selected text occupies on the
66 page, represented as polygons. The coordinate system for the polygons has
67 the origin at the upper-left corner of the page, and the units are
68 \l {https://en.wikipedia.org/wiki/Point_(typography)}{points}.
69
70 \note For now, the polygons returned from \l QPdfDocument::getSelection()
71 are always rectangles; but in the future it may be possible to represent
72 more complex regions.
73*/
74QList<QPolygonF> QPdfSelection::bounds() const
75{
76 return d->bounds;
77}
78
79/*!
80 \property QPdfSelection::text
81
82 This property holds the selected text.
83*/
84QString QPdfSelection::text() const
85{
86 return d->text;
87}
88
89/*!
90 \property QPdfSelection::boundingRectangle
91
92 This property holds the overall bounding rectangle (convex hull) around \l bounds.
93*/
94QRectF QPdfSelection::boundingRectangle() const
95{
96 return d->boundingRect;
97}
98
99/*!
100 \property QPdfSelection::startIndex
101
102 This property holds the index at the beginning of \l text within the full text on the page.
103*/
105{
106 return d->startIndex;
107}
108
109/*!
110 \property QPdfSelection::endIndex
111
112 This property holds the index at the end of \l text within the full text on the page.
113*/
115{
116 return d->endIndex;
117}
118
119#if QT_CONFIG(clipboard)
120/*!
121 Copies \l text to the \l {QGuiApplication::clipboard()}{system clipboard}
122 depending on the \a mode selected.
123*/
124void QPdfSelection::copyToClipboard(QClipboard::Mode mode) const
125{
126 QGuiApplication::clipboard()->setText(d->text, mode);
127}
128#endif
129
130QT_END_NAMESPACE
131
132#include "moc_qpdfselection.cpp"
The QPdfSelection class defines a range of text that has been selected on one page in a PDF document,...
Q_PDF_EXPORT int startIndex() const
Q_PDF_EXPORT int endIndex() const