Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:08:15

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