QtBase  v6.3.1
qregion.h
Go to the documentation of this file.
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 
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 
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) noexcept
73  : d(qExchange(other.d, const_cast<QRegionData*>(&shared_empty))) {}
78  void swap(QRegion &other) noexcept { qt_ptr_swap(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 
86  const_iterator cbegin() const noexcept { return begin(); }
87  const_iterator end() const noexcept;
88  const_iterator cend() const noexcept { return end(); }
90  const_reverse_iterator crbegin() const noexcept { return rbegin(); }
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 
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 &region,
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 {
159  QRegionPrivate *qt_rgn;
160  };
161  struct QRegionData *d;
162  static const struct QRegionData shared_empty;
163  static void cleanUp(QRegionData *x);
164 };
166 
167 /*****************************************************************************
168  QRegion stream functions
169  *****************************************************************************/
170 
171 #ifndef QT_NO_DATASTREAM
172 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
174 #endif
175 
176 #ifndef QT_NO_DEBUG_STREAM
177 Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);
178 #endif
179 
181 
182 #endif // QREGION_H
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:52
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QPolygon class provides a list of points using integer precision. \inmodule QtGui.
Definition: qpolygon.h:57
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
const QRect * const_iterator
Definition: qregion.h:82
Q_GUI_EXPORT friend bool qt_region_strictContains(const QRegion &region, const QRect &rect)
QRegion(const QRegion &region)
QRegion united(const QRegion &r) const
QRegion(const QRect &r, RegionType t=Rectangle)
QRect boundingRect() const noexcept
bool contains(const QRect &r) const
QRegion & operator=(const QRegion &)
void translate(int dx, int dy)
bool isNull() const
QRegion(const QPolygon &pa, Qt::FillRule fillRule=Qt::OddEvenFill)
bool contains(const QPoint &p) const
const_iterator end() const noexcept
QRegion(QRegion &&other) noexcept
Definition: qregion.h:72
QRegion intersected(const QRect &r) const
bool isEmpty() const
const_iterator begin() const noexcept
const_reverse_iterator rbegin() const noexcept
Definition: qregion.h:89
const_reverse_iterator crbegin() const noexcept
Definition: qregion.h:90
bool intersects(const QRect &r) const
QRegion xored(const QRegion &r) const
QRegion intersected(const QRegion &r) const
void translate(const QPoint &p)
Definition: qregion.h:98
RegionType
Definition: qregion.h:65
QRegion subtracted(const QRegion &r) const
QRegion(const QBitmap &bitmap)
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: qregion.h:83
QRegion united(const QRect &r) const
const_reverse_iterator rend() const noexcept
Definition: qregion.h:91
const_reverse_iterator crend() const noexcept
Definition: qregion.h:92
QRegion translated(const QPoint &p) const
Definition: qregion.h:100
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
msgBox exec()
rect
[4]
auto it unsigned count const
Definition: hb-iter.hh:848
#define inline
Definition: md4c.c:45
void cleanUp()
const PluginKeyMapConstIterator cend
FillRule
Definition: qnamespace.h:1320
@ OddEvenFill
Definition: qnamespace.h:1321
decltype(auto) cbegin(const T &t)
void
Definition: png.h:1080
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
GLint GLint GLint GLint GLint x
[0]
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLuint GLuint end
GLint ref
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
Definition: qopenglext.h:5182
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
GLuint num
Definition: qopenglext.h:5654
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QRegion &)
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QRegion &)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QByteArray ba
[0]
QSharedPointer< T > other(t)
[5]
this swap(other)