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

« back to all changes in this revision

Viewing changes to src/qt3support/painting/q3pointarray.cpp

  • 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 Qt 3 compatibility classes 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
#include "q3pointarray.h"
 
30
#include "private/qbezier_p.h"
 
31
#include "private/qpainterpath_p.h"
 
32
 
 
33
/*!
 
34
    \class Q3PointArray
 
35
    The Q3PointArray class provides an array of points.
 
36
 
 
37
    \compat
 
38
 
 
39
    Q3PointArray is a QPolygon subclass that provides functions
 
40
    to make it more source compatible with the \c QPointArray class
 
41
    in Qt 3.
 
42
 
 
43
    In Qt 4, we recommend that you use QPainterPath for representing
 
44
    arcs, ellipses, and Bezier curves, rather than QPolygon.
 
45
*/
 
46
 
 
47
/*!
 
48
    Sets the points of the array to those describing an arc of an
 
49
    ellipse with size, width \a w by height \a h, and position (\a x,
 
50
    \a y), starting from angle \a a1 and spanning by angle \a a2. The
 
51
    resulting array has sufficient resolution for pixel accuracy (see
 
52
    the overloaded function which takes an additional QMatrix
 
53
    parameter).
 
54
 
 
55
    Angles are specified in 16ths of a degree, i.e. a full circle
 
56
    equals 5760 (16*360). Positive values mean counter-clockwise,
 
57
    whereas negative values mean the clockwise direction. Zero degrees
 
58
    is at the 3 o'clock position.
 
59
*/
 
60
#ifndef QT_NO_WMATRIX
 
61
void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2)
 
62
{
 
63
    QRectF r(x, y, w, h);
 
64
    QPointF startPoint;
 
65
    qt_find_ellipse_coords(r, a1, a2, &startPoint, 0);
 
66
 
 
67
    QPainterPath path(startPoint);
 
68
    path.arcTo(r, a1, a2);
 
69
    *this = path.toSubpathPolygons().at(0).toPolygon();
 
70
}
 
71
#endif
 
72
 
 
73
#ifndef QT_NO_TRANSFORMATIONS
 
74
/*!
 
75
    \overload
 
76
 
 
77
    Sets the points of the array to those describing an arc of an
 
78
    ellipse with width \a w and height \a h and position (\a x, \a y),
 
79
    starting from angle \a a1, and spanning angle by \a a2, and
 
80
    transformed by the matrix \a xf. The resulting array has
 
81
    sufficient resolution for pixel accuracy.
 
82
 
 
83
    Angles are specified in 16ths of a degree, i.e. a full circle
 
84
    equals 5760 (16 * 360). Positive values mean counter-clockwise,
 
85
    whereas negative values mean the clockwise direction. Zero
 
86
    degrees is at the 3 o'clock position.
 
87
*/
 
88
void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2, const QMatrix &xf)
 
89
{
 
90
    QRectF r(x, y, w, h);
 
91
    QPointF startPoint;
 
92
    qt_find_ellipse_coords(r, a1, a2, &startPoint, 0);
 
93
 
 
94
    QPainterPath path(startPoint);
 
95
    path.arcTo(r, a1, a2);
 
96
    path = path * xf;
 
97
    *this = path.toSubpathPolygons().at(0).toPolygon();
 
98
}
 
99
 
 
100
#endif // QT_NO_TRANSFORMATIONS
 
101
 
 
102
/*!
 
103
    \fn Q3PointArray::Q3PointArray()
 
104
 
 
105
    Constructs an empty Q3PointArray.
 
106
*/
 
107
 
 
108
/*!
 
109
    \fn Q3PointArray::Q3PointArray(const QRect &r, bool closed)
 
110
 
 
111
    Constructs a point array from the rectangle \a r.
 
112
 
 
113
    If \a closed is false, then the point array just contains the
 
114
    following four points of the rectangle ordered clockwise. The
 
115
    bottom-right point is located at (r.x() + r.width(), r.y() +
 
116
    r.height()).
 
117
*/
 
118
 
 
119
/*!
 
120
    \fn Q3PointArray::Q3PointArray(const QPolygon& other)
 
121
 
 
122
    Constructs a copy of \a other.
 
123
*/
 
124
 
 
125
/*!
 
126
    \fn Q3PointArray Q3PointArray::copy() const
 
127
 
 
128
    Returns a copy of this Q3PointArray.
 
129
*/
 
130
 
 
131
/*!
 
132
    \fn bool Q3PointArray::isNull()
 
133
 
 
134
    Same as isEmpty().
 
135
*/
 
136
 
 
137
/*!
 
138
    Sets the points of the array to those describing an ellipse with
 
139
    size, width \a w by height \a h, and position (\a x, \a y).
 
140
 
 
141
    The returned array has sufficient resolution for use as pixels.
 
142
*/
 
143
void Q3PointArray::makeEllipse(int x, int y, int w, int h)
 
144
{
 
145
    QPainterPath path;
 
146
    path.addEllipse(x, y, w, h);
 
147
    *this = path.toSubpathPolygons().at(0).toPolygon();
 
148
}
 
149
 
 
150
#ifndef QT_NO_BEZIER
 
151
 
 
152
/*!
 
153
    Returns the Bezier points for the four control points in this
 
154
    array.
 
155
*/
 
156
Q3PointArray Q3PointArray::cubicBezier() const
 
157
{
 
158
    if (size() != 4) {
 
159
        qWarning( "Q3PointArray::bezier: The array must have 4 control points" );
 
160
        return QPolygon();
 
161
    }
 
162
    QPolygonF polygon = QBezier(at(0), at(1), at(2), at(3)).toPolygon();
 
163
    return polygon.toPolygon();
 
164
}
 
165
#endif //QT_NO_BEZIER