QtBase  v6.3.1
qpainterpath.h
Go to the documentation of this file.
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/qtransform.h>
45 #include <QtCore/qglobal.h>
46 #include <QtCore/qline.h>
47 #include <QtCore/qlist.h>
48 #include <QtCore/qrect.h>
49 #include <QtCore/qshareddata.h>
50 
52 
53 
54 class QFont;
56 struct QPainterPathPrivateDeleter;
58 class QPen;
59 class QPolygonF;
60 class QRegion;
61 class QTransform;
62 class QVectorPath;
63 
64 class Q_GUI_EXPORT QPainterPath
65 {
66 public:
67  enum ElementType {
71  CurveToDataElement
72  };
73 
74  class Element {
75  public:
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() noexcept;
92  explicit QPainterPath(const QPointF &startPoint);
94  QPainterPath &operator=(const QPainterPath &other);
96  ~QPainterPath();
97 
98  inline void swap(QPainterPath &other) noexcept { d_ptr.swap(other.d_ptr); }
99 
100  void clear();
101  void reserve(int size);
102  int capacity() const;
103 
104  void closeSubpath();
105 
106  void moveTo(const QPointF &p);
107  inline void moveTo(qreal x, qreal y);
108 
109  void lineTo(const QPointF &p);
110  inline void lineTo(qreal x, qreal y);
111 
112  void arcMoveTo(const QRectF &rect, qreal angle);
113  inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle);
114 
115  void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength);
116  inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength);
117 
118  void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
119  inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
120  qreal endPtx, qreal endPty);
121  void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
122  inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty);
123 
124  QPointF currentPosition() const;
125 
126  void addRect(const QRectF &rect);
127  inline void addRect(qreal x, qreal y, qreal w, qreal h);
128  void addEllipse(const QRectF &rect);
129  inline void addEllipse(qreal x, qreal y, qreal w, qreal h);
130  inline void addEllipse(const QPointF &center, qreal rx, qreal ry);
131  void addPolygon(const QPolygonF &polygon);
132  void addText(const QPointF &point, const QFont &f, const QString &text);
133  inline void addText(qreal x, qreal y, const QFont &f, const QString &text);
134  void addPath(const QPainterPath &path);
135  void addRegion(const QRegion &region);
136 
137  void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
139  inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h,
140  qreal xRadius, qreal yRadius,
142 
143  void connectPath(const QPainterPath &path);
144 
145  bool contains(const QPointF &pt) const;
146  bool contains(const QRectF &rect) const;
147  bool intersects(const QRectF &rect) const;
148 
149  void translate(qreal dx, qreal dy);
150  inline void translate(const QPointF &offset);
151 
152  [[nodiscard]] QPainterPath translated(qreal dx, qreal dy) const;
153  [[nodiscard]] inline QPainterPath translated(const QPointF &offset) const;
154 
155  QRectF boundingRect() const;
156  QRectF controlPointRect() const;
157 
158  Qt::FillRule fillRule() const;
159  void setFillRule(Qt::FillRule fillRule);
160 
161  bool isEmpty() const;
162 
163  [[nodiscard]] QPainterPath toReversed() const;
164 
165  QList<QPolygonF> toSubpathPolygons(const QTransform &matrix = QTransform()) const;
166  QList<QPolygonF> toFillPolygons(const QTransform &matrix = QTransform()) const;
167  QPolygonF toFillPolygon(const QTransform &matrix = QTransform()) const;
168 
169  int elementCount() const;
170  QPainterPath::Element elementAt(int i) const;
171  void setElementPositionAt(int i, qreal x, qreal y);
172 
173  qreal length() const;
174  qreal percentAtLength(qreal t) const;
175  QPointF pointAtPercent(qreal t) const;
176  qreal angleAtPercent(qreal t) const;
177  qreal slopeAtPercent(qreal t) const;
178 
179  bool intersects(const QPainterPath &p) const;
180  bool contains(const QPainterPath &p) const;
181  [[nodiscard]] QPainterPath united(const QPainterPath &r) const;
182  [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const;
183  [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const;
184 
185  [[nodiscard]] QPainterPath simplified() const;
186 
187  bool operator==(const QPainterPath &other) const;
188  bool operator!=(const QPainterPath &other) const;
189 
194  QPainterPath &operator&=(const QPainterPath &other);
197  QPainterPath &operator-=(const QPainterPath &other);
198 
199 private:
201 
202  inline void ensureData() { if (!d_ptr) ensureData_helper(); }
203  void ensureData_helper();
204  void detach();
205  void setDirty(bool);
206  void computeBoundingRect() const;
207  void computeControlPointRect() const;
208 
209  QPainterPathPrivate *d_func() const { return d_ptr.data(); }
210 
211  friend class QPainterPathStroker;
213  friend class QTransform;
214  friend class QVectorPath;
215  friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &);
216 
217 #ifndef QT_NO_DATASTREAM
218  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
219  friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
220 #endif
221 };
222 
225 
226 #ifndef QT_NO_DATASTREAM
227 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
228 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
229 #endif
230 
231 class Q_GUI_EXPORT QPainterPathStroker
232 {
233  Q_DECLARE_PRIVATE(QPainterPathStroker)
234 public:
236  explicit QPainterPathStroker(const QPen &pen);
238 
239  void setWidth(qreal width);
240  qreal width() const;
241 
242  void setCapStyle(Qt::PenCapStyle style);
243  Qt::PenCapStyle capStyle() const;
244 
245  void setJoinStyle(Qt::PenJoinStyle style);
246  Qt::PenJoinStyle joinStyle() const;
247 
248  void setMiterLimit(qreal length);
249  qreal miterLimit() const;
250 
251  void setCurveThreshold(qreal threshold);
252  qreal curveThreshold() const;
253 
254  void setDashPattern(Qt::PenStyle);
255  void setDashPattern(const QList<qreal> &dashPattern);
256  QList<qreal> dashPattern() const;
257 
258  void setDashOffset(qreal offset);
259  qreal dashOffset() const;
260 
261  QPainterPath createStroke(const QPainterPath &path) const;
262 
263 private:
265 
266  friend class QX11PaintEngine;
267 
269 };
270 
272 {
273  moveTo(QPointF(x, y));
274 }
275 
277 {
278  lineTo(QPointF(x, y));
279 }
280 
281 inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
282 {
283  arcTo(QRectF(x, y, w, h), startAngle, arcLength);
284 }
285 
287 {
288  arcMoveTo(QRectF(x, y, w, h), angle);
289 }
290 
291 inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
292  qreal endPtx, qreal endPty)
293 {
294  cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
295  QPointF(endPtx, endPty));
296 }
297 
298 inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
299 {
300  quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
301 }
302 
304 {
305  addEllipse(QRectF(x, y, w, h));
306 }
307 
309 {
310  addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
311 }
312 
314 {
315  addRect(QRectF(x, y, w, h));
316 }
317 
319  qreal xRadius, qreal yRadius,
321 {
322  addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
323 }
324 
325 inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
326 {
327  addText(QPointF(x, y), f, text);
328 }
329 
331 { translate(offset.x(), offset.y()); }
332 
334 { return translated(offset.x(), offset.y()); }
335 
337 { return m.map(p); }
338 
339 #ifndef QT_NO_DEBUG_STREAM
340 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &);
341 #endif
342 
344 
345 #endif // QPAINTERPATH_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
Arabic default style
Definition: afstyles.h:94
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
T * data() const noexcept
Definition: qshareddata.h:171
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
Definition: qlist.h:108
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:74
bool isMoveTo() const
Definition: qpainterpath.h:80
bool isCurveTo() const
Definition: qpainterpath.h:82
bool operator==(const Element &e) const
the x coordinate of the element's position.
Definition: qpainterpath.h:86
bool operator!=(const Element &e) const
Definition: qpainterpath.h:88
bool isLineTo() const
Definition: qpainterpath.h:81
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
void quadTo(const QPointF &ctrlPt, const QPointF &endPt)
QPainterPath translated(qreal dx, qreal dy) const
void translate(qreal dx, qreal dy)
void addRect(const QRectF &rect)
void addEllipse(const QRectF &rect)
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
void addText(const QPointF &point, const QFont &f, const QString &text)
void lineTo(const QPointF &p)
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
void arcMoveTo(const QRectF &rect, qreal angle)
The QPainterPathStroker class is used to generate fillable outlines for a given painter path.
Definition: qpainterpath.h:232
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:61
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPolygonF class provides a list of points using floating point precision. \inmodule QtGui.
Definition: qpolygon.h:128
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
float rx
b clear()
double e
set reserve(20000)
set contains("Julia")
rect
[4]
auto it unsigned count const
Definition: hb-iter.hh:848
#define inline
Definition: md4c.c:45
SizeMode
Definition: qnamespace.h:1161
@ AbsoluteSize
Definition: qnamespace.h:1162
PenStyle
Definition: qnamespace.h:1111
PenJoinStyle
Definition: qnamespace.h:1131
FillRule
Definition: qnamespace.h:1320
QTextStream & center(QTextStream &stream)
PenCapStyle
Definition: qnamespace.h:1124
QString operator+(const ProString &one, const ProString &two)
Definition: proitems.cpp:281
QString & operator+=(QString &that, const ProString &other)
Definition: proitems.h:262
Q_CORE_EXPORT QBitArray operator&(const QBitArray &, const QBitArray &)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
Definition: qcore_unix_p.h:124
constexpr timespec operator-(const timespec &t1, const timespec &t2)
Definition: qcore_unix_p.h:139
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition: qfloat16.h:233
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
@ text
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
constexpr QKeyCombination operator|(Qt::Modifier modifier, Qt::Key key) noexcept
Definition: qnamespace.h:1932
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLenum type
Definition: qopengl.h:270
GLint GLint GLint GLint GLint x
[0]
GLenum mode
const GLfloat * m
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLint GLsizei width
GLfloat angle
GLenum GLuint GLintptr offset
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum matrix
Definition: qopenglext.h:11564
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
const QVectorPath & qtVectorPathForPath(const QPainterPath &path)
QPainterPath operator*(const QPainterPath &p, const QTransform &m)
Definition: qpainterpath.h:336
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QPainterPath &)
Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE)
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QPainterPath &)
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
@ Q_PRIMITIVE_TYPE
Definition: qtypeinfo.h:155
QUrl::FormattingOptions & operator|=(QUrl::FormattingOptions &i, QUrl::ComponentFormattingOptions f)
Definition: qurl.h:327
#define explicit
p ry()++
QSharedPointer< T > other(t)
[5]
this swap(other)
scene addText("Hello, world!")
scene addRect(QRectF(-10, -10, 20, 20))