- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qregion.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QREGION_H
    00043 #define QREGION_H
    00044
    00045 #include <QtCore/qatomic.h>
    00046 #include <QtCore/qrect.h>
    00047 #include <QtGui/qwindowdefs.h>
    00048
    00049 #ifndef QT_NO_DATASTREAM
    00050 #include <QtCore/qdatastream.h>
    00051 #endif
    00052
    00053 QT_BEGIN_HEADER
    00054
    00055 QT_BEGIN_NAMESPACE
    00056
    00057 QT_MODULE(Gui)
    00058
    00059 template <class T> class QVector;
    00060 class QVariant;
    00061
    00062 #if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
    00063 struct QRegionPrivate;
    00064 #endif
    00065
    00066 class QBitmap;
    00067
    00068 class Q_GUI_EXPORT QRegion
    00069 {
    00070 public:
    00071     enum RegionType { Rectangle, Ellipse };
    00072
    00073     QRegion();
    00074     QRegion(int x, int y, int w, int h, RegionType t = Rectangle);
    00075     QRegion(const QRect &r, RegionType t = Rectangle);
    00076     QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill);
    00077 #ifdef QT3_SUPPORT
    00078     QT3_SUPPORT_CONSTRUCTOR QRegion(const QPolygon &pa, bool winding);
    00079 #endif
    00080     QRegion(const QRegion &region);
    00081     QRegion(const QBitmap &bitmap);
    00082     ~QRegion();
    00083     QRegion &operator=(const QRegion &);
    00084
    00085 #ifdef QT3_SUPPORT
    00086     inline QT3_SUPPORT bool isNull() const { return isEmpty(); }
    00087 #endif
    00088     bool isEmpty() const;
    00089
    00090     bool contains(const QPoint &p) const;
    00091     bool contains(const QRect &r) const;
    00092
    00093     void translate(int dx, int dy);
    00094     inline void translate(const QPoint &p) { translate(p.x(), p.y()); }
    00095     QRegion translated(int dx, int dy) const;
    00096     inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); }
    00097
    00098     // ### Qt 5: make these four functions QT4_SUPPORT
    00099     QRegion unite(const QRegion &r) const;
    00100     QRegion unite(const QRect &r) const;
    00101     QRegion intersect(const QRegion &r) const;
    00102     QRegion intersect(const QRect &r) const;
    00103     QRegion subtract(const QRegion &r) const;
    00104     QRegion eor(const QRegion &r) const;
    00105
    00106     inline QRegion united(const QRegion &r) const { return unite(r); }
    00107     inline QRegion united(const QRect &r) const { return unite(r); }
    00108     inline QRegion intersected(const QRegion &r) const { return intersect(r); }
    00109     inline QRegion intersected(const QRect &r) const { return intersect(r); }
    00110     inline QRegion subtracted(const QRegion &r) const { return subtract(r); }
    00111     inline QRegion xored(const QRegion &r) const { return eor(r); }
    00112
    00113     bool intersects(const QRegion &r) const;
    00114     bool intersects(const QRect &r) const;
    00115
    00116     QRect boundingRect() const;
    00117     QVector<QRect> rects() const;
    00118     void setRects(const QRect *rect, int num);
    00119 #ifdef QT_DEPRECATED
    00120     QT_DEPRECATED int numRects() const;
    00121 #endif
    00122     int rectCount() const;
    00123
    00124     const QRegion operator|(const QRegion &r) const;
    00125     const QRegion operator+(const QRegion &r) const;
    00126     const QRegion operator+(const QRect &r) const;
    00127     const QRegion operator&(const QRegion &r) const;
    00128     const QRegion operator&(const QRect &r) const;
    00129     const QRegion operator-(const QRegion &r) const;
    00130     const QRegion operator^(const QRegion &r) const;
    00131     QRegion& operator|=(const QRegion &r);
    00132     QRegion& operator+=(const QRegion &r);
    00133     QRegion& operator+=(const QRect &r);
    00134     QRegion& operator&=(const QRegion &r);
    00135     QRegion& operator&=(const QRect &r);
    00136     QRegion& operator-=(const QRegion &r);
    00137     QRegion& operator^=(const QRegion &r);
    00138
    00139     bool operator==(const QRegion &r) const;
    00140     inline bool operator!=(const QRegion &r) const { return !(operator==(r)); }
    00141     operator QVariant() const;
    00142
    00143 #ifdef qdoc
    00144     Handle handle() const;
    00145 #endif
    00146 #ifndef qdoc
    00147 #if defined(Q_WS_WIN)
    00148     inline HRGN    handle() const { ensureHandle(); return d->rgn; }
    00149 #elif defined(Q_WS_X11)
    00150     inline Region handle() const { if(!d->rgn) updateX11Region(); return d->rgn; }
    00151 #elif defined(Q_WS_MAC)
    00152 #if defined Q_WS_MAC32
    00153     RgnHandle toQDRgn() const;
    00154     RgnHandle toQDRgnForUpdate_sys() const;
    00155     static QRegion fromQDRgn(RgnHandle shape);
    00156 #endif
    00157 #ifdef QT_MAC_USE_COCOA
    00158     inline HIMutableShapeRef handle(bool unused = false) const
    00159     { Q_UNUSED(unused); return toHIMutableShape(); }
    00160 #else
    00161     inline RgnHandle handle() const { return handle(false); }
    00162     inline RgnHandle handle(bool) const { return toQDRgn(); }
    00163 #endif
    00164     HIMutableShapeRef toHIMutableShape() const;
    00165     static QRegion fromHIShapeRef(HIShapeRef shape);
    00166 #elif defined(Q_WS_QWS)
    00167     inline void *handle() const { return d->qt_rgn; }
    00168 #endif
    00169 #endif
    00170
    00171 #ifndef QT_NO_DATASTREAM
    00172     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
    00173     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
    00174 #endif
    00175 private:
    00176     QRegion copy() const;   // helper of detach.
    00177     void detach();
    00178 #if defined(Q_WS_WIN)
    00179     void ensureHandle() const;
    00180     QRegion winCombine(const QRegion &r, int num) const;
    00181 #elif defined(Q_WS_X11)
    00182     void updateX11Region() const;
    00183     void *clipRectangles(int &num) const;
    00184     friend void *qt_getClipRects(const QRegion &r, int &num);
    00185 #elif defined(Q_WS_MAC)
    00186     static OSStatus shape2QRegionHelper(int inMessage, HIShapeRef inShape,
    00187                                         const CGRect *inRect, void *inRefcon);
    00188 #endif
    00189     friend bool qt_region_strictContains(const QRegion &region,
    00190                                          const QRect &rect);
    00191     friend struct QRegionPrivate;
    00192
    00193 #ifndef QT_NO_DATASTREAM
    00194     void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian);
    00195 #endif
    00196     struct QRegionData {
    00197         QBasicAtomicInt ref;
    00198 #if defined(Q_WS_WIN)
    00199         HRGN   rgn;
    00200 #elif defined(Q_WS_X11)
    00201         Region rgn;
    00202         void *xrectangles;
    00203 #elif defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
    00204         mutable RgnHandle unused; // Here for binary compatability reasons. ### Qt 5 remove.
    00205 #endif
    00206 #if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
    00207         QRegionPrivate *qt_rgn;
    00208 #endif
    00209     };
    00210 #if defined(Q_WS_WIN)
    00211     friend class QETWidget;
    00212 #endif
    00213     struct QRegionData *d;
    00214     static struct QRegionData shared_empty;
    00215     static void cleanUp(QRegionData *x);
    00216 };
    00217
    00218 /*****************************************************************************
    00219   QRegion stream functions
    00220  *****************************************************************************/
    00221
    00222 #ifndef QT_NO_DATASTREAM
    00223 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
    00224 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
    00225 #endif
    00226
    00227 #ifndef QT_NO_DEBUG_STREAM
    00228 Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);
    00229 #endif
    00230
    00231 QT_END_NAMESPACE
    00232
    00233 QT_END_HEADER
    00234
    00235 #endif // QREGION_H