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