Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpainterpath.h
Go to the documentation of this file.
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#include <QtCore/qglobal.h>
10#include <QtCore/qline.h>
11#include <QtCore/qlist.h>
12#include <QtCore/qrect.h>
13#include <QtCore/qshareddata.h>
14
16
17
18class QFont;
20struct QPainterPathPrivateDeleter;
22class QPen;
23class QPolygonF;
24class QRegion;
25class QTransform;
26class QVectorPath;
27
28class Q_GUI_EXPORT QPainterPath
29{
30public:
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 bool isMoveTo() const { return type == MoveToElement; }
45 bool isLineTo() const { return type == LineToElement; }
46 bool isCurveTo() const { return type == CurveToElement; }
47
48 operator QPointF () const { return QPointF(x, y); }
49
50 bool operator==(const Element &e) const { return qFuzzyCompare(x, e.x)
51 && qFuzzyCompare(y, e.y) && type == e.type; }
52 inline bool operator!=(const Element &e) const { return !operator==(e); }
53 };
54
55 QPainterPath() noexcept;
56 explicit QPainterPath(const QPointF &startPoint);
57 QPainterPath(const QPainterPath &other);
58 QPainterPath &operator=(const QPainterPath &other);
59 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath)
60 ~QPainterPath();
61
62 inline void swap(QPainterPath &other) noexcept { d_ptr.swap(other.d_ptr); }
63
64 void clear();
65 void reserve(int size);
66 int capacity() const;
67
68 void closeSubpath();
69
70 void moveTo(const QPointF &p);
71 inline void moveTo(qreal x, qreal y);
72
73 void lineTo(const QPointF &p);
74 inline void lineTo(qreal x, qreal y);
75
76 void arcMoveTo(const QRectF &rect, qreal angle);
77 inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle);
78
79 void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength);
80 inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength);
81
82 void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
83 inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
84 qreal endPtx, qreal endPty);
85 void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
86 inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty);
87
88 QPointF currentPosition() const;
89
90 void addRect(const QRectF &rect);
91 inline void addRect(qreal x, qreal y, qreal w, qreal h);
92 void addEllipse(const QRectF &rect);
93 inline void addEllipse(qreal x, qreal y, qreal w, qreal h);
94 inline void addEllipse(const QPointF &center, qreal rx, qreal ry);
95 void addPolygon(const QPolygonF &polygon);
96 void addText(const QPointF &point, const QFont &f, const QString &text);
97 inline void addText(qreal x, qreal y, const QFont &f, const QString &text);
98 void addPath(const QPainterPath &path);
99 void addRegion(const QRegion &region);
100
101 void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
102 Qt::SizeMode mode = Qt::AbsoluteSize);
103 inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h,
104 qreal xRadius, qreal yRadius,
105 Qt::SizeMode mode = Qt::AbsoluteSize);
106
107 void connectPath(const QPainterPath &path);
108
109 bool contains(const QPointF &pt) const;
110 bool contains(const QRectF &rect) const;
111 bool intersects(const QRectF &rect) const;
112
113 void translate(qreal dx, qreal dy);
114 inline void translate(const QPointF &offset);
115
116 [[nodiscard]] QPainterPath translated(qreal dx, qreal dy) const;
117 [[nodiscard]] inline QPainterPath translated(const QPointF &offset) const;
118
119 QRectF boundingRect() const;
120 QRectF controlPointRect() const;
121
122 Qt::FillRule fillRule() const;
123 void setFillRule(Qt::FillRule fillRule);
124
125 bool isEmpty() const;
126
127 [[nodiscard]] QPainterPath toReversed() const;
128
129 QList<QPolygonF> toSubpathPolygons(const QTransform &matrix = QTransform()) const;
130 QList<QPolygonF> toFillPolygons(const QTransform &matrix = QTransform()) const;
131 QPolygonF toFillPolygon(const QTransform &matrix = QTransform()) const;
132
133 int elementCount() const;
134 QPainterPath::Element elementAt(int i) const;
135 void setElementPositionAt(int i, qreal x, qreal y);
136
137 bool isCachingEnabled() const;
138 void setCachingEnabled(bool enabled);
139 qreal length() const;
140 qreal percentAtLength(qreal len) const;
141 QPointF pointAtPercent(qreal t) const;
142 qreal angleAtPercent(qreal t) const;
143 qreal slopeAtPercent(qreal t) const;
144 [[nodiscard]] QPainterPath trimmed(qreal f1, qreal f2, qreal offset = 0) const;
145
146 bool intersects(const QPainterPath &p) const;
147 bool contains(const QPainterPath &p) const;
148 [[nodiscard]] QPainterPath united(const QPainterPath &r) const;
149 [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const;
150 [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const;
151
152 [[nodiscard]] QPainterPath simplified() const;
153
154 bool operator==(const QPainterPath &other) const;
155 bool operator!=(const QPainterPath &other) const;
156
157 QPainterPath operator&(const QPainterPath &other) const;
158 QPainterPath operator|(const QPainterPath &other) const;
159 QPainterPath operator+(const QPainterPath &other) const;
160 QPainterPath operator-(const QPainterPath &other) const;
161 QPainterPath &operator&=(const QPainterPath &other);
162 QPainterPath &operator|=(const QPainterPath &other);
163 QPainterPath &operator+=(const QPainterPath &other);
164 QPainterPath &operator-=(const QPainterPath &other);
165
166private:
167 QExplicitlySharedDataPointer<QPainterPathPrivate> d_ptr;
168
169 inline void ensureData() { if (!d_ptr) ensureData_helper(); }
170 void ensureData_helper();
171 void detach();
172 void setDirty(bool);
173 void computeBoundingRect() const;
174 void computeControlPointRect() const;
175
176 QPainterPathPrivate *d_func() const { return d_ptr.data(); }
177
178 friend class QPainterPathStroker;
179 friend class QPainterPathStrokerPrivate;
180 friend class QPainterPathPrivate;
181 friend class QTransform;
182 friend class QVectorPath;
183 friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &);
184
185#ifndef QT_NO_DATASTREAM
186 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
187 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
188#endif
189};
190
192Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE);
193
194#ifndef QT_NO_DATASTREAM
195Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
196Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
197#endif
198
199class Q_GUI_EXPORT QPainterPathStroker
200{
201 Q_DECLARE_PRIVATE(QPainterPathStroker)
202public:
203 QPainterPathStroker();
204 explicit QPainterPathStroker(const QPen &pen);
205 ~QPainterPathStroker();
206
207 void setWidth(qreal width);
208 qreal width() const;
209
210 void setCapStyle(Qt::PenCapStyle style);
211 Qt::PenCapStyle capStyle() const;
212
213 void setJoinStyle(Qt::PenJoinStyle style);
214 Qt::PenJoinStyle joinStyle() const;
215
216 void setMiterLimit(qreal length);
217 qreal miterLimit() const;
218
219 void setCurveThreshold(qreal threshold);
220 qreal curveThreshold() const;
221
223 void setDashPattern(const QList<qreal> &dashPattern);
224 QList<qreal> dashPattern() const;
225
226 void setDashOffset(qreal offset);
227 qreal dashOffset() const;
228
229 QPainterPath createStroke(const QPainterPath &path) const;
230
231private:
232 Q_DISABLE_COPY(QPainterPathStroker)
233
234 friend class QX11PaintEngine;
235
237};
238
239inline void QPainterPath::moveTo(qreal x, qreal y)
240{
241 moveTo(QPointF(x, y));
242}
243
244inline void QPainterPath::lineTo(qreal x, qreal y)
245{
246 lineTo(QPointF(x, y));
247}
248
249inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
250{
251 arcTo(QRectF(x, y, w, h), startAngle, arcLength);
252}
253
254inline void QPainterPath::arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle)
255{
256 arcMoveTo(QRectF(x, y, w, h), angle);
257}
258
259inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
260 qreal endPtx, qreal endPty)
261{
262 cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
263 QPointF(endPtx, endPty));
264}
265
266inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
267{
268 quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
269}
270
271inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h)
272{
273 addEllipse(QRectF(x, y, w, h));
274}
275
276inline void QPainterPath::addEllipse(const QPointF &center, qreal rx, qreal ry)
277{
278 addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
279}
280
281inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h)
282{
283 addRect(QRectF(x, y, w, h));
284}
285
286inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h,
287 qreal xRadius, qreal yRadius,
288 Qt::SizeMode mode)
289{
290 addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
291}
292
293inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
294{
295 addText(QPointF(x, y), f, text);
296}
297
298inline void QPainterPath::translate(const QPointF &offset)
299{ translate(offset.x(), offset.y()); }
300
301inline QPainterPath QPainterPath::translated(const QPointF &offset) const
302{ return translated(offset.x(), offset.y()); }
303
304inline QPainterPath operator *(const QPainterPath &p, const QTransform &m)
305{ return m.map(p); }
306
307#ifndef QT_NO_DEBUG_STREAM
308Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &);
309#endif
310
311QT_END_NAMESPACE
312
313#endif // QPAINTERPATH_H
\inmodule QtCore\reentrant
Definition qdatastream.h:49
QPaintEngine * paintEngine() const override
Definition qpicture.cpp:374
void setDpiY(int dpi)
Definition qpicture.cpp:373
int metric(PaintDeviceMetric m) const override
Definition qpicture.cpp:375
void setDpiX(int dpi)
Definition qpicture.cpp:372
QScopedPointer< QImageIOHandlerPrivate > d_ptr
The QPainterPathStroker class is used to generate fillable outlines for a given painter path.
void setCurveThreshold(qreal threshold)
Specifies the curve flattening threshold, controlling the granularity with which the generated outlin...
Qt::PenJoinStyle joinStyle() const
Returns the join style of the generated outlines.
QList< qreal > dashPattern() const
Returns the dash pattern for the generated outlines.
QPainterPathStroker(const QPen &pen)
Creates a new stroker based on pen.
void setDashPattern(Qt::PenStyle)
Sets the dash pattern for the generated outlines to style.
qreal miterLimit() const
Returns the miter limit for the generated outlines.
qreal curveThreshold() const
Returns the curve flattening threshold for the generated outlines.
Qt::PenCapStyle capStyle() const
Returns the cap style of the generated outlines.
void setDashPattern(const QList< qreal > &dashPattern)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qreal width() const
Returns the width of the generated outlines.
void setDashOffset(qreal offset)
Sets the dash offset for the generated outlines to offset.
void setCapStyle(Qt::PenCapStyle style)
Sets the cap style of the generated outlines to style.
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style of the generated outlines to style.
qreal dashOffset() const
Returns the dash offset for the generated outlines.
void setMiterLimit(qreal length)
Sets the miter limit of the generated outlines to limit.
\inmodule QtGui
friend class QPaintEngine
Definition qpainter.h:429
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2462
QPainterPath operator*(const QPainterPath &p, const QTransform &m)
static const quint16 mfhdr_maj
Definition qpicture.cpp:84
QT_BEGIN_NAMESPACE void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QTextOption *opt, const QString &str, QRectF *brect, int tabstops, int *, int tabarraylen, QPainter *painter)
static const quint16 mfhdr_min
Definition qpicture.cpp:85
const char * qt_mfhdr_tag
Definition qpicture.cpp:83