1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPOLYGON_H
5#define QPOLYGON_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qpoint.h>
10#include <QtCore/qrect.h>
11
12QT_BEGIN_NAMESPACE
13
14class QTransform;
15class QRect;
16class QVariant;
17
18class QPolygonF;
19
20// We export each out-of-line method individually to prevent MSVC from
21// exporting the whole QList class.
22class QPolygon : public QList<QPoint>
23{
24public:
25 using QList<QPoint>::QList;
26 QPolygon() = default;
27 Q_IMPLICIT QPolygon(const QList<QPoint> &v) : QList<QPoint>(v) { }
28 Q_IMPLICIT QPolygon(QList<QPoint> &&v) noexcept : QList<QPoint>(std::move(v)) { }
29 Q_IMPLICIT Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false);
30 Q_GUI_EXPORT QPolygon(int nPoints, const int *points);
31 void swap(QPolygon &other) noexcept { QList<QPoint>::swap(other); } // prevent QList<QPoint><->QPolygon swaps
32
33 Q_GUI_EXPORT operator QVariant() const;
34
35 Q_GUI_EXPORT void translate(int dx, int dy);
36 void translate(const QPoint &offset);
37
38 [[nodiscard]] Q_GUI_EXPORT QPolygon translated(int dx, int dy) const;
39 [[nodiscard]] inline QPolygon translated(const QPoint &offset) const;
40
41 Q_GUI_EXPORT QRect boundingRect() const;
42
43 Q_GUI_EXPORT void point(int i, int *x, int *y) const;
44 QPoint point(int i) const;
45 Q_GUI_EXPORT void setPoint(int index, int x, int y);
46 inline void setPoint(int index, const QPoint &p);
47 Q_GUI_EXPORT void setPoints(int nPoints, const int *points);
48 Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...);
49 Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points);
50 Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty, ...);
51 Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
52
53 Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
54
55 [[nodiscard]] Q_GUI_EXPORT QPolygon united(const QPolygon &r) const;
56 [[nodiscard]] Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const;
57 [[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const;
58
59 Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
60
61 [[nodiscard]] inline QPolygonF toPolygonF() const;
62};
63Q_DECLARE_SHARED(QPolygon)
64
65#ifndef QT_NO_DEBUG_STREAM
66Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
67#endif
68
69/*****************************************************************************
70 QPolygon stream functions
71 *****************************************************************************/
72#ifndef QT_NO_DATASTREAM
73Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
74Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
75#endif
76
77/*****************************************************************************
78 Misc. QPolygon functions
79 *****************************************************************************/
80
81inline void QPolygon::setPoint(int index, const QPoint &pt)
82{ setPoint(index, x: pt.x(), y: pt.y()); }
83
84inline QPoint QPolygon::point(int index) const
85{ return at(i: index); }
86
87inline void QPolygon::translate(const QPoint &offset)
88{ translate(dx: offset.x(), dy: offset.y()); }
89
90inline QPolygon QPolygon::translated(const QPoint &offset) const
91{ return translated(dx: offset.x(), dy: offset.y()); }
92
93class QRectF;
94
95class QPolygonF : public QList<QPointF>
96{
97public:
98 using QList<QPointF>::QList;
99 QPolygonF() = default;
100 Q_IMPLICIT QPolygonF(const QList<QPointF> &v) : QList<QPointF>(v) { }
101 Q_IMPLICIT QPolygonF(QList<QPointF> &&v) noexcept : QList<QPointF>(std::move(v)) { }
102 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r);
103 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QPolygon &a);
104 inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps
105
106 Q_GUI_EXPORT operator QVariant() const;
107
108 inline void translate(qreal dx, qreal dy);
109 void Q_GUI_EXPORT translate(const QPointF &offset);
110
111 inline QPolygonF translated(qreal dx, qreal dy) const;
112 [[nodiscard]] Q_GUI_EXPORT QPolygonF translated(const QPointF &offset) const;
113
114 QPolygon Q_GUI_EXPORT toPolygon() const;
115
116 bool isClosed() const { return !isEmpty() && first() == last(); }
117
118 QRectF Q_GUI_EXPORT boundingRect() const;
119
120 Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
121
122 [[nodiscard]] Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const;
123 [[nodiscard]] Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const;
124 [[nodiscard]] Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const;
125
126 Q_GUI_EXPORT bool intersects(const QPolygonF &r) const;
127};
128Q_DECLARE_SHARED(QPolygonF)
129
130QPolygonF QPolygon::toPolygonF() const { return QPolygonF(*this); }
131
132#ifndef QT_NO_DEBUG_STREAM
133Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
134#endif
135
136/*****************************************************************************
137 QPolygonF stream functions
138 *****************************************************************************/
139#ifndef QT_NO_DATASTREAM
140Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
141Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
142#endif
143
144inline void QPolygonF::translate(qreal dx, qreal dy)
145{ translate(offset: QPointF(dx, dy)); }
146
147inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
148{ return translated(offset: QPointF(dx, dy)); }
149
150QT_END_NAMESPACE
151
152#endif // QPOLYGON_H
153

source code of qtbase/src/gui/painting/qpolygon.h