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/qmatrix.h> |
45 | #include <QtCore/qglobal.h> |
46 | #include <QtCore/qrect.h> |
47 | #include <QtCore/qline.h> |
48 | #include <QtCore/qvector.h> |
49 | #include <QtCore/qscopedpointer.h> |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | |
54 | class QFont; |
55 | class QPainterPathPrivate; |
56 | struct QPainterPathPrivateDeleter; |
57 | class QPainterPathData; |
58 | class QPainterPathStrokerPrivate; |
59 | class QPen; |
60 | class QPolygonF; |
61 | class QRegion; |
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() Q_DECL_NOEXCEPT; |
92 | explicit QPainterPath(const QPointF &startPoint); |
93 | QPainterPath(const QPainterPath &other); |
94 | QPainterPath &operator=(const QPainterPath &other); |
95 | #ifdef Q_COMPILER_RVALUE_REFS |
96 | inline QPainterPath &operator=(QPainterPath &&other) Q_DECL_NOEXCEPT |
97 | { qSwap(d_ptr, other.d_ptr); return *this; } |
98 | #endif |
99 | ~QPainterPath(); |
100 | inline void swap(QPainterPath &other) Q_DECL_NOEXCEPT { d_ptr.swap(other.d_ptr); } |
101 | |
102 | void closeSubpath(); |
103 | |
104 | void moveTo(const QPointF &p); |
105 | inline void moveTo(qreal x, qreal y); |
106 | |
107 | void lineTo(const QPointF &p); |
108 | inline void lineTo(qreal x, qreal y); |
109 | |
110 | void arcMoveTo(const QRectF &rect, qreal angle); |
111 | inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle); |
112 | |
113 | void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength); |
114 | inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength); |
115 | |
116 | void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt); |
117 | inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
118 | qreal endPtx, qreal endPty); |
119 | void quadTo(const QPointF &ctrlPt, const QPointF &endPt); |
120 | inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty); |
121 | |
122 | QPointF currentPosition() const; |
123 | |
124 | void addRect(const QRectF &rect); |
125 | inline void addRect(qreal x, qreal y, qreal w, qreal h); |
126 | void addEllipse(const QRectF &rect); |
127 | inline void addEllipse(qreal x, qreal y, qreal w, qreal h); |
128 | inline void addEllipse(const QPointF ¢er, qreal rx, qreal ry); |
129 | void addPolygon(const QPolygonF &polygon); |
130 | void addText(const QPointF &point, const QFont &f, const QString &text); |
131 | inline void addText(qreal x, qreal y, const QFont &f, const QString &text); |
132 | void addPath(const QPainterPath &path); |
133 | void addRegion(const QRegion ®ion); |
134 | |
135 | void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, |
136 | Qt::SizeMode mode = Qt::AbsoluteSize); |
137 | inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
138 | qreal xRadius, qreal yRadius, |
139 | Qt::SizeMode mode = Qt::AbsoluteSize); |
140 | |
141 | void addRoundRect(const QRectF &rect, int xRnd, int yRnd); |
142 | inline void addRoundRect(qreal x, qreal y, qreal w, qreal h, |
143 | int xRnd, int yRnd); |
144 | inline void addRoundRect(const QRectF &rect, int roundness); |
145 | inline void addRoundRect(qreal x, qreal y, qreal w, qreal h, |
146 | int roundness); |
147 | |
148 | void connectPath(const QPainterPath &path); |
149 | |
150 | bool contains(const QPointF &pt) const; |
151 | bool contains(const QRectF &rect) const; |
152 | bool intersects(const QRectF &rect) const; |
153 | |
154 | void translate(qreal dx, qreal dy); |
155 | inline void translate(const QPointF &offset); |
156 | |
157 | Q_REQUIRED_RESULT QPainterPath translated(qreal dx, qreal dy) const; |
158 | Q_REQUIRED_RESULT inline QPainterPath translated(const QPointF &offset) const; |
159 | |
160 | QRectF boundingRect() const; |
161 | QRectF controlPointRect() const; |
162 | |
163 | Qt::FillRule fillRule() const; |
164 | void setFillRule(Qt::FillRule fillRule); |
165 | |
166 | bool isEmpty() const; |
167 | |
168 | Q_REQUIRED_RESULT QPainterPath toReversed() const; |
169 | QList<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const; |
170 | QList<QPolygonF> toFillPolygons(const QMatrix &matrix = QMatrix()) const; |
171 | QPolygonF toFillPolygon(const QMatrix &matrix = QMatrix()) const; |
172 | QList<QPolygonF> toSubpathPolygons(const QTransform &matrix) const; |
173 | QList<QPolygonF> toFillPolygons(const QTransform &matrix) const; |
174 | QPolygonF toFillPolygon(const QTransform &matrix) const; |
175 | |
176 | int elementCount() const; |
177 | QPainterPath::Element elementAt(int i) const; |
178 | void setElementPositionAt(int i, qreal x, qreal y); |
179 | |
180 | qreal length() const; |
181 | qreal percentAtLength(qreal t) const; |
182 | QPointF pointAtPercent(qreal t) const; |
183 | qreal angleAtPercent(qreal t) const; |
184 | qreal slopeAtPercent(qreal t) const; |
185 | |
186 | bool intersects(const QPainterPath &p) const; |
187 | bool contains(const QPainterPath &p) const; |
188 | Q_REQUIRED_RESULT QPainterPath united(const QPainterPath &r) const; |
189 | Q_REQUIRED_RESULT QPainterPath intersected(const QPainterPath &r) const; |
190 | Q_REQUIRED_RESULT QPainterPath subtracted(const QPainterPath &r) const; |
191 | Q_REQUIRED_RESULT QPainterPath subtractedInverted(const QPainterPath &r) const; |
192 | |
193 | Q_REQUIRED_RESULT QPainterPath simplified() const; |
194 | |
195 | bool operator==(const QPainterPath &other) const; |
196 | bool operator!=(const QPainterPath &other) const; |
197 | |
198 | QPainterPath operator&(const QPainterPath &other) const; |
199 | QPainterPath operator|(const QPainterPath &other) const; |
200 | QPainterPath operator+(const QPainterPath &other) const; |
201 | QPainterPath operator-(const QPainterPath &other) const; |
202 | QPainterPath &operator&=(const QPainterPath &other); |
203 | QPainterPath &operator|=(const QPainterPath &other); |
204 | QPainterPath &operator+=(const QPainterPath &other); |
205 | QPainterPath &operator-=(const QPainterPath &other); |
206 | |
207 | private: |
208 | QScopedPointer<QPainterPathPrivate, QPainterPathPrivateDeleter> d_ptr; |
209 | |
210 | inline void ensureData() { if (!d_ptr) ensureData_helper(); } |
211 | void ensureData_helper(); |
212 | void detach(); |
213 | void detach_helper(); |
214 | void setDirty(bool); |
215 | void computeBoundingRect() const; |
216 | void computeControlPointRect() const; |
217 | |
218 | QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr.data()); } |
219 | |
220 | friend class QPainterPathData; |
221 | friend class QPainterPathStroker; |
222 | friend class QPainterPathStrokerPrivate; |
223 | friend class QMatrix; |
224 | friend class QTransform; |
225 | friend class QVectorPath; |
226 | friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &); |
227 | |
228 | #ifndef QT_NO_DATASTREAM |
229 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
230 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
231 | #endif |
232 | }; |
233 | |
234 | Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPainterPath) |
235 | Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE); |
236 | |
237 | #ifndef QT_NO_DATASTREAM |
238 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
239 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
240 | #endif |
241 | |
242 | class Q_GUI_EXPORT QPainterPathStroker |
243 | { |
244 | Q_DECLARE_PRIVATE(QPainterPathStroker) |
245 | public: |
246 | QPainterPathStroker(); |
247 | explicit QPainterPathStroker(const QPen &pen); |
248 | ~QPainterPathStroker(); |
249 | |
250 | void setWidth(qreal width); |
251 | qreal width() const; |
252 | |
253 | void setCapStyle(Qt::PenCapStyle style); |
254 | Qt::PenCapStyle capStyle() const; |
255 | |
256 | void setJoinStyle(Qt::PenJoinStyle style); |
257 | Qt::PenJoinStyle joinStyle() const; |
258 | |
259 | void setMiterLimit(qreal length); |
260 | qreal miterLimit() const; |
261 | |
262 | void setCurveThreshold(qreal threshold); |
263 | qreal curveThreshold() const; |
264 | |
265 | void setDashPattern(Qt::PenStyle); |
266 | void setDashPattern(const QVector<qreal> &dashPattern); |
267 | QVector<qreal> dashPattern() const; |
268 | |
269 | void setDashOffset(qreal offset); |
270 | qreal dashOffset() const; |
271 | |
272 | QPainterPath createStroke(const QPainterPath &path) const; |
273 | |
274 | private: |
275 | Q_DISABLE_COPY(QPainterPathStroker) |
276 | |
277 | friend class QX11PaintEngine; |
278 | |
279 | QScopedPointer<QPainterPathStrokerPrivate> d_ptr; |
280 | }; |
281 | |
282 | inline void QPainterPath::moveTo(qreal x, qreal y) |
283 | { |
284 | moveTo(QPointF(x, y)); |
285 | } |
286 | |
287 | inline void QPainterPath::lineTo(qreal x, qreal y) |
288 | { |
289 | lineTo(QPointF(x, y)); |
290 | } |
291 | |
292 | inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength) |
293 | { |
294 | arcTo(QRectF(x, y, w, h), startAngle, arcLength); |
295 | } |
296 | |
297 | inline void QPainterPath::arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle) |
298 | { |
299 | arcMoveTo(QRectF(x, y, w, h), angle); |
300 | } |
301 | |
302 | inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
303 | qreal endPtx, qreal endPty) |
304 | { |
305 | cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y), |
306 | QPointF(endPtx, endPty)); |
307 | } |
308 | |
309 | inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) |
310 | { |
311 | quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty)); |
312 | } |
313 | |
314 | inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h) |
315 | { |
316 | addEllipse(QRectF(x, y, w, h)); |
317 | } |
318 | |
319 | inline void QPainterPath::addEllipse(const QPointF ¢er, qreal rx, qreal ry) |
320 | { |
321 | addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry)); |
322 | } |
323 | |
324 | inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h) |
325 | { |
326 | addRect(QRectF(x, y, w, h)); |
327 | } |
328 | |
329 | inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
330 | qreal xRadius, qreal yRadius, |
331 | Qt::SizeMode mode) |
332 | { |
333 | addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode); |
334 | } |
335 | |
336 | inline void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, |
337 | int xRnd, int yRnd) |
338 | { |
339 | addRoundRect(QRectF(x, y, w, h), xRnd, yRnd); |
340 | } |
341 | |
342 | inline void QPainterPath::addRoundRect(const QRectF &rect, |
343 | int roundness) |
344 | { |
345 | int xRnd = roundness; |
346 | int yRnd = roundness; |
347 | if (rect.width() > rect.height()) |
348 | xRnd = int(roundness * rect.height()/rect.width()); |
349 | else |
350 | yRnd = int(roundness * rect.width()/rect.height()); |
351 | addRoundRect(rect, xRnd, yRnd); |
352 | } |
353 | |
354 | inline void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, |
355 | int roundness) |
356 | { |
357 | addRoundRect(QRectF(x, y, w, h), roundness); |
358 | } |
359 | |
360 | inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text) |
361 | { |
362 | addText(QPointF(x, y), f, text); |
363 | } |
364 | |
365 | inline void QPainterPath::translate(const QPointF &offset) |
366 | { translate(offset.x(), offset.y()); } |
367 | |
368 | inline QPainterPath QPainterPath::translated(const QPointF &offset) const |
369 | { return translated(offset.x(), offset.y()); } |
370 | |
371 | |
372 | #ifndef QT_NO_DEBUG_STREAM |
373 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &); |
374 | #endif |
375 | |
376 | QT_END_NAMESPACE |
377 | |
378 | #endif // QPAINTERPATH_H |
379 | |