~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/painting/qpainterpath.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the painting module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QPAINTERPATH_H
 
30
#define QPAINTERPATH_H
 
31
 
 
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"
 
37
 
 
38
 
 
39
class QFont;
 
40
class QPainterPathPrivate;
 
41
class QPainterPathData;
 
42
class QPainterPathStrokerPrivate;
 
43
class QPolygonF;
 
44
class QRegion;
 
45
 
 
46
class Q_GUI_EXPORT QPainterPath
 
47
{
 
48
public:
 
49
    enum ElementType {
 
50
        MoveToElement,
 
51
        LineToElement,
 
52
        CurveToElement,
 
53
        CurveToDataElement
 
54
    };
 
55
 
 
56
    class Element {
 
57
    public:
 
58
        qreal x;
 
59
        qreal y;
 
60
        ElementType type;
 
61
 
 
62
        bool isMoveTo() const { return type == MoveToElement; }
 
63
        bool isLineTo() const { return type == LineToElement; }
 
64
        bool isCurveTo() const { return type == CurveToElement; }
 
65
 
 
66
        operator QPointF () const { return QPointF(x, y); }
 
67
 
 
68
        bool operator==(const Element &e) const { return x == e.x && y == e.y && type == e.type; }
 
69
    };
 
70
 
 
71
    QPainterPath();
 
72
    explicit QPainterPath(const QPointF &startPoint);
 
73
    QPainterPath(const QPainterPath &other);
 
74
    QPainterPath &operator=(const QPainterPath &other);
 
75
    ~QPainterPath();
 
76
 
 
77
    void closeSubpath();
 
78
 
 
79
    void moveTo(const QPointF &p);
 
80
    inline void moveTo(qreal x, qreal y);
 
81
 
 
82
    void lineTo(const QPointF &p);
 
83
    inline void lineTo(qreal x, qreal y);
 
84
 
 
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);
 
87
 
 
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);
 
93
 
 
94
    QPointF currentPosition() const;
 
95
 
 
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 &region);
 
105
 
 
106
    void connectPath(const QPainterPath &path);
 
107
 
 
108
    bool contains(const QPointF &pt) const;
 
109
    bool contains(const QRectF &rect) const;
 
110
    bool intersects(const QRectF &rect) const;
 
111
 
 
112
    QRectF boundingRect() const;
 
113
    QRectF controlPointRect() const;
 
114
 
 
115
    Qt::FillRule fillRule() const;
 
116
    void setFillRule(Qt::FillRule fillRule);
 
117
 
 
118
    inline bool isEmpty() const;
 
119
 
 
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;
 
124
 
 
125
    inline int elementCount() const;
 
126
    inline const QPainterPath::Element &elementAt(int i) const;
 
127
 
 
128
    bool operator==(const QPainterPath &other) const;
 
129
    bool operator!=(const QPainterPath &other) const;
 
130
 
 
131
private:
 
132
    QPainterPathPrivate *d_ptr;
 
133
 
 
134
    inline void ensureData() { if (!d_ptr) ensureData_helper(); }
 
135
    void ensureData_helper();
 
136
    inline void detach();
 
137
    void detach_helper();
 
138
 
 
139
    QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr); }
 
140
 
 
141
    friend class QPainterPathData;
 
142
    friend class QPainterPathStroker;
 
143
    friend class QPainterPathStrokerPrivate;
 
144
    friend class QMatrix;
 
145
 
 
146
#ifndef QT_NO_DATASTREAM
 
147
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
 
148
    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
 
149
#endif
 
150
};
 
151
 
 
152
class QPainterPathPrivate
 
153
{
 
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 &);
 
162
#endif
 
163
private:
 
164
    QAtomic ref;
 
165
    QVector<QPainterPath::Element> elements;
 
166
};
 
167
 
 
168
Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE);
 
169
 
 
170
#ifndef QT_NO_DATASTREAM
 
171
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
 
172
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
 
173
#endif
 
174
 
 
175
class Q_GUI_EXPORT QPainterPathStroker
 
176
{
 
177
    Q_DECLARE_PRIVATE(QPainterPathStroker)
 
178
public:
 
179
    QPainterPathStroker();
 
180
    ~QPainterPathStroker();
 
181
 
 
182
    void setWidth(qreal width);
 
183
    qreal width() const;
 
184
 
 
185
    void setCapStyle(Qt::PenCapStyle style);
 
186
    Qt::PenCapStyle capStyle() const;
 
187
 
 
188
    void setJoinStyle(Qt::PenJoinStyle style);
 
189
    Qt::PenJoinStyle joinStyle() const;
 
190
 
 
191
    void setMiterLimit(qreal length);
 
192
    qreal miterLimit() const;
 
193
 
 
194
    void setCurveThreshold(qreal threshold);
 
195
    qreal curveThreshold() const;
 
196
 
 
197
    void setDashPattern(Qt::PenStyle);
 
198
    void setDashPattern(const QVector<qreal> &dashPattern);
 
199
    QVector<qreal> dashPattern() const;
 
200
 
 
201
    QPainterPath createStroke(const QPainterPath &path) const;
 
202
 
 
203
private:
 
204
    QPainterPathStrokerPrivate *d_ptr;
 
205
};
 
206
 
 
207
inline void QPainterPath::moveTo(qreal x, qreal y)
 
208
{
 
209
    moveTo(QPointF(x, y));
 
210
}
 
211
 
 
212
inline void QPainterPath::lineTo(qreal x, qreal y)
 
213
{
 
214
    lineTo(QPointF(x, y));
 
215
}
 
216
 
 
217
inline void QPainterPath::arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLenght)
 
218
{
 
219
    arcTo(QRectF(x, y, w, h), startAngle, arcLenght);
 
220
}
 
221
 
 
222
inline void QPainterPath::cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y,
 
223
                                   qreal endPtx, qreal endPty)
 
224
{
 
225
    cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
 
226
            QPointF(endPtx, endPty));
 
227
}
 
228
 
 
229
inline void QPainterPath::quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
 
230
{
 
231
    quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
 
232
}
 
233
 
 
234
inline void QPainterPath::addEllipse(qreal x, qreal y, qreal w, qreal h)
 
235
{
 
236
    addEllipse(QRectF(x, y, w, h));
 
237
}
 
238
 
 
239
inline void QPainterPath::addRect(qreal x, qreal y, qreal w, qreal h)
 
240
{
 
241
    addRect(QRectF(x, y, w, h));
 
242
}
 
243
 
 
244
inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text)
 
245
{
 
246
    addText(QPointF(x, y), f, text);
 
247
}
 
248
 
 
249
inline bool QPainterPath::isEmpty() const
 
250
{
 
251
    return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement);
 
252
}
 
253
 
 
254
inline int QPainterPath::elementCount() const
 
255
{
 
256
    return d_ptr ? d_ptr->elements.size() : 0;
 
257
}
 
258
 
 
259
inline const QPainterPath::Element &QPainterPath::elementAt(int i) const
 
260
{
 
261
    Q_ASSERT(d_ptr);
 
262
    Q_ASSERT(i >= 0 && i < elementCount());
 
263
    return d_ptr->elements.at(i);
 
264
}
 
265
 
 
266
inline void QPainterPath::detach()
 
267
{
 
268
    if (d_ptr->ref != 1)
 
269
        detach_helper();
 
270
}
 
271
 
 
272
#endif // QPAINTERPATH_H