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