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 Qt3Support 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 | #include "q3pointarray.h"
|
---|
43 | #include "private/qbezier_p.h"
|
---|
44 | #include "private/qpainterpath_p.h"
|
---|
45 |
|
---|
46 | QT_BEGIN_NAMESPACE
|
---|
47 |
|
---|
48 | /*!
|
---|
49 | \class Q3PointArray
|
---|
50 | The Q3PointArray class provides an array of points.
|
---|
51 |
|
---|
52 | \compat
|
---|
53 |
|
---|
54 | Q3PointArray is a QPolygon subclass that provides functions
|
---|
55 | to make it more source compatible with the \c QPointArray class
|
---|
56 | in Qt 3.
|
---|
57 |
|
---|
58 | In Qt 4, we recommend that you use QPainterPath for representing
|
---|
59 | arcs, ellipses, and Bezier curves, rather than QPolygon.
|
---|
60 | */
|
---|
61 |
|
---|
62 | /*!
|
---|
63 | Sets the points of the array to those describing an arc of an
|
---|
64 | ellipse with size, width \a w by height \a h, and position (\a x,
|
---|
65 | \a y), starting from angle \a a1 and spanning by angle \a a2. The
|
---|
66 | resulting array has sufficient resolution for pixel accuracy (see
|
---|
67 | the overloaded function which takes an additional QMatrix
|
---|
68 | parameter).
|
---|
69 |
|
---|
70 | Angles are specified in 16ths of a degree, i.e. a full circle
|
---|
71 | equals 5760 (16*360). Positive values mean counter-clockwise,
|
---|
72 | whereas negative values mean the clockwise direction. Zero degrees
|
---|
73 | is at the 3 o'clock position.
|
---|
74 | */
|
---|
75 | #ifndef QT_NO_WMATRIX
|
---|
76 | void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2)
|
---|
77 | {
|
---|
78 | QRectF r(x, y, w, h);
|
---|
79 | QPointF startPoint;
|
---|
80 | qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
|
---|
81 |
|
---|
82 | QPainterPath path(startPoint);
|
---|
83 | path.arcTo(r, a1 / 16.0, a2 / 16.0);
|
---|
84 |
|
---|
85 | if (path.isEmpty())
|
---|
86 | *this = Q3PointArray();
|
---|
87 | else
|
---|
88 | *this = path.toSubpathPolygons().at(0).toPolygon();
|
---|
89 | }
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #ifndef QT_NO_TRANSFORMATIONS
|
---|
93 | /*!
|
---|
94 | \overload
|
---|
95 |
|
---|
96 | Sets the points of the array to those describing an arc of an
|
---|
97 | ellipse with width \a w and height \a h and position (\a x, \a y),
|
---|
98 | starting from angle \a a1, and spanning angle by \a a2, and
|
---|
99 | transformed by the matrix \a xf. The resulting array has
|
---|
100 | sufficient resolution for pixel accuracy.
|
---|
101 |
|
---|
102 | Angles are specified in 16ths of a degree, i.e. a full circle
|
---|
103 | equals 5760 (16 * 360). Positive values mean counter-clockwise,
|
---|
104 | whereas negative values mean the clockwise direction. Zero
|
---|
105 | degrees is at the 3 o'clock position.
|
---|
106 | */
|
---|
107 | void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2, const QMatrix &xf)
|
---|
108 | {
|
---|
109 | QRectF r(x, y, w, h);
|
---|
110 | QPointF startPoint;
|
---|
111 | qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
|
---|
112 |
|
---|
113 | QPainterPath path(startPoint);
|
---|
114 | path.arcTo(r, a1 / 16.0, a2 / 16.0);
|
---|
115 | path = path * xf;
|
---|
116 | if (path.isEmpty())
|
---|
117 | *this = Q3PointArray();
|
---|
118 | else
|
---|
119 | *this = path.toSubpathPolygons().at(0).toPolygon();
|
---|
120 | }
|
---|
121 |
|
---|
122 | #endif // QT_NO_TRANSFORMATIONS
|
---|
123 |
|
---|
124 | /*!
|
---|
125 | \fn Q3PointArray::Q3PointArray()
|
---|
126 |
|
---|
127 | Constructs an empty Q3PointArray.
|
---|
128 | */
|
---|
|
---|