File indexing completed on 2026-01-06 10:22:20
0001
0002
0003
0004 #ifndef QPAINTERPATH_H
0005 #define QPAINTERPATH_H
0006
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtGui/qtransform.h>
0009 #include <QtCore/qglobal.h>
0010 #include <QtCore/qline.h>
0011 #include <QtCore/qlist.h>
0012 #include <QtCore/qrect.h>
0013
0014 QT_BEGIN_NAMESPACE
0015
0016
0017 class QFont;
0018 class QPainterPathPrivate;
0019 class QPainterPathStrokerPrivate;
0020 class QPen;
0021 class QPolygonF;
0022 class QRegion;
0023 class QTransform;
0024 class QVectorPath;
0025
0026 class Q_GUI_EXPORT QPainterPath
0027 {
0028 public:
0029 enum ElementType {
0030 MoveToElement,
0031 LineToElement,
0032 CurveToElement,
0033 CurveToDataElement
0034 };
0035
0036 class Element {
0037 public:
0038 qreal x;
0039 qreal y;
0040 ElementType type;
0041
0042 bool isMoveTo() const { return type == MoveToElement; }
0043 bool isLineTo() const { return type == LineToElement; }
0044 bool isCurveTo() const { return type == CurveToElement; }
0045
0046 operator QPointF () const { return QPointF(x, y); }
0047
0048 bool operator==(const Element &e) const { return qFuzzyCompare(x, e.x)
0049 && qFuzzyCompare(y, e.y) && type == e.type; }
0050 inline bool operator!=(const Element &e) const { return !operator==(e); }
0051 };
0052
0053 QPainterPath() noexcept;
0054 explicit QPainterPath(const QPointF &startPoint);
0055 QPainterPath(const QPainterPath &other);
0056 QPainterPath &operator=(const QPainterPath &other);
0057 QPainterPath(QPainterPath &&other) noexcept
0058 : d_ptr(std::exchange(other.d_ptr, nullptr))
0059 {}
0060 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath)
0061 ~QPainterPath();
0062
0063 inline void swap(QPainterPath &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
0064
0065 void clear();
0066 void reserve(int size);
0067 int capacity() const;
0068
0069 void closeSubpath();
0070
0071 void moveTo(const QPointF &p);
0072 inline void moveTo(qreal x, qreal y);
0073
0074 void lineTo(const QPointF &p);
0075 inline void lineTo(qreal x, qreal y);
0076
0077 void arcMoveTo(const QRectF &rect, qreal angle);
0078 inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle);
0079
0080 void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength);
0081 inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength);
0082
0083 void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
0084 inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
0085 qreal endPtx, qreal endPty);
0086 void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
0087 inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty);
0088
0089 QPointF currentPosition() const;
0090
0091 void addRect(const QRectF &rect);
0092 inline void addRect(qreal x, qreal y, qreal w, qreal h);
0093 void addEllipse(const QRectF &rect);
0094 inline void addEllipse(qreal x, qreal y, qreal w, qreal h);
0095 inline void addEllipse(const QPointF ¢er, qreal rx, qreal ry);
0096 void addPolygon(const QPolygonF &polygon);
0097 void addText(const QPointF &point, const QFont &f, const QString &text);
0098 inline void addText(qreal x, qreal y, const QFont &f, const QString &text);
0099 void addPath(const QPainterPath &path);
0100 void addRegion(const QRegion ®ion);
0101
0102 void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
0103 Qt::SizeMode mode = Qt::AbsoluteSize);
0104 inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h,
0105 qreal xRadius, qreal yRadius,
0106 Qt::SizeMode mode = Qt::AbsoluteSize);
0107
0108 void connectPath(const QPainterPath &path);
0109
0110 bool contains(const QPointF &pt) const;
0111 bool contains(const QRectF &rect) const;
0112 bool intersects(const QRectF &rect) const;
0113
0114 void translate(qreal dx, qreal dy);
0115 inline void translate(const QPointF &offset);
0116
0117 [[nodiscard]] QPainterPath translated(qreal dx, qreal dy) const;
0118 [[nodiscard]] inline QPainterPath translated(const QPointF &offset) const;
0119
0120 QRectF boundingRect() const;
0121 QRectF controlPointRect() const;
0122
0123 Qt::FillRule fillRule() const;
0124 void setFillRule(Qt::FillRule fillRule);
0125
0126 bool isEmpty() const;
0127
0128 [[nodiscard]] QPainterPath toReversed() const;
0129
0130 QList<QPolygonF> toSubpathPolygons(const QTransform &matrix = QTransform()) const;
0131 QList<QPolygonF> toFillPolygons(const QTransform &matrix = QTransform()) const;
0132 QPolygonF toFillPolygon(const QTransform &matrix = QTransform()) const;
0133
0134 int elementCount() const;
0135 QPainterPath::Element elementAt(int i) const;
0136 void setElementPositionAt(int i, qreal x, qreal y);
0137
0138 bool isCachingEnabled() const;
0139 void setCachingEnabled(bool enabled);
0140 qreal length() const;
0141 qreal percentAtLength(qreal len) const;
0142 QPointF pointAtPercent(qreal t) const;
0143 qreal angleAtPercent(qreal t) const;
0144 qreal slopeAtPercent(qreal t) const;
0145 [[nodiscard]] QPainterPath trimmed(qreal fromFraction, qreal toFraction, qreal offset = 0) const;
0146
0147 bool intersects(const QPainterPath &p) const;
0148 bool contains(const QPainterPath &p) const;
0149 [[nodiscard]] QPainterPath united(const QPainterPath &r) const;
0150 [[nodiscard]] QPainterPath intersected(const QPainterPath &r) const;
0151 [[nodiscard]] QPainterPath subtracted(const QPainterPath &r) const;
0152
0153 [[nodiscard]] QPainterPath simplified() const;
0154
0155 bool operator==(const QPainterPath &other) const;
0156 bool operator!=(const QPainterPath &other) const;
0157
0158 QPainterPath operator&(const QPainterPath &other) const;
0159 QPainterPath operator|(const QPainterPath &other) const;
0160 QPainterPath operator+(const QPainterPath &other) const;
0161 QPainterPath operator-(const QPainterPath &other) const;
0162 QPainterPath &operator&=(const QPainterPath &other);
0163 QPainterPath &operator|=(const QPainterPath &other);
0164 QPainterPath &operator+=(const QPainterPath &other);
0165 QPainterPath &operator-=(const QPainterPath &other);
0166
0167 private:
0168 QPainterPathPrivate *d_ptr;
0169
0170 inline void ensureData() { if (!d_ptr) ensureData_helper(); }
0171 void ensureData_helper();
0172 void setDirty(bool);
0173 void computeBoundingRect() const;
0174 void computeControlPointRect() const;
0175
0176 QPainterPathPrivate *d_func() const { return d_ptr; }
0177
0178 friend class QPainterPathStroker;
0179 friend class QPainterPathStrokerPrivate;
0180 friend class QPainterPathPrivate;
0181 friend class QTransform;
0182 friend class QVectorPath;
0183 friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &);
0184
0185 #ifndef QT_NO_DATASTREAM
0186 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
0187 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
0188 #endif
0189 };
0190
0191 Q_DECLARE_SHARED(QPainterPath)
0192 Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE);
0193
0194 #ifndef QT_NO_DATASTREAM
0195 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
0196 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
0197 #endif
0198
0199 class Q_GUI_EXPORT QPainterPathStroker
0200 {
0201 Q_DECLARE_PRIVATE(QPainterPathStroker)
0202 public:
0203 QPainterPathStroker();
0204 explicit QPainterPathStroker(const QPen &pen);
0205 ~QPainterPathStroker();
0206
0207 void setWidth(qreal width);
0208 qreal width() const;
0209
0210 void setCapStyle(Qt::PenCapStyle style);
0211 Qt::PenCapStyle capStyle() const;
0212
0213 void setJoinStyle(Qt::PenJoinStyle style);
0214 Qt::PenJoinStyle joinStyle() const;
0215
0216 void setMiterLimit(qreal length);
0217 qreal miterLimit() const;
0218
0219 void setCurveThreshold(qreal threshold);
0220 qreal curveThreshold() const;
0221
0222 void setDashPattern(Qt::PenStyle);
0223 void setDashPattern(const QList<qreal> &dashPattern);
0224 QList<qreal> dashPattern() const;
0225
0226 void setDashOffset(qreal offset);
0227 qreal dashOffset() const;
0228
0229 QPainterPath createStroke(const QPainterPath &path) const;
0230
0231 private:
0232 Q_DISABLE_COPY(QPainterPathStroker)
0233
0234 friend class QX11PaintEngine;
0235
0236 QScopedPointer<QPainterPathStrokerPrivate> d_ptr;
0237 };
0238
0239 inline void QPainterPath::moveTo(qreal x, qreal y)
0240 {
0241 moveTo(QPointF(x, y));
0242 }
0243
0244 inline void QPainterPath::lineTo(qreal x, qreal y)
0245 {
0246 lineTo(QPointF(x, y));
0247 }
0248
0249 inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
0250 {
0251 arcTo(QRectF(x, y, w, h), startAngle, arcLength);
0252 }
0253
0254 inline void QPainterPath::arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle)
0255 {
0256 arcMoveTo(QRectF(x, y, w, h), angle);
0257 }
0258
0259 inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
0260 qreal endPtx, qreal endPty)
0261 {
0262 cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
0263 QPointF(endPtx, endPty));
0264 }
0265
0266 inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
0267 {
0268 quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
0269 }
0270
0271 inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h)
0272 {
0273 addEllipse(QRectF(x, y, w, h));
0274 }
0275
0276 inline void QPainterPath::addEllipse(const QPointF ¢er, qreal rx, qreal ry)
0277 {
0278 addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
0279 }
0280
0281 inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h)
0282 {
0283 addRect(QRectF(x, y, w, h));
0284 }
0285
0286 inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h,
0287 qreal xRadius, qreal yRadius,
0288 Qt::SizeMode mode)
0289 {
0290 addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
0291 }
0292
0293 inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
0294 {
0295 addText(QPointF(x, y), f, text);
0296 }
0297
0298 inline void QPainterPath::translate(const QPointF &offset)
0299 { translate(offset.x(), offset.y()); }
0300
0301 inline QPainterPath QPainterPath::translated(const QPointF &offset) const
0302 { return translated(offset.x(), offset.y()); }
0303
0304 inline QPainterPath operator *(const QPainterPath &p, const QTransform &m)
0305 { return m.map(p); }
0306
0307 #ifndef QT_NO_DEBUG_STREAM
0308 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &);
0309 #endif
0310
0311 QT_END_NAMESPACE
0312
0313 #endif