| 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 QREGION_H |
| 41 | #define QREGION_H |
| 42 | |
| 43 | #include <QtGui/qtguiglobal.h> |
| 44 | #include <QtCore/qatomic.h> |
| 45 | #include <QtCore/qrect.h> |
| 46 | #include <QtGui/qwindowdefs.h> |
| 47 | #include <QtCore/qcontainerfwd.h> |
| 48 | |
| 49 | #ifndef QT_NO_DATASTREAM |
| 50 | #include <QtCore/qdatastream.h> |
| 51 | #endif |
| 52 | |
| 53 | QT_BEGIN_NAMESPACE |
| 54 | |
| 55 | |
| 56 | class QVariant; |
| 57 | |
| 58 | struct QRegionPrivate; |
| 59 | |
| 60 | class QBitmap; |
| 61 | |
| 62 | class Q_GUI_EXPORT QRegion |
| 63 | { |
| 64 | public: |
| 65 | enum RegionType { Rectangle, Ellipse }; |
| 66 | |
| 67 | QRegion(); |
| 68 | QRegion(int x, int y, int w, int h, RegionType t = Rectangle); |
| 69 | QRegion(const QRect &r, RegionType t = Rectangle); |
| 70 | QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill); |
| 71 | QRegion(const QRegion ®ion); |
| 72 | QRegion(QRegion &&other) noexcept |
| 73 | : d(qExchange(other.d, const_cast<QRegionData*>(&shared_empty))) {} |
| 74 | QRegion(const QBitmap &bitmap); |
| 75 | ~QRegion(); |
| 76 | QRegion &operator=(const QRegion &); |
| 77 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegion); |
| 78 | inline void swap(QRegion &other) noexcept { qSwap(d, other.d); } |
| 79 | bool isEmpty() const; |
| 80 | bool isNull() const; |
| 81 | |
| 82 | typedef const QRect *const_iterator; |
| 83 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 84 | |
| 85 | const_iterator begin() const noexcept; |
| 86 | const_iterator cbegin() const noexcept { return begin(); } |
| 87 | const_iterator end() const noexcept; |
| 88 | const_iterator cend() const noexcept { return end(); } |
| 89 | const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } |
| 90 | const_reverse_iterator crbegin() const noexcept { return rbegin(); } |
| 91 | const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } |
| 92 | const_reverse_iterator crend() const noexcept { return rend(); } |
| 93 | |
| 94 | bool contains(const QPoint &p) const; |
| 95 | bool contains(const QRect &r) const; |
| 96 | |
| 97 | void translate(int dx, int dy); |
| 98 | inline void translate(const QPoint &p) { translate(p.x(), p.y()); } |
| 99 | [[nodiscard]] QRegion translated(int dx, int dy) const; |
| 100 | [[nodiscard]] inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); } |
| 101 | |
| 102 | [[nodiscard]] QRegion united(const QRegion &r) const; |
| 103 | [[nodiscard]] QRegion united(const QRect &r) const; |
| 104 | [[nodiscard]] QRegion intersected(const QRegion &r) const; |
| 105 | [[nodiscard]] QRegion intersected(const QRect &r) const; |
| 106 | [[nodiscard]] QRegion subtracted(const QRegion &r) const; |
| 107 | [[nodiscard]] QRegion xored(const QRegion &r) const; |
| 108 | |
| 109 | bool intersects(const QRegion &r) const; |
| 110 | bool intersects(const QRect &r) const; |
| 111 | |
| 112 | QRect boundingRect() const noexcept; |
| 113 | void setRects(const QRect *rect, int num); |
| 114 | int rectCount() const noexcept; |
| 115 | |
| 116 | QRegion operator|(const QRegion &r) const; |
| 117 | QRegion operator+(const QRegion &r) const; |
| 118 | QRegion operator+(const QRect &r) const; |
| 119 | QRegion operator&(const QRegion &r) const; |
| 120 | QRegion operator&(const QRect &r) const; |
| 121 | QRegion operator-(const QRegion &r) const; |
| 122 | QRegion operator^(const QRegion &r) const; |
| 123 | |
| 124 | QRegion& operator|=(const QRegion &r); |
| 125 | QRegion& operator+=(const QRegion &r); |
| 126 | QRegion& operator+=(const QRect &r); |
| 127 | QRegion& operator&=(const QRegion &r); |
| 128 | QRegion& operator&=(const QRect &r); |
| 129 | QRegion& operator-=(const QRegion &r); |
| 130 | QRegion& operator^=(const QRegion &r); |
| 131 | |
| 132 | bool operator==(const QRegion &r) const; |
| 133 | inline bool operator!=(const QRegion &r) const { return !(operator==(r)); } |
| 134 | operator QVariant() const; |
| 135 | |
| 136 | // Platform specific conversion functions |
| 137 | #if defined(Q_OS_WIN) || defined(Q_QDOC) |
| 138 | HRGN toHRGN() const; |
| 139 | static QRegion fromHRGN(HRGN hrgn); |
| 140 | #endif |
| 141 | |
| 142 | #ifndef QT_NO_DATASTREAM |
| 143 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); |
| 144 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); |
| 145 | #endif |
| 146 | private: |
| 147 | QRegion copy() const; // helper of detach. |
| 148 | void detach(); |
| 149 | Q_GUI_EXPORT |
| 150 | friend bool qt_region_strictContains(const QRegion ®ion, |
| 151 | const QRect &rect); |
| 152 | friend struct QRegionPrivate; |
| 153 | |
| 154 | #ifndef QT_NO_DATASTREAM |
| 155 | void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian); |
| 156 | #endif |
| 157 | struct QRegionData { |
| 158 | QtPrivate::RefCount ref; |
| 159 | QRegionPrivate *qt_rgn; |
| 160 | }; |
| 161 | struct QRegionData *d; |
| 162 | static const struct QRegionData shared_empty; |
| 163 | static void cleanUp(QRegionData *x); |
| 164 | }; |
| 165 | Q_DECLARE_SHARED(QRegion) |
| 166 | |
| 167 | /***************************************************************************** |
| 168 | QRegion stream functions |
| 169 | *****************************************************************************/ |
| 170 | |
| 171 | #ifndef QT_NO_DATASTREAM |
| 172 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); |
| 173 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); |
| 174 | #endif |
| 175 | |
| 176 | #ifndef QT_NO_DEBUG_STREAM |
| 177 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &); |
| 178 | #endif |
| 179 | |
| 180 | QT_END_NAMESPACE |
| 181 | |
| 182 | #endif // QREGION_H |
| 183 | |