1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtPDF module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL3$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or later as published by the Free
28 ** Software Foundation and appearing in the file LICENSE.GPL included in
29 ** the packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 2.0 requirements will be
31 ** met: http://www.gnu.org/licenses/gpl-2.0.html.
32 **
33 ** $QT_END_LICENSE$
34 **
35 ****************************************************************************/
36
37 #include "qpdfselection.h"
38 #include "qpdfselection_p.h"
39 #include <QGuiApplication>
40
41 QT_BEGIN_NAMESPACE
42
43 /*!
44 \class QPdfSelection
45 \since 5.15
46 \inmodule QtPdf
47
48 \brief The QPdfSelection class defines a range of text that has been selected
49 on one page in a PDF document, and its geometric boundaries.
50
51 \sa QPdfDocument::getSelection()
52 */
53
54 /*!
55 Constructs an invalid selection.
56
57 \sa valid
58 */
QPdfSelection()59 QPdfSelection::QPdfSelection()
60 : d(new QPdfSelectionPrivate())
61 {
62 }
63
64 /*!
65 \internal
66 Constructs a selection including the range of characters that make up the
67 \a text string, and which take up space on the page within the polygon
68 regions given in \a bounds.
69 */
QPdfSelection(const QString & text,QVector<QPolygonF> bounds,QRectF boundingRect,int startIndex,int endIndex)70 QPdfSelection::QPdfSelection(const QString &text, QVector<QPolygonF> bounds, QRectF boundingRect, int startIndex, int endIndex)
71 : d(new QPdfSelectionPrivate(text, bounds, boundingRect, startIndex, endIndex))
72 {
73 }
74
QPdfSelection(QPdfSelectionPrivate * d)75 QPdfSelection::QPdfSelection(QPdfSelectionPrivate *d)
76 : d(d)
77 {
78 }
79
QPdfSelection(const QPdfSelection & other)80 QPdfSelection::QPdfSelection(const QPdfSelection &other)
81 : d(other.d)
82 {
83 }
84
QPdfSelection(QPdfSelection && other)85 QPdfSelection::QPdfSelection(QPdfSelection &&other) noexcept
86 : d(std::move(other.d))
87 {
88 }
89
~QPdfSelection()90 QPdfSelection::~QPdfSelection()
91 {
92 }
93
operator =(const QPdfSelection & other)94 QPdfSelection &QPdfSelection::operator=(const QPdfSelection &other)
95 {
96 d = other.d;
97 return *this;
98 }
99
100 /*!
101 \property QPdfSelection::valid
102
103 This property holds whether the selection is valid.
104 */
isValid() const105 bool QPdfSelection::isValid() const
106 {
107 return !d->bounds.isEmpty();
108 }
109
110 /*!
111 \property QPdfSelection::bounds
112
113 This property holds a set of regions that the selected text occupies on the
114 page, represented as polygons. The coordinate system for the polygons has
115 the origin at the upper-left corner of the page, and the units are
116 \l {https://en.wikipedia.org/wiki/Point_(typography)}{points}.
117
118 \note For now, the polygons returned from \l QPdfDocument::getSelection()
119 are always rectangles; but in the future it may be possible to represent
120 more complex regions.
121 */
bounds() const122 QVector<QPolygonF> QPdfSelection::bounds() const
123 {
124 return d->bounds;
125 }
126
127 /*!
128 \property QPdfSelection::text
129
130 This property holds the selected text.
131 */
text() const132 QString QPdfSelection::text() const
133 {
134 return d->text;
135 }
136
137 /*!
138 \property rect QPdfSelection::boundingRectangle
139
140 This property holds the overall bounding rectangle (convex hull) around \l bounds.
141 */
boundingRectangle() const142 QRectF QPdfSelection::boundingRectangle() const
143 {
144 return d->boundingRect;
145 }
146
147 /*!
148 \property int QPdfSelection::startIndex
149
150 This property holds the index at the beginning of \l text within the full text on the page.
151 */
startIndex() const152 int QPdfSelection::startIndex() const
153 {
154 return d->startIndex;
155 }
156
157 /*!
158 \property int QPdfSelection::endIndex
159
160 This property holds the index at the end of \l text within the full text on the page.
161 */
endIndex() const162 int QPdfSelection::endIndex() const
163 {
164 return d->endIndex;
165 }
166
167 #if QT_CONFIG(clipboard)
168 /*!
169 Copies \l text to the \l {QGuiApplication::clipboard()}{system clipboard}.
170 */
copyToClipboard(QClipboard::Mode mode) const171 void QPdfSelection::copyToClipboard(QClipboard::Mode mode) const
172 {
173 QGuiApplication::clipboard()->setText(d->text, mode);
174 }
175 #endif
176
177 QT_END_NAMESPACE
178
179 #include "moc_qpdfselection.cpp"
180