1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QPAINTERPATH_H |
41 | #define QPAINTERPATH_H |
42 | |
43 | #include <QtGui/qtguiglobal.h> |
44 | #include <QtGui/qtransform.h> |
45 | #include <QtCore/qglobal.h> |
46 | #include <QtCore/qline.h> |
47 | #include <QtCore/qlist.h> |
48 | #include <QtCore/qrect.h> |
49 | #include <QtCore/qscopedpointer.h> |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | |
54 | class QFont; |
55 | class QPainterPathPrivate; |
56 | struct QPainterPathPrivateDeleter; |
57 | class QPainterPathStrokerPrivate; |
58 | class QPen; |
59 | class QPolygonF; |
60 | class QRegion; |
61 | class QTransform; |
62 | class QVectorPath; |
63 | |
64 | class Q_GUI_EXPORT QPainterPath |
65 | { |
66 | public: |
67 | enum ElementType { |
68 | MoveToElement, |
69 | LineToElement, |
70 | CurveToElement, |
71 | CurveToDataElement |
72 | }; |
73 | |
74 | class Element { |
75 | public: |
76 | qreal x; |
77 | qreal y; |
78 | ElementType type; |
79 | |
80 | bool isMoveTo() const { return type == MoveToElement; } |
81 | bool isLineTo() const { return type == LineToElement; } |
82 | bool isCurveTo() const { return type == CurveToElement; } |
83 | |
84 | operator QPointF () const { return QPointF(x, y); } |
85 | |
86 | bool operator==(const Element &e) const { return qFuzzyCompare(x, e.x) |
87 | && qFuzzyCompare(y, e.y) && type == e.type; } |
88 | inline bool operator!=(const Element &e) const { return !operator==(e); } |
89 | }; |
90 | |
91 | QPainterPath() noexcept; |
92 | explicit QPainterPath(const QPointF &startPoint); |
93 | QPainterPath(const QPainterPath &other); |
94 | QPainterPath &operator=(const QPainterPath &other); |
95 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath) |
96 | ~QPainterPath(); |
97 | |
98 | inline void swap(QPainterPath &other) noexcept { d_ptr.swap(other.d_ptr); } |
99 | |
100 | void clear(); |
101 | void reserve(int size); |
102 | int capacity() const; |
103 | |
104 | void closeSubpath(); |
105 | |
106 | void moveTo(const QPointF &p); |
107 | inline void moveTo(qreal x, qreal y); |
108 | |
109 | void lineTo(const QPointF &p); |
110 | inline void lineTo(qreal x, qreal y); |
111 | |
112 | void arcMoveTo(const QRectF &rect, qreal angle); |
113 | inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle); |
114 | |
115 | void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength); |
116 | inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength); |
117 | |
118 | void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt); |
119 | inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
120 | qreal endPtx, qreal endPty); |
121 | void quadTo(const QPointF &ctrlPt, const QPointF &endPt); |
122 | inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty); |
123 | |
124 | QPointF currentPosition() const; |
125 | |
126 | void addRect(const QRectF &rect); |
127 | inline void addRect(qreal x, qreal y, qreal w, qreal h); |
128 | void addEllipse(const QRectF &rect); |
129 | inline void addEllipse(qreal x, qreal y, qreal w, qreal h); |
130 | inline void addEllipse(const QPointF ¢er, qreal rx, qreal ry); |
131 | void addPolygon(const QPolygonF &polygon); |
132 | void addText(const QPointF &point, const QFont &f, const QString &text); |
133 | inline void addText(qreal x, qreal y, const QFont &f, const QString &text); |
134 | void addPath(const QPainterPath &path); |
135 | void addRegion(const QRegion ®ion); |
136 | |
137 | void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, |
138 | Qt::SizeMode mode = Qt::AbsoluteSize); |
139 | inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
140 | qreal xRadius, qreal yRadius, |
141 | Qt::SizeMode mode = Qt::AbsoluteSize); |
142 | |
143 | void connectPath(const QPainterPath &path); |
144 | |
145 | bool contains(const QPointF &pt) const; |
146 | bool contains(const QRectF &rect) const; |
147 | bool intersects(const QRectF &rect) const; |
148 | |
149 | void translate(qreal dx, qreal dy); |
150 | inline void translate(const QPointF &offset); |
151 | |
152 | [[nodiscard]] QPainterPath translated(qreal dx, qreal dy) const; |
153 | [[nodiscard]] inline QPainterPath translated(const QPointF &offset) const; |
154 | |
155 | QRectF boundingRect() const; |
156 | QRectF controlPointRect() const; |
157 | |
158 | Qt::FillRule fillRule() const; |
159 | void setFillRule(Qt::FillRule fillRule); |
160 | |
161 | bool isEmpty() const; |
162 | |
163 | [[nodiscard]] QPainterPath toReversed() const; |
164 | |
165 | QList<QPolygonF> toSubpathPolygons(const QTransform &matrix = QTransform()) const; |
166 | QList<QPolygonF> toFillPolygons(const QTransform &matrix = QTransform()) const; |
167 | QPolygonF toFillPolygon(const QTransform &matrix = QTransform()) const; |
168 | |
169 | int elementCount() const; |
170 | QPainterPath::Element elementAt(int i) const; |
171 | void setElementPositionAt(int i, qreal x, qreal y); |
172 | |
173 | qreal length() const; |
174 | qreal percentAtLength(qreal t) const; |
175 | QPointF pointAtPercent(qreal t) const; |
176 | qreal angleAtPercent(qreal t) const; |
177 | qreal slopeAtPercent(qreal t) const; |
178 | |
179 | bool intersects(const QPainterPath &p) const; |
180 | bool contains(const QPainterPath &p) const; |
181 | [[nodiscard]] QPainterPath united(const QPainterPath &r) const; |
182 | [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const; |
183 | [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const; |
184 | |
185 | [[nodiscard]] QPainterPath simplified() const; |
186 | |
187 | bool operator==(const QPainterPath &other) const; |
188 | bool operator!=(const QPainterPath &other) const; |
189 | |
190 | QPainterPath operator&(const QPainterPath &other) const; |
191 | QPainterPath operator|(const QPainterPath &other) const; |
192 | QPainterPath operator+(const QPainterPath &other) const; |
193 | QPainterPath operator-(const QPainterPath &other) const; |
194 | QPainterPath &operator&=(const QPainterPath &other); |
195 | QPainterPath &operator|=(const QPainterPath &other); |
196 | QPainterPath &operator+=(const QPainterPath &other); |
197 | QPainterPath &operator-=(const QPainterPath &other); |
198 | |
199 | private: |
200 | QScopedPointer<QPainterPathPrivate, QPainterPathPrivateDeleter> d_ptr; |
201 | |
202 | inline void ensureData() { if (!d_ptr) ensureData_helper(); } |
203 | void ensureData_helper(); |
204 | void detach(); |
205 | void detach_helper(); |
206 | void setDirty(bool); |
207 | void computeBoundingRect() const; |
208 | void computeControlPointRect() const; |
209 | |
210 | QPainterPathPrivate *d_func() const { return d_ptr.data(); } |
211 | |
212 | friend class QPainterPathStroker; |
213 | friend class QPainterPathStrokerPrivate; |
214 | friend class QTransform; |
215 | friend class QVectorPath; |
216 | friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &); |
217 | |
218 | #ifndef QT_NO_DATASTREAM |
219 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
220 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
221 | #endif |
222 | }; |
223 | |
224 | Q_DECLARE_SHARED(QPainterPath) |
225 | Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE); |
226 | |
227 | #ifndef QT_NO_DATASTREAM |
228 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
229 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
230 | #endif |
231 | |
232 | class Q_GUI_EXPORT QPainterPathStroker |
233 | { |
234 | Q_DECLARE_PRIVATE(QPainterPathStroker) |
235 | public: |
236 | QPainterPathStroker(); |
237 | explicit QPainterPathStroker(const QPen &pen); |
238 | ~QPainterPathStroker(); |
239 | |
240 | void setWidth(qreal width); |
241 | qreal width() const; |
242 | |
243 | void setCapStyle(Qt::PenCapStyle style); |
244 | Qt::PenCapStyle capStyle() const; |
245 | |
246 | void setJoinStyle(Qt::PenJoinStyle style); |
247 | Qt::PenJoinStyle joinStyle() const; |
248 | |
249 | void setMiterLimit(qreal length); |
250 | qreal miterLimit() const; |
251 | |
252 | void setCurveThreshold(qreal threshold); |
253 | qreal curveThreshold() const; |
254 | |
255 | void setDashPattern(Qt::PenStyle); |
256 | void setDashPattern(const QList<qreal> &dashPattern); |
257 | QList<qreal> dashPattern() const; |
258 | |
259 | void setDashOffset(qreal offset); |
260 | qreal dashOffset() const; |
261 | |
262 | QPainterPath createStroke(const QPainterPath &path) const; |
263 | |
264 | private: |
265 | Q_DISABLE_COPY(QPainterPathStroker) |
266 | |
267 | friend class QX11PaintEngine; |
268 | |
269 | QScopedPointer<QPainterPathStrokerPrivate> d_ptr; |
270 | }; |
271 | |
272 | inline void QPainterPath::moveTo(qreal x, qreal y) |
273 | { |
274 | moveTo(QPointF(x, y)); |
275 | } |
276 | |
277 | inline void QPainterPath::lineTo(qreal x, qreal y) |
278 | { |
279 | lineTo(QPointF(x, y)); |
280 | } |
281 | |
282 | inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength) |
283 | { |
284 | arcTo(QRectF(x, y, w, h), startAngle, arcLength); |
285 | } |
286 | |
287 | inline void QPainterPath::arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle) |
288 | { |
289 | arcMoveTo(QRectF(x, y, w, h), angle); |
290 | } |
291 | |
292 | inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
293 | qreal endPtx, qreal endPty) |
294 | { |
295 | cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y), |
296 | QPointF(endPtx, endPty)); |
297 | } |
298 | |
299 | inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) |
300 | { |
301 | quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty)); |
302 | } |
303 | |
304 | inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h) |
305 | { |
306 | addEllipse(QRectF(x, y, w, h)); |
307 | } |
308 | |
309 | inline void QPainterPath::addEllipse(const QPointF ¢er, qreal rx, qreal ry) |
310 | { |
311 | addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry)); |
312 | } |
313 | |
314 | inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h) |
315 | { |
316 | addRect(QRectF(x, y, w, h)); |
317 | } |
318 | |
319 | inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
320 | qreal xRadius, qreal yRadius, |
321 | Qt::SizeMode mode) |
322 | { |
323 | addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode); |
324 | } |
325 | |
326 | inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text) |
327 | { |
328 | addText(QPointF(x, y), f, text); |
329 | } |
330 | |
331 | inline void QPainterPath::translate(const QPointF &offset) |
332 | { translate(offset.x(), offset.y()); } |
333 | |
334 | inline QPainterPath QPainterPath::translated(const QPointF &offset) const |
335 | { return translated(offset.x(), offset.y()); } |
336 | |
337 | inline QPainterPath operator *(const QPainterPath &p, const QTransform &m) |
338 | { return m.map(p); } |
339 | |
340 | #ifndef QT_NO_DEBUG_STREAM |
341 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &); |
342 | #endif |
343 | |
344 | QT_END_NAMESPACE |
345 | |
346 | #endif // QPAINTERPATH_H |
347 | |