Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qpolygon.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QPOLYGON_H
43 #define QPOLYGON_H
44
45 #include <QtCore/qvector.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qrect.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 QT_MODULE(Gui)
54
55 class QMatrix;
56 class QTransform;
57 class QRect;
58 class QVariant;
59
60 class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
61 {
62 public:
63     inline QPolygon() {}
64     inline ~QPolygon() {}
65     inline QPolygon(int size);
66     inline QPolygon(const QPolygon &a) : QVector<QPoint>(a) {}
67     inline QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
68     QPolygon(const QRect &r, bool closed=false);
69     QPolygon(int nPoints, const int *points);
70     inline void swap(QPolygon &other) { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
71
72     operator QVariant() const;
73
74     void translate(int dx, int dy);
75     void translate(const QPoint &offset);
76
77     QPolygon translated(int dx, int dy) const;
78     inline QPolygon translated(const QPoint &offset) const;
79
80     QRect boundingRect() const;
81
82     void point(int i, int *x, int *y) const;
83     QPoint point(int i) const;
84     void setPoint(int index, int x, int y);
85     void setPoint(int index, const QPoint &p);
86     void setPoints(int nPoints, const int *points);
87     void setPoints(int nPoints, int firstx, int firsty, ...);
88     void putPoints(int index, int nPoints, const int *points);
89     void putPoints(int index, int nPoints, int firstx, int firsty, ...);
90     void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
91
92     bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
93
94     QPolygon united(const QPolygon &r) const;
95     QPolygon intersected(const QPolygon &r) const;
96     QPolygon subtracted(const QPolygon &r) const;
97 };
98
99 inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
100
101 #ifndef QT_NO_DEBUG_STREAM
102 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
103 #endif
104
105 /*****************************************************************************
106   QPolygon stream functions
107  *****************************************************************************/
108 #ifndef QT_NO_DATASTREAM
109 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
110 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
111 #endif
112
113 /*****************************************************************************
114   Misc. QPolygon functions
115  *****************************************************************************/
116
117 inline void QPolygon::setPoint(int index, const QPoint &pt)
118 { (*this)[index] = pt; }
119
120 inline void QPolygon::setPoint(int index, int x, int y)
121 { (*this)[index] = QPoint(x, y); }
122
123 inline QPoint QPolygon::point(int index) const
124 { return at(index); }
125
126 inline void QPolygon::translate(const QPoint &offset)
127 { translate(offset.x(), offset.y()); }
128
129 inline QPolygon QPolygon::translated(const QPoint &offset) const
130 { return translated(offset.x(), offset.y()); }
131
132 class QRectF;
133
134 class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
135 {
136 public:
137     inline QPolygonF() {}
138     inline ~QPolygonF() {}
139     inline QPolygonF(int size);
140     inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {}
141     inline QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
142     QPolygonF(const QRectF &r);
143     QPolygonF(const QPolygon &a);
144     inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
145
146     inline void translate(qreal dx, qreal dy);
147     void translate(const QPointF &offset);
148
149     inline QPolygonF translated(qreal dx, qreal dy) const;
150     QPolygonF translated(const QPointF &offset) const;
151
152     QPolygon toPolygon() const;
153
154     bool isClosed() const { return !isEmpty() && first() == last(); }
155
156     QRectF boundingRect() const;
157
158     bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
159
160     QPolygonF united(const QPolygonF &r) const;
161     QPolygonF intersected(const QPolygonF &r) const;
162     QPolygonF subtracted(const QPolygonF &r) const;
163 };
164
165 inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
166
167 #ifndef QT_NO_DEBUG_STREAM
168 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
169 #endif
170
171 /*****************************************************************************
172   QPolygonF stream functions
173  *****************************************************************************/
174 #ifndef QT_NO_DATASTREAM
175 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
176 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
177 #endif
178
179 inline void QPolygonF::translate(qreal dx, qreal dy)
180 { translate(QPointF(dx, dy)); }
181
182 inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
183 { return translated(QPointF(dx, dy)); }
184
185 QT_END_NAMESPACE
186
187 QT_END_HEADER
188
189 #endif // QPOLYGON_H