1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QREGION_H |
5 | #define QREGION_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | #include <QtCore/qatomic.h> |
9 | #include <QtCore/qrect.h> |
10 | #include <QtGui/qwindowdefs.h> |
11 | #include <QtCore/qcontainerfwd.h> |
12 | |
13 | #ifndef QT_NO_DATASTREAM |
14 | #include <QtCore/qdatastream.h> |
15 | #endif |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | |
20 | class QVariant; |
21 | |
22 | struct QRegionPrivate; |
23 | |
24 | class QBitmap; |
25 | |
26 | class Q_GUI_EXPORT QRegion |
27 | { |
28 | public: |
29 | enum RegionType { Rectangle, Ellipse }; |
30 | |
31 | QRegion(); |
32 | QRegion(int x, int y, int w, int h, RegionType t = Rectangle); |
33 | QRegion(const QRect &r, RegionType t = Rectangle); |
34 | QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill); |
35 | QRegion(const QRegion ®ion); |
36 | QRegion(QRegion &&other) noexcept |
37 | : d(std::exchange(obj&: other.d, new_val: const_cast<QRegionData*>(&shared_empty))) {} |
38 | QRegion(const QBitmap &bitmap); |
39 | ~QRegion(); |
40 | QRegion &operator=(const QRegion &); |
41 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegion) |
42 | void swap(QRegion &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
43 | bool isEmpty() const; |
44 | bool isNull() const; |
45 | |
46 | typedef const QRect *const_iterator; |
47 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
48 | |
49 | const_iterator begin() const noexcept; |
50 | const_iterator cbegin() const noexcept { return begin(); } |
51 | const_iterator end() const noexcept; |
52 | const_iterator cend() const noexcept { return end(); } |
53 | const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } |
54 | const_reverse_iterator crbegin() const noexcept { return rbegin(); } |
55 | const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } |
56 | const_reverse_iterator crend() const noexcept { return rend(); } |
57 | |
58 | bool contains(const QPoint &p) const; |
59 | bool contains(const QRect &r) const; |
60 | |
61 | void translate(int dx, int dy); |
62 | inline void translate(const QPoint &p) { translate(dx: p.x(), dy: p.y()); } |
63 | [[nodiscard]] QRegion translated(int dx, int dy) const; |
64 | [[nodiscard]] inline QRegion translated(const QPoint &p) const { return translated(dx: p.x(), dy: p.y()); } |
65 | |
66 | [[nodiscard]] QRegion united(const QRegion &r) const; |
67 | [[nodiscard]] QRegion united(const QRect &r) const; |
68 | [[nodiscard]] QRegion intersected(const QRegion &r) const; |
69 | [[nodiscard]] QRegion intersected(const QRect &r) const; |
70 | [[nodiscard]] QRegion subtracted(const QRegion &r) const; |
71 | [[nodiscard]] QRegion xored(const QRegion &r) const; |
72 | |
73 | bool intersects(const QRegion &r) const; |
74 | bool intersects(const QRect &r) const; |
75 | |
76 | QRect boundingRect() const noexcept; |
77 | void setRects(const QRect *rect, int num); |
78 | int rectCount() const noexcept; |
79 | |
80 | QRegion operator|(const QRegion &r) const; |
81 | QRegion operator+(const QRegion &r) const; |
82 | QRegion operator+(const QRect &r) const; |
83 | QRegion operator&(const QRegion &r) const; |
84 | QRegion operator&(const QRect &r) const; |
85 | QRegion operator-(const QRegion &r) const; |
86 | QRegion operator^(const QRegion &r) const; |
87 | |
88 | QRegion& operator|=(const QRegion &r); |
89 | QRegion& operator+=(const QRegion &r); |
90 | QRegion& operator+=(const QRect &r); |
91 | QRegion& operator&=(const QRegion &r); |
92 | QRegion& operator&=(const QRect &r); |
93 | QRegion& operator-=(const QRegion &r); |
94 | QRegion& operator^=(const QRegion &r); |
95 | |
96 | bool operator==(const QRegion &r) const; |
97 | inline bool operator!=(const QRegion &r) const { return !(operator==(r)); } |
98 | operator QVariant() const; |
99 | |
100 | // Platform specific conversion functions |
101 | #if defined(Q_OS_WIN) || defined(Q_QDOC) |
102 | HRGN toHRGN() const; |
103 | static QRegion fromHRGN(HRGN hrgn); |
104 | #endif |
105 | |
106 | #ifndef QT_NO_DATASTREAM |
107 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); |
108 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); |
109 | #endif |
110 | private: |
111 | QRegion copy() const; // helper of detach. |
112 | void detach(); |
113 | Q_GUI_EXPORT |
114 | friend bool qt_region_strictContains(const QRegion ®ion, |
115 | const QRect &rect); |
116 | friend struct QRegionPrivate; |
117 | |
118 | #ifndef QT_NO_DATASTREAM |
119 | void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian); |
120 | #endif |
121 | struct QRegionData { |
122 | QtPrivate::RefCount ref; |
123 | QRegionPrivate *qt_rgn; |
124 | }; |
125 | struct QRegionData *d; |
126 | static const struct QRegionData shared_empty; |
127 | static void cleanUp(QRegionData *x); |
128 | }; |
129 | Q_DECLARE_SHARED(QRegion) |
130 | |
131 | /***************************************************************************** |
132 | QRegion stream functions |
133 | *****************************************************************************/ |
134 | |
135 | #ifndef QT_NO_DATASTREAM |
136 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); |
137 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); |
138 | #endif |
139 | |
140 | #ifndef QT_NO_DEBUG_STREAM |
141 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &); |
142 | #endif |
143 | |
144 | QT_END_NAMESPACE |
145 | |
146 | #endif // QREGION_H |
147 | |