1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qatomic.h>
46 #include <QtCore/qrect.h>
47 #include <QtGui/qwindowdefs.h>
49 #ifndef QT_NO_DATASTREAM
50 #include <QtCore/qdatastream.h>
59 template <class T> class QVector;
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)
63 struct QRegionPrivate;
68 class Q_GUI_EXPORT QRegion
71 enum RegionType { Rectangle, Ellipse };
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);
78 QT3_SUPPORT_CONSTRUCTOR QRegion(const QPolygon &pa, bool winding);
80 QRegion(const QRegion ®ion);
81 QRegion(const QBitmap &bitmap);
83 QRegion &operator=(const QRegion &);
84 #ifdef Q_COMPILER_RVALUE_REFS
85 inline QRegion &operator=(QRegion &&other)
86 { qSwap(d, other.d); return *this; }
88 inline void swap(QRegion &other) { qSwap(d, other.d); }
90 inline QT3_SUPPORT bool isNull() const { return isEmpty(); }
94 bool contains(const QPoint &p) const;
95 bool contains(const QRect &r) const;
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()); }
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;
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); }
117 bool intersects(const QRegion &r) const;
118 bool intersects(const QRect &r) const;
120 QRect boundingRect() const;
121 QVector<QRect> rects() const;
122 void setRects(const QRect *rect, int num);
124 QT_DEPRECATED int numRects() const;
126 int rectCount() const;
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);
143 bool operator==(const QRegion &r) const;
144 inline bool operator!=(const QRegion &r) const { return !(operator==(r)); }
145 operator QVariant() const;
148 Handle handle() const;
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);
161 #ifdef QT_MAC_USE_COCOA
162 inline HIMutableShapeRef handle(bool unused = false) const
163 { Q_UNUSED(unused); return toHIMutableShape(); }
165 inline RgnHandle handle() const { return handle(false); }
166 inline RgnHandle handle(bool) const { return toQDRgn(); }
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; }
175 #ifndef QT_NO_DATASTREAM
176 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
177 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
180 QRegion copy() const; // helper of 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);
193 friend bool qt_region_strictContains(const QRegion ®ion,
195 friend struct QRegionPrivate;
197 #ifndef QT_NO_DATASTREAM
198 void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian);
202 #if defined(Q_WS_WIN)
204 #elif defined(Q_WS_X11)
207 #elif defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
208 mutable RgnHandle unused; // Here for binary compatibility reasons. ### Qt 5 remove.
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;
214 #if defined(Q_WS_WIN)
215 friend class QETWidget;
217 struct QRegionData *d;
218 static struct QRegionData shared_empty;
219 static void cleanUp(QRegionData *x);
222 /*****************************************************************************
223 QRegion stream functions
224 *****************************************************************************/
226 #ifndef QT_NO_DATASTREAM
227 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
228 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
231 #ifndef QT_NO_DEBUG_STREAM
232 Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);