1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QPOLYGON_H
41#define QPOLYGON_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qvector.h>
45#include <QtCore/qpoint.h>
46#include <QtCore/qrect.h>
47
48QT_BEGIN_NAMESPACE
49
50
51class QMatrix;
52class QTransform;
53class QRect;
54class QVariant;
55
56class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
57{
58public:
59 inline QPolygon() {}
60 inline ~QPolygon() {}
61 inline explicit QPolygon(int size);
62 inline /*implicit*/ QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
63#ifdef Q_COMPILER_RVALUE_REFS
64 /*implicit*/ QPolygon(QVector<QPoint> &&v) Q_DECL_NOTHROW : QVector<QPoint>(std::move(v)) {}
65#endif
66 QPolygon(const QRect &r, bool closed=false);
67 QPolygon(int nPoints, const int *points);
68 QPolygon(const QPolygon &other) : QVector<QPoint>(other) {}
69#ifdef Q_COMPILER_RVALUE_REFS
70 QPolygon(QPolygon &&other) Q_DECL_NOTHROW : QVector<QPoint>(std::move(other)) {}
71 QPolygon &operator=(QPolygon &&other) Q_DECL_NOTHROW { swap(other); return *this; }
72#endif
73 QPolygon &operator=(const QPolygon &other) { QVector<QPoint>::operator=(other); return *this; }
74 void swap(QPolygon &other) Q_DECL_NOTHROW { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
75
76 operator QVariant() const;
77
78 void translate(int dx, int dy);
79 void translate(const QPoint &offset);
80
81 Q_REQUIRED_RESULT QPolygon translated(int dx, int dy) const;
82 Q_REQUIRED_RESULT inline QPolygon translated(const QPoint &offset) const;
83
84 QRect boundingRect() const;
85
86 void point(int i, int *x, int *y) const;
87 QPoint point(int i) const;
88 void setPoint(int index, int x, int y);
89 void setPoint(int index, const QPoint &p);
90 void setPoints(int nPoints, const int *points);
91 void setPoints(int nPoints, int firstx, int firsty, ...);
92 void putPoints(int index, int nPoints, const int *points);
93 void putPoints(int index, int nPoints, int firstx, int firsty, ...);
94 void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
95
96 bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
97
98 Q_REQUIRED_RESULT QPolygon united(const QPolygon &r) const;
99 Q_REQUIRED_RESULT QPolygon intersected(const QPolygon &r) const;
100 Q_REQUIRED_RESULT QPolygon subtracted(const QPolygon &r) const;
101
102 bool intersects(const QPolygon &r) const;
103};
104Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygon)
105
106inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
107
108#ifndef QT_NO_DEBUG_STREAM
109Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
110#endif
111
112/*****************************************************************************
113 QPolygon stream functions
114 *****************************************************************************/
115#ifndef QT_NO_DATASTREAM
116Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
117Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
118#endif
119
120/*****************************************************************************
121 Misc. QPolygon functions
122 *****************************************************************************/
123
124inline void QPolygon::setPoint(int index, const QPoint &pt)
125{ (*this)[index] = pt; }
126
127inline void QPolygon::setPoint(int index, int x, int y)
128{ (*this)[index] = QPoint(x, y); }
129
130inline QPoint QPolygon::point(int index) const
131{ return at(index); }
132
133inline void QPolygon::translate(const QPoint &offset)
134{ translate(offset.x(), offset.y()); }
135
136inline QPolygon QPolygon::translated(const QPoint &offset) const
137{ return translated(offset.x(), offset.y()); }
138
139class QRectF;
140
141class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
142{
143public:
144 inline QPolygonF() {}
145 inline ~QPolygonF() {}
146 inline explicit QPolygonF(int size);
147 inline /*implicit*/ QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
148#ifdef Q_COMPILER_RVALUE_REFS
149 /* implicit */ QPolygonF(QVector<QPointF> &&v) Q_DECL_NOTHROW : QVector<QPointF>(std::move(v)) {}
150#endif
151 QPolygonF(const QRectF &r);
152 /*implicit*/ QPolygonF(const QPolygon &a);
153 inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {}
154#ifdef Q_COMPILER_RVALUE_REFS
155 QPolygonF(QPolygonF &&other) Q_DECL_NOTHROW : QVector<QPointF>(std::move(other)) {}
156 QPolygonF &operator=(QPolygonF &&other) Q_DECL_NOTHROW { swap(other); return *this; }
157#endif
158 QPolygonF &operator=(const QPolygonF &other) { QVector<QPointF>::operator=(other); return *this; }
159 inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
160
161 operator QVariant() const;
162
163 inline void translate(qreal dx, qreal dy);
164 void translate(const QPointF &offset);
165
166 inline QPolygonF translated(qreal dx, qreal dy) const;
167 Q_REQUIRED_RESULT QPolygonF translated(const QPointF &offset) const;
168
169 QPolygon toPolygon() const;
170
171 bool isClosed() const { return !isEmpty() && first() == last(); }
172
173 QRectF boundingRect() const;
174
175 bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
176
177 Q_REQUIRED_RESULT QPolygonF united(const QPolygonF &r) const;
178 Q_REQUIRED_RESULT QPolygonF intersected(const QPolygonF &r) const;
179 Q_REQUIRED_RESULT QPolygonF subtracted(const QPolygonF &r) const;
180
181 bool intersects(const QPolygonF &r) const;
182};
183Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygonF)
184
185inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
186
187#ifndef QT_NO_DEBUG_STREAM
188Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
189#endif
190
191/*****************************************************************************
192 QPolygonF stream functions
193 *****************************************************************************/
194#ifndef QT_NO_DATASTREAM
195Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
196Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
197#endif
198
199inline void QPolygonF::translate(qreal dx, qreal dy)
200{ translate(QPointF(dx, dy)); }
201
202inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
203{ return translated(QPointF(dx, dy)); }
204
205QT_END_NAMESPACE
206
207#endif // QPOLYGON_H
208