Qt 4.8
qpainterpath_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
67 
69 {
70 public:
72 
76 };
77 
78 class QPolygonF;
80 
82 {
83 public:
84  QVectorPathConverter(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex)
85  : pathData(path, fillRule, convex),
86  path(pathData.points.data(), path.size(),
87  pathData.elements.data(), pathData.flags) {}
88 
90  return path;
91  }
92 
93  struct QVectorPathData {
94  QVectorPathData(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex)
95  : elements(path.size()),
96  points(path.size() * 2),
97  flags(0)
98  {
99  int ptsPos = 0;
100  bool isLines = true;
101  for (int i=0; i<path.size(); ++i) {
102  const QPainterPath::Element &e = path.at(i);
103  elements[i] = e.type;
104  points[ptsPos++] = e.x;
105  points[ptsPos++] = e.y;
108 
109  // This is to check if the path contains only alternating lineTo/moveTo,
110  // in which case we can set the LinesHint in the path. MoveTo is 0 and
111  // LineTo is 1 so the i%2 gets us what we want cheaply.
112  isLines = isLines && e.type == (QPainterPath::ElementType) (i%2);
113  }
114 
115  if (fillRule == Qt::WindingFill)
116  flags |= QVectorPath::WindingFill;
117  else
118  flags |= QVectorPath::OddEvenFill;
119 
120  if (isLines)
122  else {
124  if (!convex)
126  }
127 
128  }
132  };
133 
136 
137 private:
139 };
140 
142 {
143 public:
145  cStart(0),
146  fillRule(Qt::OddEvenFill),
147  dirtyBounds(false),
148  dirtyControlBounds(false),
149  pathConverter(0)
150  {
151  ref = 1;
152  require_moveTo = false;
153  convex = false;
154  }
155 
157  QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule),
158  bounds(other.bounds),
159  controlBounds(other.controlBounds),
160  dirtyBounds(other.dirtyBounds),
161  dirtyControlBounds(other.dirtyControlBounds),
162  convex(other.convex),
163  pathConverter(0)
164  {
165  ref = 1;
166  require_moveTo = false;
167  elements = other.elements;
168  }
169 
171  delete pathConverter;
172  }
173 
174  inline bool isClosed() const;
175  inline void close();
176  inline void maybeMoveTo();
177 
179  if (!pathConverter)
180  pathConverter = new QVectorPathConverter(elements, fillRule, convex);
181  return pathConverter->path;
182  }
183 
184  int cStart;
186 
189 
194 
196 };
197 
198 
200 {
201  QPainterPath path;
202  path.ensureData();
203  QPainterPathData *data = path.d_func();
204  data->elements.reserve(m_count);
205  int index = 0;
206  data->elements[0].x = m_points[index++];
207  data->elements[0].y = m_points[index++];
208 
209  if (m_elements) {
210  data->elements[0].type = m_elements[0];
211  for (int i=1; i<m_count; ++i) {
212  QPainterPath::Element element;
213  element.x = m_points[index++];
214  element.y = m_points[index++];
215  element.type = m_elements[i];
216  data->elements << element;
217  }
218  } else {
219  data->elements[0].type = QPainterPath::MoveToElement;
220  for (int i=1; i<m_count; ++i) {
221  QPainterPath::Element element;
222  element.x = m_points[index++];
223  element.y = m_points[index++];
225  data->elements << element;
226  }
227  }
228 
229  if (m_hints & OddEvenFill)
230  data->fillRule = Qt::OddEvenFill;
231  else
232  data->fillRule = Qt::WindingFill;
233  return path;
234 }
235 
237  QPointF* startPoint, QPointF *endPoint);
238 
239 inline bool QPainterPathData::isClosed() const
240 {
241  const QPainterPath::Element &first = elements.at(cStart);
242  const QPainterPath::Element &last = elements.last();
243  return first.x == last.x && first.y == last.y;
244 }
245 
247 {
248  Q_ASSERT(ref == 1);
249  require_moveTo = true;
250  const QPainterPath::Element &first = elements.at(cStart);
251  QPainterPath::Element &last = elements.last();
252  if (first.x != last.x || first.y != last.y) {
253  if (qFuzzyCompare(first.x, last.x) && qFuzzyCompare(first.y, last.y)) {
254  last.x = first.x;
255  last.y = first.y;
256  } else {
258  elements << e;
259  }
260  }
261 }
262 
264 {
265  if (require_moveTo) {
266  QPainterPath::Element e = elements.last();
268  elements.append(e);
269  require_moveTo = false;
270  }
271 }
272 
273 #define KAPPA qreal(0.5522847498)
274 
275 
277 
278 #endif // QPAINTERPATH_P_H
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
QVarLengthArray< QPainterPath::ElementType > elements
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QVectorPathConverter * pathConverter
const QVectorPath & vectorPath()
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
FillRule
Definition: qnamespace.h:1485
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< qfixed > dashPattern
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
QPainterPathData(const QPainterPathData &other)
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
const QVectorPath & vectorPath()
QVectorPathData(const QVector< QPainterPath::Element > &path, uint fillRule, bool convex)
const QPainterPath convertToPainterPath() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
qreal angle(const QPointF &p1, const QPointF &p2)
Qt::FillRule fillRule
Definition: qnamespace.h:54
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
quint16 index
static const QTextHtmlElement elements[Html_NumElements]
QVectorPathConverter(const QVector< QPainterPath::Element > &path, uint fillRule, bool convex)
bool isClosed() const
QVectorPathData pathData
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, QPointF *startPoint, QPointF *endPoint)