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 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | class QMatrix; |
52 | class QTransform; |
53 | class QRect; |
54 | class QVariant; |
55 | |
56 | class Q_GUI_EXPORT QPolygon : public QVector<QPoint> |
57 | { |
58 | public: |
59 | inline QPolygon() {} |
60 | inline ~QPolygon() {} |
61 | inline explicit QPolygon(int size); |
62 | inline /*implicit*/ QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {} |
63 | /*implicit*/ QPolygon(QVector<QPoint> &&v) noexcept : QVector<QPoint>(std::move(v)) {} |
64 | QPolygon(const QRect &r, bool closed=false); |
65 | QPolygon(int nPoints, const int *points); |
66 | QPolygon(const QPolygon &other) : QVector<QPoint>(other) {} |
67 | QPolygon(QPolygon &&other) noexcept : QVector<QPoint>(std::move(other)) {} |
68 | QPolygon &operator=(QPolygon &&other) noexcept { swap(other); return *this; } |
69 | QPolygon &operator=(const QPolygon &other) { QVector<QPoint>::operator=(other); return *this; } |
70 | void swap(QPolygon &other) noexcept { 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 | Q_REQUIRED_RESULT QPolygon translated(int dx, int dy) const; |
78 | Q_REQUIRED_RESULT 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 | Q_REQUIRED_RESULT QPolygon united(const QPolygon &r) const; |
95 | Q_REQUIRED_RESULT QPolygon intersected(const QPolygon &r) const; |
96 | Q_REQUIRED_RESULT QPolygon subtracted(const QPolygon &r) const; |
97 | |
98 | bool intersects(const QPolygon &r) const; |
99 | }; |
100 | Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygon) |
101 | |
102 | inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {} |
103 | |
104 | #ifndef QT_NO_DEBUG_STREAM |
105 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &); |
106 | #endif |
107 | |
108 | /***************************************************************************** |
109 | QPolygon stream functions |
110 | *****************************************************************************/ |
111 | #ifndef QT_NO_DATASTREAM |
112 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon); |
113 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon); |
114 | #endif |
115 | |
116 | /***************************************************************************** |
117 | Misc. QPolygon functions |
118 | *****************************************************************************/ |
119 | |
120 | inline void QPolygon::setPoint(int index, const QPoint &pt) |
121 | { (*this)[index] = pt; } |
122 | |
123 | inline void QPolygon::setPoint(int index, int x, int y) |
124 | { (*this)[index] = QPoint(x, y); } |
125 | |
126 | inline QPoint QPolygon::point(int index) const |
127 | { return at(index); } |
128 | |
129 | inline void QPolygon::translate(const QPoint &offset) |
130 | { translate(offset.x(), offset.y()); } |
131 | |
132 | inline QPolygon QPolygon::translated(const QPoint &offset) const |
133 | { return translated(offset.x(), offset.y()); } |
134 | |
135 | class QRectF; |
136 | |
137 | class Q_GUI_EXPORT QPolygonF : public QVector<QPointF> |
138 | { |
139 | public: |
140 | inline QPolygonF() {} |
141 | inline ~QPolygonF() {} |
142 | inline explicit QPolygonF(int size); |
143 | inline /*implicit*/ QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {} |
144 | /* implicit */ QPolygonF(QVector<QPointF> &&v) noexcept : QVector<QPointF>(std::move(v)) {} |
145 | QPolygonF(const QRectF &r); |
146 | /*implicit*/ QPolygonF(const QPolygon &a); |
147 | inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {} |
148 | QPolygonF(QPolygonF &&other) noexcept : QVector<QPointF>(std::move(other)) {} |
149 | QPolygonF &operator=(QPolygonF &&other) noexcept { swap(other); return *this; } |
150 | QPolygonF &operator=(const QPolygonF &other) { QVector<QPointF>::operator=(other); return *this; } |
151 | inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps |
152 | |
153 | operator QVariant() const; |
154 | |
155 | inline void translate(qreal dx, qreal dy); |
156 | void translate(const QPointF &offset); |
157 | |
158 | inline QPolygonF translated(qreal dx, qreal dy) const; |
159 | Q_REQUIRED_RESULT QPolygonF translated(const QPointF &offset) const; |
160 | |
161 | QPolygon toPolygon() const; |
162 | |
163 | bool isClosed() const { return !isEmpty() && first() == last(); } |
164 | |
165 | QRectF boundingRect() const; |
166 | |
167 | bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const; |
168 | |
169 | Q_REQUIRED_RESULT QPolygonF united(const QPolygonF &r) const; |
170 | Q_REQUIRED_RESULT QPolygonF intersected(const QPolygonF &r) const; |
171 | Q_REQUIRED_RESULT QPolygonF subtracted(const QPolygonF &r) const; |
172 | |
173 | bool intersects(const QPolygonF &r) const; |
174 | }; |
175 | Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygonF) |
176 | |
177 | inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {} |
178 | |
179 | #ifndef QT_NO_DEBUG_STREAM |
180 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &); |
181 | #endif |
182 | |
183 | /***************************************************************************** |
184 | QPolygonF stream functions |
185 | *****************************************************************************/ |
186 | #ifndef QT_NO_DATASTREAM |
187 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array); |
188 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array); |
189 | #endif |
190 | |
191 | inline void QPolygonF::translate(qreal dx, qreal dy) |
192 | { translate(QPointF(dx, dy)); } |
193 | |
194 | inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const |
195 | { return translated(QPointF(dx, dy)); } |
196 | |
197 | QT_END_NAMESPACE |
198 | |
199 | #endif // QPOLYGON_H |
200 | |