Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtGui/qpainterpath.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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