1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the painting module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#ifndef QPAINTERPATH_H
30
#define QPAINTERPATH_H
32
#include "QtCore/qglobal.h"
33
#include "QtCore/qrect.h"
34
#include "QtCore/qline.h"
35
#include "QtCore/qvector.h"
36
#include "QtGui/qmatrix.h"
40
class QPainterPathPrivate;
41
class QPainterPathData;
42
class QPainterPathStrokerPrivate;
46
class Q_GUI_EXPORT QPainterPath
62
bool isMoveTo() const { return type == MoveToElement; }
63
bool isLineTo() const { return type == LineToElement; }
64
bool isCurveTo() const { return type == CurveToElement; }
66
operator QPointF () const { return QPointF(x, y); }
68
bool operator==(const Element &e) const { return x == e.x && y == e.y && type == e.type; }
72
explicit QPainterPath(const QPointF &startPoint);
73
QPainterPath(const QPainterPath &other);
74
QPainterPath &operator=(const QPainterPath &other);
79
void moveTo(const QPointF &p);
80
inline void moveTo(qreal x, qreal y);
82
void lineTo(const QPointF &p);
83
inline void lineTo(qreal x, qreal y);
85
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength);
86
inline void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength);
88
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
89
inline void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
90
qreal endPtx, qreal endPty);
91
void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
92
inline void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty);
94
QPointF currentPosition() const;
96
void addRect(const QRectF &rect);
97
inline void addRect(qreal x, qreal y, qreal w, qreal h);
98
void addEllipse(const QRectF &rect);
99
inline void addEllipse(qreal x, qreal y, qreal w, qreal h);
100
void addPolygon(const QPolygonF &polygon);
101
void addText(const QPointF &point, const QFont &f, const QString &text);
102
inline void addText(qreal x, qreal y, const QFont &f, const QString &text);
103
void addPath(const QPainterPath &path);
104
void addRegion(const QRegion ®ion);
106
void connectPath(const QPainterPath &path);
108
bool contains(const QPointF &pt) const;
109
bool contains(const QRectF &rect) const;
110
bool intersects(const QRectF &rect) const;
112
QRectF boundingRect() const;
113
QRectF controlPointRect() const;
115
Qt::FillRule fillRule() const;
116
void setFillRule(Qt::FillRule fillRule);
118
inline bool isEmpty() const;
120
QPainterPath toReversed() const;
121
QList<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const;
122
QList<QPolygonF> toFillPolygons(const QMatrix &matrix = QMatrix()) const;
123
QPolygonF toFillPolygon(const QMatrix &matrix = QMatrix()) const;
125
inline int elementCount() const;
126
inline const QPainterPath::Element &elementAt(int i) const;
128
bool operator==(const QPainterPath &other) const;
129
bool operator!=(const QPainterPath &other) const;
132
QPainterPathPrivate *d_ptr;
134
inline void ensureData() { if (!d_ptr) ensureData_helper(); }
135
void ensureData_helper();
136
inline void detach();
137
void detach_helper();
139
QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr); }
141
friend class QPainterPathData;
142
friend class QPainterPathStroker;
143
friend class QPainterPathStrokerPrivate;
144
friend class QMatrix;
146
#ifndef QT_NO_DATASTREAM
147
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
148
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
152
class QPainterPathPrivate
154
friend class QPainterPath;
155
friend class QPainterPathData;
156
friend class QPainterPathStroker;
157
friend class QPainterPathStrokerPrivate;
158
friend class QMatrix;
159
#ifndef QT_NO_DATASTREAM
160
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
161
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
165
QVector<QPainterPath::Element> elements;
168
Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE);
170
#ifndef QT_NO_DATASTREAM
171
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
172
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
175
class Q_GUI_EXPORT QPainterPathStroker
177
Q_DECLARE_PRIVATE(QPainterPathStroker)
179
QPainterPathStroker();
180
~QPainterPathStroker();
182
void setWidth(qreal width);
185
void setCapStyle(Qt::PenCapStyle style);
186
Qt::PenCapStyle capStyle() const;
188
void setJoinStyle(Qt::PenJoinStyle style);
189
Qt::PenJoinStyle joinStyle() const;
191
void setMiterLimit(qreal length);
192
qreal miterLimit() const;
194
void setCurveThreshold(qreal threshold);
195
qreal curveThreshold() const;
197
void setDashPattern(Qt::PenStyle);
198
void setDashPattern(const QVector<qreal> &dashPattern);
199
QVector<qreal> dashPattern() const;
201
QPainterPath createStroke(const QPainterPath &path) const;
204
QPainterPathStrokerPrivate *d_ptr;
207
inline void QPainterPath::moveTo(qreal x, qreal y)
209
moveTo(QPointF(x, y));
212
inline void QPainterPath::lineTo(qreal x, qreal y)
214
lineTo(QPointF(x, y));
217
inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLenght)
219
arcTo(QRectF(x, y, w, h), startAngle, arcLenght);
222
inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
223
qreal endPtx, qreal endPty)
225
cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
226
QPointF(endPtx, endPty));
229
inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
231
quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
234
inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h)
236
addEllipse(QRectF(x, y, w, h));
239
inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h)
241
addRect(QRectF(x, y, w, h));
244
inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
246
addText(QPointF(x, y), f, text);
249
inline bool QPainterPath::isEmpty() const
251
return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement);
254
inline int QPainterPath::elementCount() const
256
return d_ptr ? d_ptr->elements.size() : 0;
259
inline const QPainterPath::Element &QPainterPath::elementAt(int i) const
262
Q_ASSERT(i >= 0 && i < elementCount());
263
return d_ptr->elements.at(i);
266
inline void QPainterPath::detach()
272
#endif // QPAINTERPATH_H