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 QPOLYGON_H
43#define QPOLYGON_H
44
45#include <QtCore/qvector.h>
46#include <QtCore/qpoint.h>
47#include <QtCore/qrect.h>
48
49QT_BEGIN_HEADER
50
51QT_BEGIN_NAMESPACE
52
53QT_MODULE(Gui)
54
55class QMatrix;
56class QTransform;
57class QRect;
58class QVariant;
59
60class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
61{
62public:
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
99inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
100
101#ifndef QT_NO_DEBUG_STREAM
102Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
103#endif
104
105/*****************************************************************************
106 QPolygon stream functions
107 *****************************************************************************/
108#ifndef QT_NO_DATASTREAM
109Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
110Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
111#endif
112
113/*****************************************************************************
114 Misc. QPolygon functions
115 *****************************************************************************/
116
117inline void QPolygon::setPoint(int index, const QPoint &pt)
118{ (*this)[index] = pt; }
119
120inline void QPolygon::setPoint(int index, int x, int y)
121{ (*this)[index] = QPoint(x, y); }
122
123inline QPoint QPolygon::point(int index) const
124{ return at(index); }
125
126inline void QPolygon::translate(const QPoint &offset)
127{ translate(offset.x(), offset.y()); }
128
129inline QPolygon QPolygon::translated(const QPoint &offset) const
130{ return translated(offset.x(), offset.y()); }
131
132class QRectF;
133
134class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
135{
136public:
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
165inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
166
167#ifndef QT_NO_DEBUG_STREAM
168Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
169#endif
170
171/*****************************************************************************
172 QPolygonF stream functions
173 *****************************************************************************/
174#ifndef QT_NO_DATASTREAM
175Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
176Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
177#endif
178
179inline void QPolygonF::translate(qreal dx, qreal dy)
180{ translate(QPointF(dx, dy)); }
181
182inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
183{ return translated(QPointF(dx, dy)); }
184
185QT_END_NAMESPACE
186
187QT_END_HEADER
188
189#endif // QPOLYGON_H
190