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