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

« back to all changes in this revision

Viewing changes to src/gui/painting/qpainterpath_p.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_P_H
 
30
#define QPAINTERPATH_P_H
 
31
 
 
32
//
 
33
//  W A R N I N G
 
34
//  -------------
 
35
//
 
36
// This file is not part of the Qt API.  It exists for the convenience
 
37
// of other Qt classes.  This header file may change from version to
 
38
// version without notice, or even be removed.
 
39
//
 
40
// We mean it.
 
41
//
 
42
 
 
43
#include <qlist.h>
 
44
#include <qregion.h>
 
45
#include <qpainterpath.h>
 
46
 
 
47
class QPolygonF;
 
48
 
 
49
class QPainterPathData : public QPainterPathPrivate
 
50
{
 
51
public:
 
52
    QPainterPathData() :
 
53
        cStart(0), fillRule(Qt::OddEvenFill)
 
54
    {
 
55
        ref = 1;
 
56
    }
 
57
 
 
58
    QPainterPathData(const QPainterPathData &other) :
 
59
        QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule), containsCache(other.containsCache)
 
60
    {
 
61
        ref = 1;
 
62
        elements = other.elements;
 
63
    }
 
64
 
 
65
    inline bool isClosed() const;
 
66
    inline void close();
 
67
 
 
68
    inline void makeDirty();
 
69
 
 
70
    int cStart;
 
71
    Qt::FillRule fillRule;
 
72
 
 
73
    QRegion containsCache;
 
74
};
 
75
 
 
76
 
 
77
void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length,
 
78
                                         QPointF* startPoint, QPointF *endPoint);
 
79
 
 
80
inline bool QPainterPathData::isClosed() const
 
81
{
 
82
    const QPainterPath::Element &first = elements.at(cStart);
 
83
    const QPainterPath::Element &last = elements.last();
 
84
    return first.x == last.x && first.y == last.y;
 
85
}
 
86
 
 
87
inline void QPainterPathData::close()
 
88
{
 
89
    Q_ASSERT(ref == 1);
 
90
    const QPainterPath::Element &first = elements.at(cStart);
 
91
    const QPainterPath::Element &last = elements.last();
 
92
    if (first.x != last.x || first.y != last.y) {
 
93
        QPainterPath::Element e = { first.x, first.y, QPainterPath::LineToElement };
 
94
        elements << e;
 
95
    }
 
96
}
 
97
 
 
98
inline void QPainterPathData::makeDirty()
 
99
{
 
100
    if (!containsCache.isEmpty())
 
101
        containsCache = QRegion();
 
102
}
 
103
 
 
104
/*******************************************************************************
 
105
 * class QSubpathIterator
 
106
 * Iterates through a path, subpath by subpath, element by element.
 
107
 */
 
108
class QSubpathIterator
 
109
{
 
110
public:
 
111
    QSubpathIterator(const QPainterPath *path);
 
112
 
 
113
    inline bool hasSubpath() const;
 
114
    inline QPointF nextSubpath();
 
115
 
 
116
    inline bool hasNext() const;
 
117
    inline QPainterPath::Element next();
 
118
 
 
119
    inline int position() const { return m_pos; }
 
120
 
 
121
private:
 
122
    const QPainterPath *m_path;
 
123
    int m_pos;
 
124
};
 
125
 
 
126
/*******************************************************************************
 
127
 * QSubpathReverseIterator
 
128
 *
 
129
 * Iterates through all subpaths backwards. The order of the subpaths
 
130
 * are the same as their order in the original path.
 
131
 */
 
132
class QSubpathReverseIterator
 
133
{
 
134
public:
 
135
    QSubpathReverseIterator(const QPainterPath *path);
 
136
 
 
137
    inline bool hasSubpath() const;
 
138
    inline QPointF nextSubpath();
 
139
 
 
140
    inline bool hasNext() const;
 
141
    QPainterPath::Element next();
 
142
 
 
143
private:
 
144
    inline int indexOfSubpath(int startIndex);
 
145
 
 
146
    const QPainterPath *m_path;
 
147
    int m_pos;
 
148
    int m_start, m_end;
 
149
};
 
150
 
 
151
/*******************************************************************************
 
152
 * QSubpathFlatIterator
 
153
 *
 
154
 * Iterates through all subpaths, element by element, but converts any
 
155
 * curve element to a number of line segments so all elements retrieved
 
156
 * are of type QPainterPath::LineToElement.
 
157
 */
 
158
class QSubpathFlatIterator
 
