1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QREGION_H
43#define QREGION_H
44
45#include <QtCore/qatomic.h>
46#include <QtCore/qrect.h>
47#include <QtGui/qwindowdefs.h>
48
49#ifndef QT_NO_DATASTREAM
50#include <QtCore/qdatastream.h>
51#endif
52
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(Gui)
58
59template <class T> class QVector;
60class QVariant;
61
62#if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
63struct QRegionPrivate;
64#endif
65
66class QBitmap;
67
68class Q_GUI_EXPORT QRegion
69{
70public:
71 enum RegionType { Rectangle, Ellipse };
72
73 QRegion();
74 QRegion(int x, int y, int w, int h, RegionType t = Rectangle);
75 QRegion(const QRect &r, RegionType t = Rectangle);
76 QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill);
77#ifdef QT3_SUPPORT
78 QT3_SUPPORT_CONSTRUCTOR QRegion(const QPolygon &pa, bool winding);
79#endif
80 QRegion(const QRegion &region);
81 QRegion(const QBitmap &bitmap);
82 ~QRegion();
83 QRegion &operator=(const QRegion &);
84#ifdef Q_COMPILER_RVALUE_REFS
85 inline QRegion &operator=(QRegion &&other)
86 { qSwap(d, other.d); return *this; }
87#endif
88 inline void swap(QRegion &other) { qSwap(d, other.d); }
89#ifdef QT3_SUPPORT
90 inline QT3_SUPPORT bool isNull() const { return isEmpty(); }
91#endif
92 bool isEmpty() const;
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 QRegion translated(int dx, int dy) const;
100 inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); }
101
102 // ### Qt 5: make these four functions QT4_SUPPORT
103 QRegion unite(const QRegion &r) const;
104 QRegion unite(const QRect &r) const;
105 QRegion intersect(const QRegion &r) const;
106 QRegion intersect(const QRect &r) const;
107 QRegion subtract(const QRegion &r) const;
108 QRegion eor(const QRegion &r) const;
109
110 inline QRegion united(const QRegion &r) const { return unite(r); }
111 inline QRegion united(const QRect &r) const { return unite(r); }
112 inline QRegion intersected(const QRegion &r) const { return intersect(r); }
113 inline QRegion intersected(const QRect &r) const { return intersect(r); }
114 inline QRegion subtracted(const QRegion &r) const { return subtract(r); }
115 inline QRegion xored(const QRegion &r) const { return eor(r); }
116
117 bool intersects(const QRegion &r) const;
118 bool intersects(const QRect &r) const;
119
120 QRect boundingRect() const;
121 QVector<QRect> rects() const;
122 void setRects(const QRect *rect, int num);
123#ifdef QT_DEPRECATED
124 QT_DEPRECATED int numRects() const;
125#endif
126 int rectCount() const;
127
128 const QRegion operator|(const QRegion &r) const;
129 const QRegion operator+(const QRegion &r) const;
130 const QRegion operator+(const QRect &r) const;
131 const QRegion operator&(const QRegion &r) const;
132 const QRegion operator&(const QRect &r) const;
133 const QRegion operator-(const QRegion &r) const;
134 const QRegion operator^(const QRegion &r) const;
135 QRegion& operator|=(const QRegion &r);
136 QRegion& operator+=(const QRegion &r);
137 QRegion& operator+=(const QRect &r);
138 QRegion& operator&=(const QRegion &r);
139 QRegion& operator&=(const QRect &r);
140 QRegion& operator-=(const QRegion &r);
141 QRegion& operator^=(const QRegion &r);
142
143 bool operator==(const QRegion &r) const;
144 inline bool operator!=(const QRegion &r) const { return !(operator==(r)); }
145 operator QVariant() const;
146
147#ifdef qdoc
148 Handle handle() const;
149#endif
150#ifndef qdoc
151#if defined(Q_WS_WIN)
152 inline HRGN handle() const { ensureHandle(); return d->rgn; }
153#elif defined(Q_WS_X11)
154 inline Region handle() const { if(!d->rgn) updateX11Region(); return d->rgn; }
155#elif defined(Q_WS_MAC)
156#if defined Q_WS_MAC32
157 RgnHandle toQDRgn() const;
158 RgnHandle toQDRgnForUpdate_sys() const;
159 static QRegion fromQDRgn(RgnHandle shape);
160#endif
161#ifdef QT_MAC_USE_COCOA
162 inline HIMutableShapeRef handle(bool unused = false) const
163 { Q_UNUSED(unused); return toHIMutableShape(); }
164#else
165 inline RgnHandle handle() const { return handle(false); }
166 inline RgnHandle handle(bool) const { return toQDRgn(); }
167#endif
168 HIMutableShapeRef toHIMutableShape() const;
169 static QRegion fromHIShapeRef(HIShapeRef shape);
170#elif defined(Q_WS_QWS) || defined(Q_WS_QPA)
171 inline void *handle() const { return d->qt_rgn; }
172#endif
173#endif
174
175#ifndef QT_NO_DATASTREAM
176 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
177 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
178#endif
179private:
180 QRegion copy() const; // helper of detach.
181 void detach();
182#if defined(Q_WS_WIN)
183 void ensureHandle() const;
184 QRegion winCombine(const QRegion &r, int num) const;
185#elif defined(Q_WS_X11)
186 void updateX11Region() const;
187 void *clipRectangles(int &num) const;
188 friend void *qt_getClipRects(const QRegion &r, int &num);
189#elif defined(Q_WS_MAC)
190 static OSStatus shape2QRegionHelper(int inMessage, HIShapeRef inShape,
191 const CGRect *inRect, void *inRefcon);
192#endif
193 friend bool qt_region_strictContains(const QRegion &region,
194 const QRect &rect);
195 friend struct QRegionPrivate;
196
197#ifndef QT_NO_DATASTREAM
198 void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian);
199#endif
200 struct QRegionData {
201 QBasicAtomicInt ref;
202#if defined(Q_WS_WIN)
203 HRGN rgn;
204#elif defined(Q_WS_X11)
205 Region rgn;
206 void *xrectangles;
207#elif defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
208 mutable RgnHandle unused; // Here for binary compatibility reasons. ### Qt 5 remove.
209#endif
210#if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
211 QRegionPrivate *qt_rgn;
212#endif
213 };
214#if defined(Q_WS_WIN)
215 friend class QETWidget;
216#endif
217 struct QRegionData *d;
218 static struct QRegionData shared_empty;
219 static void cleanUp(QRegionData *x);
220};
221
222/*****************************************************************************
223 QRegion stream functions
224 *****************************************************************************/
225
226#ifndef QT_NO_DATASTREAM
227Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
228Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
229#endif
230
231#ifndef QT_NO_DEBUG_STREAM
232Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);
233#endif
234
235QT_END_NAMESPACE
236
237QT_END_HEADER
238
239#endif // QREGION_H
240