Qt 4.8
qregion.h
Go to the documentation of this file.
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 
54 
56 
57 QT_MODULE(Gui)
58 
59 template <class T> class QVector;
60 class 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)
63 struct QRegionPrivate;
64 #endif
65 
66 class QBitmap;
67 
69 {
70 public:
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
179 private:
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 {
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)
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
229 #endif
230 
231 #ifndef QT_NO_DEBUG_STREAM
233 #endif
234 
236 
238 
239 #endif // QREGION_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
timeval operator-(const timeval &t1, const timeval &t2)
Definition: qcore_unix_p.h:133
QRegion intersected(const QRegion &r) const
Returns a region which is the intersection of this region and r.
Definition: qregion.h:112
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
RegionType
Specifies the shape of the region to be created.
Definition: qregion.h:71
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QRegion translated(const QPoint &p) const
Returns a copy of the regtion that is translated {p}.
Definition: qregion.h:100
FillRule
Definition: qnamespace.h:1485
Q_GUI_EXPORT void * qt_getClipRects(const QRegion &r, int &num)
struct __HIShape * HIMutableShapeRef
struct _XRegion * Region
Definition: qwindowdefs.h:118
QRegionPrivate * qt_rgn
Definition: qregion.h:211
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
const struct __HIShape * HIShapeRef
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static const QRectF boundingRect(const QPointF *points, int pointCount)
Q_CORE_EXPORT QBitArray operator^(const QBitArray &, const QBitArray &)
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool operator!=(const QRegion &r) const
Returns true if this region is different from the other region; otherwise returns false...
Definition: qregion.h:144
static bool isEmpty(const char *str)
void translate(const QPoint &p)
Translates the region {point}.
Definition: qregion.h:98
The Rectangle item provides a filled rectangle with an optional border.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QRegion united(const QRegion &r) const
Returns a region which is the union of this region and r.
Definition: qregion.h:110
signed long OSStatus
QRegion united(const QRect &r) const
Returns a region which is the union of this region and the given rect.
Definition: qregion.h:111
struct OpaqueRgnHandle * RgnHandle
QRegion intersected(const QRect &r) const
Returns a region which is the intersection of this region and the given rect.
Definition: qregion.h:113
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QRegion &)
struct CGRect CGRect
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QRegion &)
Q_CORE_EXPORT QBitArray operator &(const QBitArray &, const QBitArray &)
Q_GUI_EXPORT bool qt_region_strictContains(const QRegion &region, const QRect &rect)
Returns true if rect is guaranteed to be fully contained in region.
Definition: qregion.cpp:4380
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
#define QT_DEPRECATED
Definition: qglobal.h:1094
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
Q_CORE_EXPORT QBitArray operator|(const QBitArray &, const QBitArray &)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
ByteOrder
The byte order used for reading/writing the data.
Definition: qdatastream.h:96
QRegion subtracted(const QRegion &r) const
Returns a region which is r subtracted from this region.
Definition: qregion.h:114
QRegion xored(const QRegion &r) const
Returns a region which is the exclusive or (XOR) of this region and r.
Definition: qregion.h:115
timeval & operator+=(timeval &t1, const timeval &t2)
Definition: qcore_unix_p.h:120
struct QRegionData * d
Definition: qregion.h:217
#define QT_END_HEADER
Definition: qglobal.h:137
void swap(QRegion &other)
Swaps region other with this region.
Definition: qregion.h:88
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
QBasicAtomicInt ref
Definition: qregion.h:201
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
timeval operator+(const timeval &t1, const timeval &t2)
Definition: qcore_unix_p.h:126