159
{
 
160
public:
 
161
    QSubpathFlatIterator(const QPainterPath *path);
 
162
 
 
163
    inline bool hasSubpath() const;
 
164
    inline QPointF nextSubpath();
 
165
 
 
166
    inline bool hasNext() const;
 
167
    QPainterPath::Element next();
 
168
 
 
169
private:
 
170
    const QPainterPath *m_path;
 
171
    int m_pos;
 
172
    QPolygonF m_curve;
 
173
    int m_curve_index;
 
174
};
 
175
 
 
176
 
 
177
/*******************************************************************************
 
178
 * QSubpathIterator inline implemetations
 
179
 */
 
180
 
 
181
inline QSubpathIterator::QSubpathIterator(const QPainterPath *path)
 
182
     : m_path(path),
 
183
       m_pos(0)
 
184
{
 
185
}
 
186
 
 
187
inline bool QSubpathIterator::hasSubpath() const
 
188
{
 
189
    return m_pos + 1 < m_path->elementCount()
 
190
        && m_path->elementAt(m_pos).type == QPainterPath::MoveToElement;
 
191
}
 
192
 
 
193
inline QPointF QSubpathIterator::nextSubpath()
 
194
{
 
195
    Q_ASSERT(hasSubpath());
 
196
    const QPainterPath::Element &e = m_path->elementAt(m_pos);
 
197
    ++m_pos;
 
198
    Q_ASSERT(!hasSubpath());
 
199
    return QPointF(e.x, e.y);
 
200
}
 
201
 
 
202
inline bool QSubpathIterator::hasNext() const
 
203
{
 
204
    return m_pos < m_path->elementCount()
 
205
        && m_path->elementAt(m_pos).type != QPainterPath::MoveToElement;
 
206
}
 
207
 
 
208
inline QPainterPath::Element QSubpathIterator::next()
 
209
{
 
210
    Q_ASSERT(hasNext());
 
211
    return m_path->elementAt(m_pos++);
 
212
}
 
213
 
 
214
 
 
215
/*******************************************************************************
 
216
 * QSubpathReverseIterator inline implementations
 
217
 */
 
218
 
 
219
inline QSubpathReverseIterator::QSubpathReverseIterator(const QPainterPath *path)
 
220
     : m_path(path)
 
221
{
 
222
    m_start = 0;
 
223
    m_end = indexOfSubpath(1);
 
224
    m_pos = m_end;
 
225
}
 
226
 
 
227
inline bool QSubpathReverseIterator::hasSubpath() const
 
228
{
 
229
    return (m_start < m_end) & (m_pos == m_end);
 
230
}
 
231
 
 
232
inline QPointF QSubpathReverseIterator::nextSubpath()
 
233
{
 
234
    Q_ASSERT(hasSubpath());
 
235
    const QPainterPath::Element &e = m_path->elementAt(m_pos);
 
236
    --m_pos;
 
237
    return QPointF(e.x, e.y);
 
238
}
 
239
 
 
240
inline bool QSubpathReverseIterator::hasNext() const
 
241
{
 
242
    return (m_start < m_end) & (m_pos < m_end) & (m_pos >= m_start);
 
243
}
 
244
 
 
245
inline int QSubpathReverseIterator::indexOfSubpath(int i)
 
246
{
 
247
    int max = m_path->elementCount();
 
248
    while (i < max && m_path->elementAt(i).type != QPainterPath::MoveToElement)
 
249
        ++i;
 
250
    return i - 1;
 
251
}
 
252
 
 
253
 
 
254
/*******************************************************************************
 
255
 * QSubpathFlatIterator inline implemetations
 
256
 */
 
257
 
 
258
inline QSubpathFlatIterator::QSubpathFlatIterator(const QPainterPath *path)
 
259
     : m_path(path),
 
260
       m_pos(0),
 
261
       m_curve_index(-1)
 
262
{
 
263
 
 
264
}
 
265
 
 
266
inline bool QSubpathFlatIterator::hasNext() const
 
267
{
 
268
    return m_curve_index >= 0 || (m_pos < m_path->elementCount()
 
269
                                  && m_path->elementAt(m_pos).type != QPainterPath::MoveToElement);
 
270
}
 
271
 
 
272
inline bool QSubpathFlatIterator::hasSubpath() const
 
273
{
 
274
    return m_pos + 1 < m_path->elementCount()
 
275
        && m_path->elementAt(m_pos).type == QPainterPath::MoveToElement;
 
276
}
 
277
 
 
278
inline QPointF QSubpathFlatIterator::nextSubpath()
 
279
{
 
280
    Q_ASSERT(hasSubpath());
 
281
    const QPainterPath::Element &e = m_path->elementAt(m_pos);
 
282
    ++m_pos;
 
283
    Q_ASSERT(!hasSubpath());
 
284
    return QPointF(e.x, e.y);
 
285
}
 
286
 
 
287
#endif // QPAINTERPATH_P_H