/src/qtbase/src/gui/painting/qpainterpath.h
Line | Count | Source |
1 | | // Copyright (C) 2016 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 | | #ifndef QPAINTERPATH_H |
5 | | #define QPAINTERPATH_H |
6 | | |
7 | | #include <QtGui/qtguiglobal.h> |
8 | | #include <QtGui/qtransform.h> |
9 | | |
10 | | #include <QtCore/qglobal.h> |
11 | | #include <QtCore/qline.h> |
12 | | #include <QtCore/qlist.h> |
13 | | #include <QtCore/qpoint.h> |
14 | | #include <QtCore/qrect.h> |
15 | | |
16 | | QT_BEGIN_NAMESPACE |
17 | | |
18 | | |
19 | | class QFont; |
20 | | class QPainterPathPrivate; |
21 | | class QPainterPathStrokerPrivate; |
22 | | class QPen; |
23 | | class QPolygonF; |
24 | | class QRegion; |
25 | | class QTransform; |
26 | | class QVectorPath; |
27 | | |
28 | | class Q_GUI_EXPORT QPainterPath |
29 | | { |
30 | | public: |
31 | | enum ElementType { |
32 | | MoveToElement, |
33 | | LineToElement, |
34 | | CurveToElement, |
35 | | CurveToDataElement |
36 | | }; |
37 | | |
38 | | class Element { |
39 | | public: |
40 | | qreal x; |
41 | | qreal y; |
42 | | ElementType type; |
43 | | |
44 | 161k | bool isMoveTo() const { return type == MoveToElement; } |
45 | 164k | bool isLineTo() const { return type == LineToElement; } |
46 | 0 | bool isCurveTo() const { return type == CurveToElement; } |
47 | | |
48 | 2.18M | operator QPointF () const { return QPointF(x, y); } |
49 | | |
50 | | bool operator==(const Element &e) const |
51 | 0 | { |
52 | 0 | return type == e.type |
53 | 0 | && qFuzzyCompare(QPointF(*this), QPointF(e)); |
54 | 0 | } |
55 | 0 | inline bool operator!=(const Element &e) const { return !operator==(e); } |
56 | | }; |
57 | | |
58 | | QPainterPath() noexcept; |
59 | | explicit QPainterPath(const QPointF &startPoint); |
60 | | QPainterPath(const QPainterPath &other); |
61 | | QPainterPath &operator=(const QPainterPath &other); |
62 | | QPainterPath(QPainterPath &&other) noexcept |
63 | 26.5k | : d_ptr(std::exchange(other.d_ptr, nullptr)) |
64 | 26.5k | {} |
65 | | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath) |
66 | | ~QPainterPath(); |
67 | | |
68 | 3.95k | inline void swap(QPainterPath &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); } |
69 | | |
70 | | void clear(); |
71 | | void reserve(int size); |
72 | | int capacity() const; |
73 | | |
74 | | void closeSubpath(); |
75 | | |
76 | | void moveTo(const QPointF &p); |
77 | | inline void moveTo(qreal x, qreal y); |
78 | | |
79 | | void lineTo(const QPointF &p); |
80 | | inline void lineTo(qreal x, qreal y); |
81 | | |
82 | | void arcMoveTo(const QRectF &rect, qreal angle); |
83 | | inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle); |
84 | | |
85 | | void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength); |
86 | | inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength); |
87 | | |
88 | | void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt); |
89 | | inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
90 | | qreal endPtx, qreal endPty); |
91 | | void quadTo(const QPointF &ctrlPt, const QPointF &endPt); |
92 | | inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty); |
93 | | |
94 | | QPointF currentPosition() const; |
95 | | |
96 | | void addRect(const QRectF &rect); |
97 | | inline void addRect(qreal x, qreal y, qreal w, qreal h); |
98 | | void addEllipse(const QRectF &rect); |
99 | | inline void addEllipse(qreal x, qreal y, qreal w, qreal h); |
100 | | inline void addEllipse(const QPointF ¢er, qreal rx, qreal ry); |
101 | | void addPolygon(const QPolygonF &polygon); |
102 | | void addText(const QPointF &point, const QFont &f, const QString &text); |
103 | | inline void addText(qreal x, qreal y, const QFont &f, const QString &text); |
104 | | void addPath(const QPainterPath &path); |
105 | | void addRegion(const QRegion ®ion); |
106 | | |
107 | | void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, |
108 | | Qt::SizeMode mode = Qt::AbsoluteSize); |
109 | | inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
110 | | qreal xRadius, qreal yRadius, |
111 | | Qt::SizeMode mode = Qt::AbsoluteSize); |
112 | | |
113 | | void connectPath(const QPainterPath &path); |
114 | | |
115 | | bool contains(const QPointF &pt) const; |
116 | | bool contains(const QRectF &rect) const; |
117 | | bool intersects(const QRectF &rect) const; |
118 | | |
119 | | void translate(qreal dx, qreal dy); |
120 | | inline void translate(const QPointF &offset); |
121 | | |
122 | | [[nodiscard]] QPainterPath translated(qreal dx, qreal dy) const; |
123 | | [[nodiscard]] inline QPainterPath translated(const QPointF &offset) const; |
124 | | |
125 | | QRectF boundingRect() const; |
126 | | QRectF controlPointRect() const; |
127 | | |
128 | | Qt::FillRule fillRule() const; |
129 | | void setFillRule(Qt::FillRule fillRule); |
130 | | |
131 | | bool isEmpty() const; |
132 | | |
133 | | [[nodiscard]] QPainterPath toReversed() const; |
134 | | |
135 | | QList<QPolygonF> toSubpathPolygons(const QTransform &matrix = QTransform()) const; |
136 | | QList<QPolygonF> toFillPolygons(const QTransform &matrix = QTransform()) const; |
137 | | QPolygonF toFillPolygon(const QTransform &matrix = QTransform()) const; |
138 | | |
139 | | int elementCount() const; |
140 | | QPainterPath::Element elementAt(int i) const; |
141 | | void setElementPositionAt(int i, qreal x, qreal y); |
142 | | |
143 | | bool isCachingEnabled() const; |
144 | | void setCachingEnabled(bool enabled); |
145 | | qreal length() const; |
146 | | qreal percentAtLength(qreal len) const; |
147 | | QPointF pointAtPercent(qreal t) const; |
148 | | qreal angleAtPercent(qreal t) const; |
149 | | qreal slopeAtPercent(qreal t) const; |
150 | | [[nodiscard]] QPainterPath trimmed(qreal fromFraction, qreal toFraction, qreal offset = 0) const; |
151 | | |
152 | | bool intersects(const QPainterPath &p) const; |
153 | | bool contains(const QPainterPath &p) const; |
154 | | [[nodiscard]] QPainterPath united(const QPainterPath &r) const; |
155 | | [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const; |
156 | | [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const; |
157 | | |
158 | | [[nodiscard]] QPainterPath simplified() const; |
159 | | |
160 | | bool operator==(const QPainterPath &other) const; |
161 | | bool operator!=(const QPainterPath &other) const; |
162 | | |
163 | | QPainterPath operator&(const QPainterPath &other) const; |
164 | | QPainterPath operator|(const QPainterPath &other) const; |
165 | | QPainterPath operator+(const QPainterPath &other) const; |
166 | | QPainterPath operator-(const QPainterPath &other) const; |
167 | | QPainterPath &operator&=(const QPainterPath &other); |
168 | | QPainterPath &operator|=(const QPainterPath &other); |
169 | | QPainterPath &operator+=(const QPainterPath &other); |
170 | | QPainterPath &operator-=(const QPainterPath &other); |
171 | | |
172 | | private: |
173 | | QPainterPathPrivate *d_ptr; |
174 | | |
175 | 1.56M | inline void ensureData() { if (!d_ptr) ensureData_helper(); } |
176 | | void ensureData_helper(); |
177 | | void setDirty(bool); |
178 | | void computeBoundingRect() const; |
179 | | void computeControlPointRect() const; |
180 | | |
181 | 10.1M | QPainterPathPrivate *d_func() const { return d_ptr; } |
182 | | |
183 | | friend class QPainterPathStroker; |
184 | | friend class QPainterPathStrokerPrivate; |
185 | | friend class QPainterPathPrivate; |
186 | | friend class QTransform; |
187 | | friend class QVectorPath; |
188 | | friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &); |
189 | | |
190 | | #ifndef QT_NO_DATASTREAM |
191 | | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
192 | | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
193 | | #endif |
194 | | }; |
195 | | |
196 | 0 | Q_DECLARE_SHARED(QPainterPath) |
197 | 0 | Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE); |
198 | 0 |
|
199 | 0 | #ifndef QT_NO_DATASTREAM |
200 | 0 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); |
201 | 0 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); |
202 | 0 | #endif |
203 | 0 |
|
204 | 0 | class Q_GUI_EXPORT QPainterPathStroker |
205 | 0 | { |
206 | 0 | Q_DECLARE_PRIVATE(QPainterPathStroker) |
207 | 0 | public: |
208 | 0 | QPainterPathStroker(); |
209 | 0 | explicit QPainterPathStroker(const QPen &pen); |
210 | 0 | ~QPainterPathStroker(); |
211 | 0 |
|
212 | 0 | void setWidth(qreal width); |
213 | 0 | qreal width() const; |
214 | 0 |
|
215 | 0 | void setCapStyle(Qt::PenCapStyle style); |
216 | 0 | Qt::PenCapStyle capStyle() const; |
217 | 0 |
|
218 | 0 | void setJoinStyle(Qt::PenJoinStyle style); |
219 | 0 | Qt::PenJoinStyle joinStyle() const; |
220 | 0 |
|
221 | 0 | void setMiterLimit(qreal length); |
222 | 0 | qreal miterLimit() const; |
223 | 0 |
|
224 | 0 | void setCurveThreshold(qreal threshold); |
225 | 0 | qreal curveThreshold() const; |
226 | 0 |
|
227 | 0 | void setDashPattern(Qt::PenStyle); |
228 | 0 | void setDashPattern(const QList<qreal> &dashPattern); |
229 | 0 | QList<qreal> dashPattern() const; |
230 | 0 |
|
231 | 0 | void setDashOffset(qreal offset); |
232 | 0 | qreal dashOffset() const; |
233 | 0 |
|
234 | 0 | QPainterPath createStroke(const QPainterPath &path) const; |
235 | 0 |
|
236 | 0 | private: |
237 | 0 | Q_DISABLE_COPY(QPainterPathStroker) |
238 | 0 |
|
239 | 0 | friend class QX11PaintEngine; |
240 | 0 |
|
241 | 0 | QScopedPointer<QPainterPathStrokerPrivate> d_ptr; |
242 | 0 | }; |
243 | 0 |
|
244 | 0 | inline void QPainterPath::moveTo(qreal x, qreal y) |
245 | 1.89k | { |
246 | 1.89k | moveTo(QPointF(x, y)); |
247 | 1.89k | } |
248 | | |
249 | | inline void QPainterPath::lineTo(qreal x, qreal y) |
250 | 9.72k | { |
251 | 9.72k | lineTo(QPointF(x, y)); |
252 | 9.72k | } |
253 | | |
254 | | inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength) |
255 | 0 | { |
256 | 0 | arcTo(QRectF(x, y, w, h), startAngle, arcLength); |
257 | 0 | } |
258 | | |
259 | | inline void QPainterPath::arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle) |
260 | 0 | { |
261 | 0 | arcMoveTo(QRectF(x, y, w, h), angle); |
262 | 0 | } |
263 | | |
264 | | inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, |
265 | | qreal endPtx, qreal endPty) |
266 | 5.49k | { |
267 | 5.49k | cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y), |
268 | 5.49k | QPointF(endPtx, endPty)); |
269 | 5.49k | } |
270 | | |
271 | | inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) |
272 | 0 | { |
273 | 0 | quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty)); |
274 | 0 | } |
275 | | |
276 | | inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h) |
277 | 0 | { |
278 | 0 | addEllipse(QRectF(x, y, w, h)); |
279 | 0 | } |
280 | | |
281 | | inline void QPainterPath::addEllipse(const QPointF ¢er, qreal rx, qreal ry) |
282 | 0 | { |
283 | 0 | addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry)); |
284 | 0 | } |
285 | | |
286 | | inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h) |
287 | 0 | { |
288 | 0 | addRect(QRectF(x, y, w, h)); |
289 | 0 | } |
290 | | |
291 | | inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h, |
292 | | qreal xRadius, qreal yRadius, |
293 | | Qt::SizeMode mode) |
294 | 0 | { |
295 | 0 | addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode); |
296 | 0 | } |
297 | | |
298 | | inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text) |
299 | 0 | { |
300 | 0 | addText(QPointF(x, y), f, text); |
301 | 0 | } |
302 | | |
303 | | inline void QPainterPath::translate(const QPointF &offset) |
304 | 0 | { translate(offset.x(), offset.y()); } |
305 | | |
306 | | inline QPainterPath QPainterPath::translated(const QPointF &offset) const |
307 | 0 | { return translated(offset.x(), offset.y()); } |
308 | | |
309 | | inline QPainterPath operator *(const QPainterPath &p, const QTransform &m) |
310 | 0 | { return m.map(p); } |
311 | | |
312 | | #ifndef QT_NO_DEBUG_STREAM |
313 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &); |
314 | | #endif |
315 | | |
316 | | QT_END_NAMESPACE |
317 | | |
318 | | #endif // QPAINTERPATH_H |