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 48 #ifndef QT_NO_DATASTREAM 49 #include <QtCore/qdatastream.h> 50 #endif 51 52 QT_BEGIN_NAMESPACE 53 54 55 template <class T> class QVector; 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); QRegion(QRegion && other)72 QRegion(QRegion &&other) noexcept 73 : d(other.d) { other.d = const_cast<QRegionData*>(&shared_empty); } 74 QRegion(const QBitmap &bitmap); 75 ~QRegion(); 76 QRegion &operator=(const QRegion &); 77 inline QRegion &operator=(QRegion &&other) noexcept 78 { qSwap(d, other.d); return *this; } swap(QRegion & other)79 inline void swap(QRegion &other) noexcept { qSwap(d, other.d); } 80 bool isEmpty() const; 81 bool isNull() const; 82 83 typedef const QRect *const_iterator; 84 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 85 86 const_iterator begin() const noexcept; cbegin()87 const_iterator cbegin() const noexcept { return begin(); } 88 const_iterator end() const noexcept; cend()89 const_iterator cend() const noexcept { return end(); } rbegin()90 const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } crbegin()91 const_reverse_iterator crbegin() const noexcept { return rbegin(); } rend()92 const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } crend()93 const_reverse_iterator crend() const noexcept { return rend(); } 94 95 bool contains(const QPoint &p) const; 96 bool contains(const QRect &r) const; 97 98 void translate(int dx, int dy); translate(const QPoint & p)99 inline void translate(const QPoint &p) { translate(p.x(), p.y()); } 100 Q_REQUIRED_RESULT QRegion translated(int dx, int dy) const; translated(const QPoint & p)101 Q_REQUIRED_RESULT inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); } 102 103 Q_REQUIRED_RESULT QRegion united(const QRegion &r) const; 104 Q_REQUIRED_RESULT QRegion united(const QRect &r) const; 105 Q_REQUIRED_RESULT QRegion intersected(const QRegion &r) const; 106 Q_REQUIRED_RESULT QRegion intersected(const QRect &r) const; 107 Q_REQUIRED_RESULT QRegion subtracted(const QRegion &r) const; 108 Q_REQUIRED_RESULT QRegion xored(const QRegion &r) const; 109 110 #if QT_DEPRECATED_SINCE(5, 0) unite(const QRegion & r)111 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion unite(const QRegion &r) const { return united(r); } unite(const QRect & r)112 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion unite(const QRect &r) const { return united(r); } intersect(const QRegion & r)113 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion intersect(const QRegion &r) const { return intersected(r); } intersect(const QRect & r)114 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion intersect(const QRect &r) const { return intersected(r); } subtract(const QRegion & r)115 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion subtract(const QRegion &r) const { return subtracted(r); } eor(const QRegion & r)116 Q_REQUIRED_RESULT inline QT_DEPRECATED QRegion eor(const QRegion &r) const { return xored(r); } 117 #endif 118 119 bool intersects(const QRegion &r) const; 120 bool intersects(const QRect &r) const; 121 122 QRect boundingRect() const noexcept; 123 #if QT_DEPRECATED_SINCE(5, 11) 124 QT_DEPRECATED_X("Use begin()/end() instead") 125 QVector<QRect> rects() const; 126 #endif 127 void setRects(const QRect *rect, int num); 128 int rectCount() const noexcept; 129 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE 130 // ### Qt 6: remove these, they're kept for MSVC compat 131 const QRegion operator|(const QRegion &r) const; 132 const QRegion operator+(const QRegion &r) const; 133 const QRegion operator+(const QRect &r) const; 134 const QRegion operator&(const QRegion &r) const; 135 const QRegion operator&(const QRect &r) const; 136 const QRegion operator-(const QRegion &r) const; 137 const QRegion operator^(const QRegion &r) const; 138 #else 139 QRegion operator|(const QRegion &r) const; 140 QRegion operator+(const QRegion &r) const; 141 QRegion operator+(const QRect &r) const; 142 QRegion operator&(const QRegion &r) const; 143 QRegion operator&(const QRect &r) const; 144 QRegion operator-(const QRegion &r) const; 145 QRegion operator^(const QRegion &r) const; 146 #endif // Q_COMPILER_MANGLES_RETURN_TYPE 147 QRegion& operator|=(const QRegion &r); 148 QRegion& operator+=(const QRegion &r); 149 QRegion& operator+=(const QRect &r); 150 QRegion& operator&=(const QRegion &r); 151 QRegion& operator&=(const QRect &r); 152 QRegion& operator-=(const QRegion &r); 153 QRegion& operator^=(const QRegion &r); 154 155 bool operator==(const QRegion &r) const; 156 inline bool operator!=(const QRegion &r) const { return !(operator==(r)); } 157 operator QVariant() const; 158 159 #ifndef QT_NO_DATASTREAM 160 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); 161 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); 162 #endif 163 private: 164 QRegion copy() const; // helper of detach. 165 void detach(); 166 Q_GUI_EXPORT 167 friend bool qt_region_strictContains(const QRegion ®ion, 168 const QRect &rect); 169 friend struct QRegionPrivate; 170 171 #ifndef QT_NO_DATASTREAM 172 void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian); 173 #endif 174 struct QRegionData { 175 QtPrivate::RefCount ref; 176 QRegionPrivate *qt_rgn; 177 }; 178 struct QRegionData *d; 179 static const struct QRegionData shared_empty; 180 static void cleanUp(QRegionData *x); 181 }; 182 Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QRegion) 183 184 /***************************************************************************** 185 QRegion stream functions 186 *****************************************************************************/ 187 188 #ifndef QT_NO_DATASTREAM 189 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); 190 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); 191 #endif 192 193 #ifndef QT_NO_DEBUG_STREAM 194 Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &); 195 #endif 196 197 QT_END_NAMESPACE 198 199 #endif // QREGION_H 200