| 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/qlist.h> |
| 45 | #include <QtCore/qpoint.h> |
| 46 | #include <QtCore/qrect.h> |
| 47 | |
| 48 | QT_BEGIN_NAMESPACE |
| 49 | |
| 50 | class QTransform; |
| 51 | class QRect; |
| 52 | class QVariant; |
| 53 | |
| 54 | // We export each out-of-line method invidually to prevent MSVC from |
| 55 | // exporting the whole QList class. |
| 56 | class QPolygon : public QList<QPoint> |
| 57 | { |
| 58 | public: |
| 59 | using QList<QPoint>::QList; |
| 60 | QPolygon() = default; |
| 61 | Q_IMPLICIT QPolygon(const QList<QPoint> &v) : QList<QPoint>(v) { } |
| 62 | Q_IMPLICIT QPolygon(QList<QPoint> &&v) noexcept : QList<QPoint>(std::move(v)) { } |
| 63 | Q_IMPLICIT Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false); |
| 64 | Q_GUI_EXPORT QPolygon(int nPoints, const int *points); |
| 65 | void swap(QPolygon &other) noexcept { QList<QPoint>::swap(other); } // prevent QList<QPoint><->QPolygon swaps |
| 66 | |
| 67 | Q_GUI_EXPORT operator QVariant() const; |
| 68 | |
| 69 | Q_GUI_EXPORT void translate(int dx, int dy); |
| 70 | void translate(const QPoint &offset); |
| 71 | |
| 72 | [[nodiscard]] Q_GUI_EXPORT QPolygon translated(int dx, int dy) const; |
| 73 | [[nodiscard]] inline QPolygon translated(const QPoint &offset) const; |
| 74 | |
| 75 | Q_GUI_EXPORT QRect boundingRect() const; |
| 76 | |
| 77 | Q_GUI_EXPORT void point(int i, int *x, int *y) const; |
| 78 | QPoint point(int i) const; |
| 79 | void setPoint(int index, int x, int y); |
| 80 | void setPoint(int index, const QPoint &p); |
| 81 | Q_GUI_EXPORT void setPoints(int nPoints, const int *points); |
| 82 | Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...); |
| 83 | Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points); |
| 84 | Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty, ...); |
| 85 | Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0); |
| 86 | |
| 87 | Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const; |
| 88 | |
| 89 | [[nodiscard]] Q_GUI_EXPORT QPolygon united(const QPolygon &r) const; |
| 90 | [[nodiscard]] Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const; |
| 91 | [[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const; |
| 92 | |
| 93 | Q_GUI_EXPORT bool intersects(const QPolygon &r) const; |
| 94 | }; |
| 95 | Q_DECLARE_SHARED(QPolygon) |
| 96 | |
| 97 | #ifndef QT_NO_DEBUG_STREAM |
| 98 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &); |
| 99 | #endif |
| 100 | |
| 101 | /***************************************************************************** |
| 102 | QPolygon stream functions |
| 103 | *****************************************************************************/ |
| 104 | #ifndef QT_NO_DATASTREAM |
| 105 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon); |
| 106 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon); |
| 107 | #endif |
| 108 | |
| 109 | /***************************************************************************** |
| 110 | Misc. QPolygon functions |
| 111 | *****************************************************************************/ |
| 112 | |
| 113 | inline void QPolygon::setPoint(int index, const QPoint &pt) |
| 114 | { (*this)[index] = pt; } |
| 115 | |
| 116 | inline void QPolygon::setPoint(int index, int x, int y) |
| 117 | { (*this)[index] = QPoint(x, y); } |
| 118 | |
| 119 | inline QPoint QPolygon::point(int index) const |
| 120 | { return at(index); } |
| 121 | |
| 122 | inline void QPolygon::translate(const QPoint &offset) |
| 123 | { translate(offset.x(), offset.y()); } |
| 124 | |
| 125 | inline QPolygon QPolygon::translated(const QPoint &offset) const |
| 126 | { return translated(offset.x(), offset.y()); } |
| 127 | |
| 128 | class QRectF; |
| 129 | |
| 130 | class QPolygonF : public QList<QPointF> |
| 131 | { |
| 132 | public: |
| 133 | using QList<QPointF>::QList; |
| 134 | QPolygonF() = default; |
| 135 | Q_IMPLICIT QPolygonF(const QList<QPointF> &v) : QList<QPointF>(v) { } |
| 136 | Q_IMPLICIT QPolygonF(QList<QPointF> &&v) noexcept : QList<QPointF>(std::move(v)) { } |
| 137 | Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r); |
| 138 | Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QPolygon &a); |
| 139 | inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps |
| 140 | |
| 141 | Q_GUI_EXPORT operator QVariant() const; |
| 142 | |
| 143 | inline void translate(qreal dx, qreal dy); |
| 144 | void Q_GUI_EXPORT translate(const QPointF &offset); |
| 145 | |
| 146 | inline QPolygonF translated(qreal dx, qreal dy) const; |
| 147 | [[nodiscard]] Q_GUI_EXPORT QPolygonF translated(const QPointF &offset) const; |
| 148 | |
| 149 | QPolygon Q_GUI_EXPORT toPolygon() const; |
| 150 | |
| 151 | bool isClosed() const { return !isEmpty() && first() == last(); } |
| 152 | |
| 153 | QRectF Q_GUI_EXPORT boundingRect() const; |
| 154 | |
| 155 | Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const; |
| 156 | |
| 157 | [[nodiscard]] Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const; |
| 158 | [[nodiscard]] Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const; |
| 159 | [[nodiscard]] Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const; |
| 160 | |
| 161 | Q_GUI_EXPORT bool intersects(const QPolygonF &r) const; |
| 162 | }; |
| 163 | Q_DECLARE_SHARED(QPolygonF) |
| 164 | |
| 165 | #ifndef QT_NO_DEBUG_STREAM |
| 166 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &); |
| 167 | #endif |
| 168 | |
| 169 | /***************************************************************************** |
| 170 | QPolygonF stream functions |
| 171 | *****************************************************************************/ |
| 172 | #ifndef QT_NO_DATASTREAM |
| 173 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array); |
| 174 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array); |
| 175 | #endif |
| 176 | |
| 177 | inline void QPolygonF::translate(qreal dx, qreal dy) |
| 178 | { translate(QPointF(dx, dy)); } |
| 179 | |
| 180 | inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const |
| 181 | { return translated(QPointF(dx, dy)); } |
| 182 | |
| 183 | QT_END_NAMESPACE |
| 184 | |
| 185 | #endif // QPOLYGON_H |
| 186 | |