| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QPAINTERPATH_H
|
|---|
| 43 | #define QPAINTERPATH_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui/qmatrix.h>
|
|---|
| 46 | #include <QtCore/qglobal.h>
|
|---|
| 47 | #include <QtCore/qrect.h>
|
|---|
| 48 | #include <QtCore/qline.h>
|
|---|
| 49 | #include <QtCore/qvector.h>
|
|---|
| 50 | #include <QtCore/qscopedpointer.h>
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_HEADER
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_NAMESPACE
|
|---|
| 55 |
|
|---|
| 56 | QT_MODULE(Gui)
|
|---|
| 57 |
|
|---|
| 58 | class QFont;
|
|---|
| 59 | class QPainterPathPrivate;
|
|---|
| 60 | struct QPainterPathPrivateDeleter;
|
|---|
| 61 | class QPainterPathData;
|
|---|
| 62 | class QPainterPathStrokerPrivate;
|
|---|
| 63 | class QPolygonF;
|
|---|
| 64 | class QRegion;
|
|---|
| 65 | class QVectorPath;
|
|---|
| 66 |
|
|---|
| 67 | class Q_GUI_EXPORT QPainterPath
|
|---|
| 68 | {
|
|---|
| 69 | public:
|
|---|
| 70 | enum ElementType {
|
|---|
| 71 | MoveToElement,
|
|---|
| 72 | LineToElement,
|
|---|
| 73 | CurveToElement,
|
|---|
| 74 | CurveToDataElement
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | class Element {
|
|---|
| 78 | public:
|
|---|
| 79 | qreal x;
|
|---|
| 80 | qreal y;
|
|---|
| 81 | ElementType type;
|
|---|
| 82 |
|
|---|
| 83 | bool isMoveTo() const { return type == MoveToElement; }
|
|---|
| 84 | bool isLineTo() const { return type == LineToElement; }
|
|---|
| 85 | bool isCurveTo() const { return type == CurveToElement; }
|
|---|
| 86 |
|
|---|
| 87 | operator QPointF () const { return QPointF(x, y); }
|
|---|
| 88 |
|
|---|
| 89 | bool operator==(const Element &e) const { return qFuzzyCompare(x, e.x)
|
|---|
| 90 | && qFuzzyCompare(y, e.y) && type == e.type; }
|
|---|
| 91 | inline bool operator!=(const Element &e) const { return !operator==(e); }
|
|---|
| 92 | };
|
|---|
| 93 |
|
|---|
| 94 | QPainterPath();
|
|---|
| 95 | explicit QPainterPath(const QPointF &startPoint);
|
|---|
| 96 | QPainterPath(const QPainterPath &other);
|
|---|
| 97 | QPainterPath &operator=(const QPainterPath &other);
|
|---|
| 98 | ~QPainterPath();
|
|---|
| 99 |
|
|---|
| 100 | void closeSubpath();
|
|---|
| 101 |
|
|---|
| 102 | void moveTo(const QPointF &p);
|
|---|
| 103 | inline void moveTo(qreal x, qreal y);
|
|---|
| 104 |
|
|---|
| 105 | void lineTo(const QPointF &p);
|
|---|
| 106 | inline void lineTo(qreal x, qreal y);
|
|---|
| 107 |
|
|---|
| 108 | void arcMoveTo(const QRectF &rect, qreal angle);
|
|---|
| 109 | inline void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle);
|
|---|
| 110 |
|
|---|
| 111 | void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength);
|
|---|
| 112 | inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength);
|
|---|
| 113 |
|
|---|
| 114 | void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
|
|---|
| 115 | inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
|
|---|
| 116 | qreal endPtx, qreal endPty);
|
|---|
| 117 | void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
|
|---|
| 118 | inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty);
|
|---|
| 119 |
|
|---|
| 120 | QPointF currentPosition() const;
|
|---|
| 121 |
|
|---|
| 122 | void addRect(const QRectF &rect);
|
|---|
| 123 | inline void addRect(qreal x, qreal y, qreal w, qreal h);
|
|---|
| 124 | void addEllipse(const QRectF &rect);
|
|---|
| 125 | inline void addEllipse(qreal x, qreal y, qreal w, qreal h);
|
|---|
| 126 | inline void addEllipse(const QPointF ¢er, qreal rx, qreal ry);
|
|---|
| 127 | void addPolygon(const QPolygonF &polygon);
|
|---|
| 128 | void addText(const QPointF &point, const QFont &f, const QString &text);
|
|---|
| 129 | inline void addText(qreal x, qreal y, const QFont &f, const QString &text);
|
|---|
| 130 | void addPath(const QPainterPath &path);
|
|---|
| 131 | void addRegion(const QRegion ®ion);
|
|---|
| 132 |
|
|---|
| 133 | void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
|
|---|
| 134 | Qt::SizeMode mode = Qt::AbsoluteSize);
|
|---|
| 135 | inline void addRoundedRect(qreal x, qreal y, qreal w, qreal h,
|
|---|
| 136 | qreal xRadius, qreal yRadius,
|
|---|
| 137 | Qt::SizeMode mode = Qt::AbsoluteSize);
|
|---|
| 138 |
|
|---|
| 139 | void addRoundRect(const QRectF &rect, int xRnd, int yRnd);
|
|---|
| 140 | inline void addRoundRect(qreal x, qreal y, qreal w, qreal h,
|
|---|
| 141 | int xRnd, int yRnd);
|
|---|
| 142 | inline void addRoundRect(const QRectF &rect, int roundness);
|
|---|
| 143 | inline void addRoundRect(qreal x, qreal y, qreal w, qreal h,
|
|---|
| 144 | int roundness);
|
|---|
| 145 |
|
|---|
| 146 | void connectPath(const QPainterPath &path);
|
|---|
| 147 |
|
|---|
| 148 | bool contains(const QPointF &pt) const;
|
|---|
| 149 | bool contains(const QRectF &rect) const;
|
|---|
| 150 | bool intersects(const QRectF &rect) const;
|
|---|
| 151 |
|
|---|
| 152 | void translate(qreal dx, qreal dy);
|
|---|
| 153 | inline void translate(const QPointF &offset);
|
|---|
| 154 |
|
|---|
| 155 | QPainterPath translated(qreal dx, qreal dy) const;
|
|---|
| 156 | inline QPainterPath translated(const QPointF &offset) const;
|
|---|
| 157 |
|
|---|
| 158 | QRectF boundingRect() const;
|
|---|
| 159 | QRectF controlPointRect() const;
|
|---|
| 160 |
|
|---|
| 161 | Qt::FillRule fillRule() const;
|
|---|
| 162 | void setFillRule(Qt::FillRule fillRule);
|
|---|
| 163 |
|
|---|
| 164 | inline bool isEmpty() const;
|
|---|
| 165 |
|
|---|
| 166 | QPainterPath toReversed() const;
|
|---|
| 167 | QList<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const;
|
|---|
| 168 | QList<QPolygonF> toFillPolygons(const QMatrix &matrix = QMatrix()) const;
|
|---|
| 169 | QPolygonF toFillPolygon(const QMatrix &matrix = QMatrix()) const;
|
|---|
| 170 | QList<QPolygonF> toSubpathPolygons(const QTransform &matrix) const;
|
|---|
| 171 | QList<QPolygonF> toFillPolygons(const QTransform &matrix) const;
|
|---|
| 172 | QPolygonF toFillPolygon(const QTransform &matrix) const;
|
|---|
| 173 |
|
|---|
| 174 | inline int elementCount() const;
|
|---|
| 175 | inline const QPainterPath::Element &elementAt(int i) const;
|
|---|
| 176 | inline void setElementPositionAt(int i, qreal x, qreal y);
|
|---|
| 177 |
|
|---|
| 178 | qreal length() const;
|
|---|
| 179 | qreal percentAtLength(qreal t) const;
|
|---|
| 180 | QPointF pointAtPercent(qreal t) const;
|
|---|
| 181 | qreal angleAtPercent(qreal t) const;
|
|---|
| 182 | qreal slopeAtPercent(qreal t) const;
|
|---|
| 183 |
|
|---|
| 184 | bool intersects(const QPainterPath &p) const;
|
|---|
| 185 | bool contains(const QPainterPath &p) const;
|
|---|
| 186 | QPainterPath united(const QPainterPath &r) const;
|
|---|
| 187 | QPainterPath intersected(const QPainterPath &r) const;
|
|---|
| 188 | QPainterPath subtracted(const QPainterPath &r) const;
|
|---|
| 189 | QPainterPath subtractedInverted(const QPainterPath &r) const;
|
|---|
| 190 |
|
|---|
| 191 | QPainterPath simplified() const;
|
|---|
| 192 |
|
|---|
| 193 | bool operator==(const QPainterPath &other) const;
|
|---|
| 194 | bool operator!=(const QPainterPath &other) const;
|
|---|
| 195 |
|
|---|
| 196 | QPainterPath operator&(const QPainterPath &other) const;
|
|---|
| 197 | QPainterPath operator|(const QPainterPath &other) const;
|
|---|
| 198 | QPainterPath operator+(const QPainterPath &other) const;
|
|---|
| 199 | QPainterPath operator-(const QPainterPath &other) const;
|
|---|
| 200 | QPainterPath &operator&=(const QPainterPath &other);
|
|---|
| 201 | QPainterPath &operator|=(const QPainterPath &other);
|
|---|
| 202 | QPainterPath &operator+=(const QPainterPath &other);
|
|---|
| 203 | QPainterPath &operator-=(const QPainterPath &other);
|
|---|
| 204 |
|
|---|
| 205 | private:
|
|---|
| 206 | QScopedPointer<QPainterPathPrivate, QPainterPathPrivateDeleter> d_ptr;
|
|---|
| 207 |
|
|---|
| 208 | inline void ensureData() { if (!d_ptr) ensureData_helper(); }
|
|---|
| 209 | void ensureData_helper();
|
|---|
| 210 | inline void detach();
|
|---|
| 211 | void detach_helper();
|
|---|
| 212 | void setDirty(bool);
|
|---|
| 213 | void computeBoundingRect() const;
|
|---|
| 214 | void computeControlPointRect() const;
|
|---|
| 215 |
|
|---|
| 216 | QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr.data()); }
|
|---|
| 217 |
|
|---|
| 218 | friend class QPainterPathData;
|
|---|
| 219 | friend class QPainterPathStroker;
|
|---|
| 220 | friend class QPainterPathStrokerPrivate;
|
|---|
| 221 | friend class QMatrix;
|
|---|
| 222 | friend class QTransform;
|
|---|
| 223 | friend class QVectorPath;
|
|---|
| 224 | friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &);
|
|---|
| 225 |
|
|---|
| 226 | #ifndef QT_NO_DATASTREAM
|
|---|
| 227 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
|
|---|
| 228 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
|
|---|
| 229 | #endif
|
|---|
| 230 | };
|
|---|
| 231 |
|
|---|
| 232 | class QPainterPathPrivate
|
|---|
| 233 | {
|
|---|
| 234 | public:
|
|---|
| 235 | friend class QPainterPath;
|
|---|
| 236 | friend class QPainterPathData;
|
|---|
| 237 | friend class QPainterPathStroker;
|
|---|
| 238 | friend class QPainterPathStrokerPrivate;
|
|---|
| 239 | friend class QMatrix;
|
|---|
| 240 | friend class QTransform;
|
|---|
| 241 | friend class QVectorPath;
|
|---|
| 242 | friend struct QPainterPathPrivateDeleter;
|
|---|
| 243 | #ifndef QT_NO_DATASTREAM
|
|---|
| 244 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
|
|---|
| 245 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
|
|---|
| 246 | #endif
|
|---|
| 247 | private:
|
|---|
| 248 | QAtomicInt ref;
|
|---|
| 249 | QVector<QPainterPath::Element> elements;
|
|---|
| 250 | };
|
|---|
| 251 |
|
|---|
| 252 | Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE);
|
|---|
| 253 |
|
|---|
| 254 | #ifndef QT_NO_DATASTREAM
|
|---|
| 255 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
|
|---|
| 256 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
|
|---|
| 257 | #endif
|
|---|
| 258 |
|
|---|
| 259 | class Q_GUI_EXPORT QPainterPathStroker
|
|---|
| 260 | {
|
|---|
| 261 | Q_DECLARE_PRIVATE(QPainterPathStroker)
|
|---|
| 262 | public:
|
|---|
| 263 | QPainterPathStroker();
|
|---|
| 264 | ~QPainterPathStroker();
|
|---|
| 265 |
|
|---|
| 266 | void setWidth(qreal width);
|
|---|
| 267 | qreal width() const;
|
|---|
| 268 |
|
|---|
| 269 | void setCapStyle(Qt::PenCapStyle style);
|
|---|
| 270 | Qt::PenCapStyle capStyle() const;
|
|---|
| 271 |
|
|---|
| 272 | void setJoinStyle(Qt::PenJoinStyle style);
|
|---|
| 273 | Qt::PenJoinStyle joinStyle() const;
|
|---|
| 274 |
|
|---|
| 275 | void setMiterLimit(qreal length);
|
|---|
| 276 | qreal miterLimit() const;
|
|---|
| 277 |
|
|---|
| 278 | void setCurveThreshold(qreal threshold);
|
|---|
| 279 | qreal curveThreshold() const;
|
|---|
| 280 |
|
|---|
| 281 | void setDashPattern(Qt::PenStyle);
|
|---|
| 282 | void setDashPattern(const QVector<qreal> &dashPattern);
|
|---|
| 283 | QVector<qreal> dashPattern() const;
|
|---|
| 284 |
|
|---|
| 285 | void setDashOffset(qreal offset);
|
|---|
| 286 | qreal dashOffset() const;
|
|---|
| 287 |
|
|---|
| 288 | QPainterPath createStroke(const QPainterPath &path) const;
|
|---|
| 289 |
|
|---|
| 290 | private:
|
|---|
| 291 | friend class QX11PaintEngine;
|
|---|
| 292 |
|
|---|
| 293 | QScopedPointer<QPainterPathStrokerPrivate> d_ptr;
|
|---|
| 294 | };
|
|---|
| 295 |
|
|---|
| 296 | inline void QPainterPath::moveTo(qreal x, qreal y)
|
|---|
| 297 | {
|
|---|
| 298 | moveTo(QPointF(x, y));
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | inline void QPainterPath::lineTo(qreal x, qreal y)
|
|---|
| 302 | {
|
|---|
| 303 | lineTo(QPointF(x, y));
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
|
|---|