Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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:
37
38 class Element {
39 public:
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);
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,
103 inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h,
104 qreal xRadius, qreal yRadius,
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 qreal length() const;
138 qreal percentAtLength(qreal t) const;
139 QPointF pointAtPercent(qreal t) const;
140 qreal angleAtPercent(qreal t) const;
141 qreal slopeAtPercent(qreal t) const;
142
143 bool intersects(const QPainterPath &p) const;
144 bool contains(const QPainterPath &p) const;
145 [[nodiscard]] QPainterPath united(const QPainterPath &r) const;
146 [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const;
147 [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const;
148
149 [[nodiscard]] QPainterPath simplified() const;
150
151 bool operator==(const QPainterPath &other) const;
152 bool operator!=(const QPainterPath &other) const;
153
158 QPainterPath &operator&=(const QPainterPath &other);
161 QPainterPath &operator-=(const QPainterPath &other);
162
163private:
164 QExplicitlySharedDataPointer<QPainterPathPrivate> d_ptr;
165
166 inline void ensureData() { if (!d_ptr) ensureData_helper(); }
167 void ensureData_helper();
168 void detach();
169 void setDirty(bool);
170 void computeBoundingRect() const;
171 void computeControlPointRect() const;
172
173 QPainterPathPrivate *d_func() const { return d_ptr.data(); }
174
177 friend class QTransform;
178 friend class QVectorPath;
179 friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &);
180
181#ifndef QT_NO_DATASTREAM
182 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
183 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
184#endif
185};
186
187Q_DECLARE_SHARED(QPainterPath)
189
190#ifndef QT_NO_DATASTREAM
191Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
193#endif
194
195class Q_GUI_EXPORT QPainterPathStroker
196{
197 Q_DECLARE_PRIVATE(QPainterPathStroker)
198public:
200 explicit QPainterPathStroker(const QPen &pen);
202
203 void setWidth(qreal width);
204 qreal width() const;
205
206 void setCapStyle(Qt::PenCapStyle style);
207 Qt::PenCapStyle capStyle() const;
208
209 void setJoinStyle(Qt::PenJoinStyle style);
210 Qt::PenJoinStyle joinStyle() const;
211
212 void setMiterLimit(qreal length);
213 qreal miterLimit() const;
214
215 void setCurveThreshold(qreal threshold);
216 qreal curveThreshold() const;
217
218 void setDashPattern(Qt::PenStyle);
219 void setDashPattern(const QList<qreal> &dashPattern);
220 QList<qreal> dashPattern() const;
221
222 void setDashOffset(qreal offset);
223 qreal dashOffset() const;
224
225 QPainterPath createStroke(const QPainterPath &path) const;
226
227private:
228 Q_DISABLE_COPY(QPainterPathStroker)
229
230 friend class QX11PaintEngine;
231
233};
234
235inline void QPainterPath::moveTo(qreal x, qreal y)
236{
237 moveTo(QPointF(x, y));
238}
239
241{
242 lineTo(QPointF(x, y));
243}
244
245inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
246{
247 arcTo(QRectF(x, y, w, h), startAngle, arcLength);
248}
249
251{
252 arcMoveTo(QRectF(x, y, w, h), angle);
253}
254
255inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
256 qreal endPtx, qreal endPty)
257{
258 cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
259 QPointF(endPtx, endPty));
260}
261
262inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
263{
264 quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
265}
266
268{
269 addEllipse(QRectF(x, y, w, h));
270}
271
272inline void QPainterPath::addEllipse(const QPointF &center, qreal rx, qreal ry)
273{
274 addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
275}
276
278{
279 addRect(QRectF(x, y, w, h));
280}
281
283 qreal xRadius, qreal yRadius,
285{
286 addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
287}
288
289inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
290{
291 addText(QPointF(x, y), f, text);
292}
293
295{ translate(offset.x(), offset.y()); }
296
298{ return translated(offset.x(), offset.y()); }
299
301{ return m.map(p); }
302
303#ifndef QT_NO_DEBUG_STREAM
304Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &);
305#endif
306
308
309#endif // QPAINTERPATH_H
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\reentrant
Definition qfont.h:22
The QPainterPathStroker class is used to generate fillable outlines for a given painter path.
\inmodule QtGui
bool isMoveTo() const
Returns true if the element is moving the current position, otherwise returns false.
bool isCurveTo() const
Returns true if the element is a curve, otherwise returns false.
bool operator==(const Element &e) const
\variable QPainterPath::Element::x
bool operator!=(const Element &e) const
bool isLineTo() const
Returns true if the element is a line, otherwise returns false.
\inmodule QtGui
void quadTo(const QPointF &ctrlPt, const QPointF &endPt)
Adds a quadratic Bezier curve between the current position and the given endPoint with the control po...
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
void addText(const QPointF &point, const QFont &f, const QString &text)
Adds the given text to this path as a set of closed subpaths created from the font supplied.
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void swap(QPainterPath &other) noexcept
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
void arcMoveTo(const QRectF &rect, qreal angle)
\inmodule QtGui
Definition qpen.h:28
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
\inmodule QtCore\reentrant
Definition qrect.h:484
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
b clear()
QString text
set reserve(20000)
rect
[4]
Combined button and popup list for selecting options.
@ AbsoluteSize
PenJoinStyle
PenCapStyle
constexpr bool operator!=(const timespec &t1, const timespec &t2)
constexpr timespec operator+(const timespec &t1, const timespec &t2)
constexpr timespec operator*(const timespec &t1, int mul)
constexpr timespec & operator+=(timespec &t1, const timespec &t2)
constexpr timespec operator-(const timespec &t1, const timespec &t2)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
NSUInteger capacity
constexpr QKeyCombination operator|(Qt::Modifier modifier, Qt::Key key) noexcept
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLint GLint GLint GLint GLint x
[0]
GLenum mode
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat f
GLint GLsizei width
GLenum type
GLfloat angle
GLenum GLuint GLintptr offset
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum matrix
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
static const QRectF boundingRect(const QPointF *points, int pointCount)
static void setCapStyle(int cap_style, GC gc)
const QVectorPath & qtVectorPathForPath(const QPainterPath &path)
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QPainterPath &)
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QPainterPath &)
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
static bool operator&(QSortFilterProxyModelPrivate::Direction a, QSortFilterProxyModelPrivate::Direction b)
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
double qreal
Definition qtypes.h:187
QUrl::FormattingOptions & operator|=(QUrl::FormattingOptions &i, QUrl::ComponentFormattingOptions f)
Definition qurl.h:301
#define explicit
static bool translate(xcb_connection_t *connection, xcb_window_t child, xcb_window_t parent, int *x, int *y)
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDataStream & operator>>(QDataStream &in, MyClass &myObj)
p ry()++
p rx()++
QSharedPointer< T > other(t)
[5]
this swap(other)
scene addText("Hello, world!")
scene addRect(QRectF(-10, -10, 20, 20))