author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QPAINTERPATH_P_H |
|
43 |
#define QPAINTERPATH_P_H |
|
44 |
||
45 |
// |
|
46 |
// W A R N I N G |
|
47 |
// ------------- |
|
48 |
// |
|
49 |
// This file is not part of the Qt API. It exists for the convenience |
|
50 |
// of other Qt classes. This header file may change from version to |
|
51 |
// version without notice, or even be removed. |
|
52 |
// |
|
53 |
// We mean it. |
|
54 |
// |
|
55 |
||
56 |
#include "QtGui/qpainterpath.h" |
|
57 |
#include "QtGui/qregion.h" |
|
58 |
#include "QtCore/qlist.h" |
|
59 |
#include "QtCore/qvarlengtharray.h" |
|
60 |
||
61 |
#include <qdebug.h> |
|
62 |
||
63 |
#include <private/qvectorpath_p.h> |
|
64 |
#include <private/qstroker_p.h> |
|
65 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
class QPainterPathStrokerPrivate |
|
69 |
{ |
|
70 |
public: |
|
71 |
QPainterPathStrokerPrivate(); |
|
72 |
||
73 |
QStroker stroker; |
|
74 |
QVector<qfixed> dashPattern; |
|
75 |
qreal dashOffset; |
|
76 |
}; |
|
77 |
||
78 |
class QPolygonF; |
|
79 |
class QVectorPathConverter; |
|
80 |
||
81 |
class QVectorPathConverter |
|
82 |
{ |
|
83 |
public: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
QVectorPathConverter(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
: pathData(path, fillRule, convex), |
0 | 86 |
path(pathData.points.data(), path.size(), |
87 |
pathData.elements.data(), pathData.flags) {} |
|
88 |
||
89 |
const QVectorPath &vectorPath() { |
|
90 |
return path; |
|
91 |
} |
|
92 |
||
93 |
struct QVectorPathData { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
QVectorPathData(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex) |
0 | 95 |
: elements(path.size()), |
96 |
points(path.size() * 2), |
|
97 |
flags(0) |
|
98 |
{ |
|
99 |
int ptsPos = 0; |
|
100 |
for (int i=0; i<path.size(); ++i) { |
|
101 |
const QPainterPath::Element &e = path.at(i); |
|
102 |
elements[i] = e.type; |
|
103 |
points[ptsPos++] = e.x; |
|
104 |
points[ptsPos++] = e.y; |
|
105 |
if (e.type == QPainterPath::CurveToElement) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
flags |= QVectorPath::CurvedShapeMask; |
0 | 107 |
} |
108 |
||
109 |
if (fillRule == Qt::WindingFill) |
|
110 |
flags |= QVectorPath::WindingFill; |
|
111 |
else |
|
112 |
flags |= QVectorPath::OddEvenFill; |
|
113 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
if (!convex) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
flags |= QVectorPath::NonConvexShapeMask; |
0 | 116 |
} |
117 |
QVarLengthArray<QPainterPath::ElementType> elements; |
|
118 |
QVarLengthArray<qreal> points; |
|
119 |
uint flags; |
|
120 |
}; |
|
121 |
||
122 |
QVectorPathData pathData; |
|
123 |
QVectorPath path; |
|
124 |
||
125 |
private: |
|
126 |
Q_DISABLE_COPY(QVectorPathConverter) |
|
127 |
}; |
|
128 |
||
129 |
class QPainterPathData : public QPainterPathPrivate |
|
130 |
{ |
|
131 |
public: |
|
132 |
QPainterPathData() : |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
cStart(0), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
fillRule(Qt::OddEvenFill), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
dirtyBounds(false), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
dirtyControlBounds(false), |
0 | 137 |
pathConverter(0) |
138 |
{ |
|
139 |
ref = 1; |
|
140 |
require_moveTo = false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
convex = false; |
0 | 142 |
} |
143 |
||
144 |
QPainterPathData(const QPainterPathData &other) : |
|
145 |
QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
bounds(other.bounds), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
controlBounds(other.controlBounds), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
dirtyBounds(other.dirtyBounds), |
0 | 149 |
dirtyControlBounds(other.dirtyControlBounds), |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
convex(other.convex), |
0 | 151 |
pathConverter(0) |
152 |
{ |
|
153 |
ref = 1; |
|
154 |
require_moveTo = false; |
|
155 |
elements = other.elements; |
|
156 |
} |
|
157 |
||
158 |
~QPainterPathData() { |
|
159 |
delete pathConverter; |
|
160 |
} |
|
161 |
||
162 |
inline bool isClosed() const; |
|
163 |
inline void close(); |
|
164 |
inline void maybeMoveTo(); |
|
165 |
||
166 |
const QVectorPath &vectorPath() { |
|
167 |
if (!pathConverter) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
pathConverter = new QVectorPathConverter(elements, fillRule, convex); |
0 | 169 |
return pathConverter->path; |
170 |
} |
|
171 |
||
172 |
int cStart; |
|
173 |
Qt::FillRule fillRule; |
|
174 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
QRectF bounds; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
QRectF controlBounds; |
0 | 177 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
uint require_moveTo : 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
uint dirtyBounds : 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
uint dirtyControlBounds : 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
uint convex : 1; |
0 | 182 |
|
183 |
QVectorPathConverter *pathConverter; |
|
184 |
}; |
|
185 |
||
186 |
||
187 |
inline const QPainterPath QVectorPath::convertToPainterPath() const |
|
188 |
{ |
|
189 |
QPainterPath path; |
|
190 |
path.ensureData(); |
|
191 |
QPainterPathData *data = path.d_func(); |
|
192 |
data->elements.reserve(m_count); |
|
193 |
int index = 0; |
|
194 |
data->elements[0].x = m_points[index++]; |
|
195 |
data->elements[0].y = m_points[index++]; |
|
196 |
||
197 |
if (m_elements) { |
|
198 |
data->elements[0].type = m_elements[0]; |
|
199 |
for (int i=1; i<m_count; ++i) { |
|
200 |
QPainterPath::Element element; |
|
201 |
element.x = m_points[index++]; |
|
202 |
element.y = m_points[index++]; |
|
203 |
element.type = m_elements[i]; |
|
204 |
data->elements << element; |
|
205 |
} |
|
206 |
} else { |
|
207 |
data->elements[0].type = QPainterPath::MoveToElement; |
|
208 |
for (int i=1; i<m_count; ++i) { |
|
209 |
QPainterPath::Element element; |
|
210 |
element.x = m_points[index++]; |
|
211 |
element.y = m_points[index++]; |
|
212 |
element.type = QPainterPath::LineToElement; |
|
213 |
data->elements << element; |
|
214 |
} |
|
215 |
} |
|
216 |
||
217 |
if (m_hints & OddEvenFill) |
|
218 |
data->fillRule = Qt::OddEvenFill; |
|
219 |
else |
|
220 |
data->fillRule = Qt::WindingFill; |
|
221 |
return path; |
|
222 |
} |
|
223 |
||
224 |
void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, |
|
225 |
QPointF* startPoint, QPointF *endPoint); |
|
226 |
||
227 |
inline bool QPainterPathData::isClosed() const |
|
228 |
{ |
|
229 |
const QPainterPath::Element &first = elements.at(cStart); |
|
230 |
const QPainterPath::Element &last = elements.last(); |
|
231 |
return first.x == last.x && first.y == last.y; |
|
232 |
} |
|
233 |
||
234 |
inline void QPainterPathData::close() |
|
235 |
{ |
|
236 |
Q_ASSERT(ref == 1); |
|
237 |
require_moveTo = true; |
|
238 |
const QPainterPath::Element &first = elements.at(cStart); |
|
239 |
QPainterPath::Element &last = elements.last(); |
|
240 |
if (first.x != last.x || first.y != last.y) { |
|
241 |
if (qFuzzyCompare(first.x, last.x) && qFuzzyCompare(first.y, last.y)) { |
|
242 |
last.x = first.x; |
|
243 |
last.y = first.y; |
|
244 |
} else { |
|
245 |
QPainterPath::Element e = { first.x, first.y, QPainterPath::LineToElement }; |
|
246 |
elements << e; |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
inline void QPainterPathData::maybeMoveTo() |
|
252 |
{ |
|
253 |
if (require_moveTo) { |
|
254 |
QPainterPath::Element e = elements.last(); |
|
255 |
e.type = QPainterPath::MoveToElement; |
|
256 |
elements.append(e); |
|
257 |
require_moveTo = false; |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
#define KAPPA 0.5522847498 |
|
262 |
||
263 |
||
264 |
QT_END_NAMESPACE |
|
265 |
||
266 |
#endif // QPAINTERPATH_P_H |