source: trunk/src/gui/painting/qpainterpath_p.h@ 228

Last change on this file since 228 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
66QT_BEGIN_NAMESPACE
67
68class QPainterPathStrokerPrivate
69{
70public:
71 QPainterPathStrokerPrivate();
72
73 QStroker stroker;
74 QVector<qfixed> dashPattern;
75 qreal dashOffset;
76};
77
78class QPolygonF;
79class QVectorPathConverter;
80
81class QVectorPathConverter
82{
83public:
84 QVectorPathConverter(const QVector<QPainterPath::Element> &path, uint fillRule)
85 : pathData(path, fillRule),
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 {
94 QVectorPathData(const QVector<QPainterPath::Element> &path, uint fillRule)
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)
106 flags |= QVectorPath::CurvedShapeHint;
107 }
108
109 if (fillRule == Qt::WindingFill)
110 flags |= QVectorPath::WindingFill;
111 else
112 flags |= QVectorPath::OddEvenFill;
113
114 }
115 QVarLengthArray<QPainterPath::ElementType> elements;
116 QVarLengthArray<qreal> points;
117 uint flags;
118 };
119
120 QVectorPathData pathData;
121 QVectorPath path;
122
123private:
124 Q_DISABLE_COPY(QVectorPathConverter)
125};
126
127class Q_GUI_EXPORT QPainterPathData : public QPainterPathPrivate
128{
129public:
130 QPainterPathData() :
131 cStart(0), fillRule(Qt::OddEvenFill),
132 dirtyBounds(false), dirtyControlBounds(false),
133 pathConverter(0)
134 {
135 ref = 1;
136 require_moveTo = false;
137 }
138
139 QPainterPathData(const QPainterPathData &other) :
140 QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule),
141 dirtyBounds(other.dirtyBounds), bounds(other.bounds),
142 dirtyControlBounds(other.dirtyControlBounds),
143 controlBounds(other.controlBounds),
144 pathConverter(0)
145 {
146 ref = 1;
147 require_moveTo = false;
148 elements = other.elements;
149 }
150
151 ~QPainterPathData() {
152 delete pathConverter;
153 }
154
155 inline bool isClosed() const;
156 inline void close();
157 inline void maybeMoveTo();
158
159 const QVectorPath &vectorPath() {
160 if (!pathConverter)
161 pathConverter = new QVectorPathConverter(elements, fillRule);
162 return pathConverter->path;
163 }
164
165 int cStart;
166 Qt::FillRule fillRule;
167
168 bool require_moveTo;
169
170 bool dirtyBounds;
171 QRectF bounds;
172 bool dirtyControlBounds;
173 QRectF controlBounds;
174
175 QVectorPathConverter *pathConverter;
176};
177
178
179
180void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length,
181 QPointF* startPoint, QPointF *endPoint);
182
183inline bool QPainterPathData::isClosed() const
184{
185 const QPainterPath::Element &first = elements.at(cStart);
186 const QPainterPath::Element &last = elements.last();
187 return first.x == last.x && first.y == last.y;
188}
189
190inline void QPainterPathData::close()
191{
192 Q_ASSERT(ref == 1);
193 require_moveTo = true;
194 const QPainterPath::Element &first = elements.at(cStart);
195 QPainterPath::Element &last = elements.last();
196 if (first.x != last.x || first.y != last.y) {
197 if (qFuzzyCompare(first.x, last.x) && qFuzzyCompare(first.y, last.y)) {
198 last.x = first.x;
199 last.y = first.y;
200 } else {
201 QPainterPath::Element e = { first.x, first.y, QPainterPath::LineToElement };
202 elements << e;
203 }
204 }
205}
206
207inline void QPainterPathData::maybeMoveTo()
208{
209 if (require_moveTo) {
210 QPainterPath::Element e = elements.last();
211 e.type = QPainterPath::MoveToElement;
212 elements.append(e);
213 require_moveTo = false;
214 }
215}
216
217#define KAPPA 0.5522847498
218
219
220QT_END_NAMESPACE
221
222#endif // QPAINTERPATH_P_H
Note: See TracBrowser for help on using the repository browser.