Eneboo - Documentación para desarrolladores
src/qt/include/qrect.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qrect.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QRect class
00005 **
00006 ** Created : 931028
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QRECT_H
00039 #define QRECT_H
00040 
00041 #ifndef QT_H
00042 #include "qsize.h"
00043 #endif // QT_H
00044 
00045 #if defined(topLeft)
00046 #error "Macro definition of topLeft conflicts with QRect"
00047 // don't just silently undo people's defines: #undef topLeft
00048 #endif
00049 
00050 class Q_EXPORT QRect                                    // rectangle class
00051 {
00052 public:
00053     QRect()     { x1 = y1 = 0; x2 = y2 = -1; }
00054     QRect( const QPoint &topleft, const QPoint &bottomright );
00055     QRect( const QPoint &topleft, const QSize &size );
00056     QRect( int left, int top, int width, int height );
00057 
00058     bool   isNull()     const;
00059     bool   isEmpty()    const;
00060     bool   isValid()    const;
00061     QRect  normalize()  const;
00062 
00063     int    left()       const;
00064     int    top()        const;
00065     int    right()      const;
00066     int    bottom()     const;
00067 
00068     QCOORD &rLeft();
00069     QCOORD &rTop();
00070     QCOORD &rRight();
00071     QCOORD &rBottom();
00072 
00073     int    x()          const;
00074     int    y()          const;
00075     void   setLeft( int pos );
00076     void   setTop( int pos );
00077     void   setRight( int pos );
00078     void   setBottom( int pos );
00079     void   setX( int x );
00080     void   setY( int y );
00081 
00082     void   setTopLeft( const QPoint &p );
00083     void   setBottomRight( const QPoint &p );
00084     void   setTopRight( const QPoint &p );
00085     void   setBottomLeft( const QPoint &p );
00086 
00087     QPoint topLeft()     const;
00088     QPoint bottomRight() const;
00089     QPoint topRight()    const;
00090     QPoint bottomLeft()  const;
00091     QPoint center()      const;
00092 
00093     void   rect( int *x, int *y, int *w, int *h ) const;
00094     void   coords( int *x1, int *y1, int *x2, int *y2 ) const;
00095 
00096     void   moveLeft( int pos );
00097     void   moveTop( int pos );
00098     void   moveRight( int pos );
00099     void   moveBottom( int pos );
00100     void   moveTopLeft( const QPoint &p );
00101     void   moveBottomRight( const QPoint &p );
00102     void   moveTopRight( const QPoint &p );
00103     void   moveBottomLeft( const QPoint &p );
00104     void   moveCenter( const QPoint &p );
00105     void   moveBy( int dx, int dy );
00106 
00107     void   setRect( int x, int y, int w, int h );
00108     void   setCoords( int x1, int y1, int x2, int y2 );
00109     void   addCoords( int x1, int y1, int x2, int y2 );
00110 
00111     QSize  size()       const;
00112     int    width()      const;
00113     int    height()     const;
00114     void   setWidth( int w );
00115     void   setHeight( int h );
00116     void   setSize( const QSize &s );
00117 
00118     QRect  operator|(const QRect &r) const;
00119     QRect  operator&(const QRect &r) const;
00120     QRect&  operator|=(const QRect &r);
00121     QRect&  operator&=(const QRect &r);
00122 
00123     bool   contains( const QPoint &p, bool proper=FALSE ) const;
00124     bool   contains( int x, int y ) const; // inline methods, _don't_ merge these
00125     bool   contains( int x, int y, bool proper ) const;
00126     bool   contains( const QRect &r, bool proper=FALSE ) const;
00127     QRect  unite( const QRect &r ) const;
00128     QRect  intersect( const QRect &r ) const;
00129     bool   intersects( const QRect &r ) const;
00130 
00131     friend Q_EXPORT bool operator==( const QRect &, const QRect & );
00132     friend Q_EXPORT bool operator!=( const QRect &, const QRect & );
00133 
00134 private:
00135 #if defined(Q_WS_X11) || defined(Q_OS_TEMP)
00136     friend void qt_setCoords( QRect *r, int xp1, int yp1, int xp2, int yp2 );
00137 #endif
00138 #if defined(Q_OS_MAC)
00139     QCOORD y1;
00140     QCOORD x1;
00141     QCOORD y2;
00142     QCOORD x2;
00143 #else
00144     QCOORD x1;
00145     QCOORD y1;
00146     QCOORD x2;
00147     QCOORD y2;
00148 #endif
00149 };
00150 
00151 Q_EXPORT bool operator==( const QRect &, const QRect & );
00152 Q_EXPORT bool operator!=( const QRect &, const QRect & );
00153 
00154 
00155 /*****************************************************************************
00156   QRect stream functions
00157  *****************************************************************************/
00158 #ifndef QT_NO_DATASTREAM
00159 Q_EXPORT QDataStream &operator<<( QDataStream &, const QRect & );
00160 Q_EXPORT QDataStream &operator>>( QDataStream &, QRect & );
00161 #endif
00162 
00163 /*****************************************************************************
00164   QRect inline member functions
00165  *****************************************************************************/
00166 
00167 inline QRect::QRect( int left, int top, int width, int height )
00168 {
00169     x1 = (QCOORD)left;
00170     y1 = (QCOORD)top;
00171     x2 = (QCOORD)(left+width-1);
00172     y2 = (QCOORD)(top+height-1);
00173 }
00174 
00175 inline bool QRect::isNull() const
00176 { return x2 == x1-1 && y2 == y1-1; }
00177 
00178 inline bool QRect::isEmpty() const
00179 { return x1 > x2 || y1 > y2; }
00180 
00181 inline bool QRect::isValid() const
00182 { return x1 <= x2 && y1 <= y2; }
00183 
00184 inline int QRect::left() const
00185 { return x1; }
00186 
00187 inline int QRect::top() const
00188 { return y1; }
00189 
00190 inline int QRect::right() const
00191 { return x2; }
00192 
00193 inline int QRect::bottom() const
00194 { return y2; }
00195 
00196 inline QCOORD &QRect::rLeft()
00197 { return x1; }
00198 
00199 inline QCOORD & QRect::rTop()
00200 { return y1; }
00201 
00202 inline QCOORD & QRect::rRight()
00203 { return x2; }
00204 
00205 inline QCOORD & QRect::rBottom()
00206 { return y2; }
00207 
00208 inline int QRect::x() const
00209 { return x1; }
00210 
00211 inline int QRect::y() const
00212 { return y1; }
00213 
00214 inline void QRect::setLeft( int pos )
00215 { x1 = (QCOORD)pos; }
00216 
00217 inline void QRect::setTop( int pos )
00218 { y1 = (QCOORD)pos; }
00219 
00220 inline void QRect::setRight( int pos )
00221 { x2 = (QCOORD)pos; }
00222 
00223 inline void QRect::setBottom( int pos )
00224 { y2 = (QCOORD)pos; }
00225 
00226 inline void QRect::setX( int x )
00227 { x1 = (QCOORD)x; }
00228 
00229 inline void QRect::setY( int y )
00230 { y1 = (QCOORD)y; }
00231 
00232 inline QPoint QRect::topLeft() const
00233 { return QPoint(x1, y1); }
00234 
00235 inline QPoint QRect::bottomRight() const
00236 { return QPoint(x2, y2); }
00237 
00238 inline QPoint QRect::topRight() const
00239 { return QPoint(x2, y1); }
00240 
00241 inline QPoint QRect::bottomLeft() const
00242 { return QPoint(x1, y2); }
00243 
00244 inline QPoint QRect::center() const
00245 { return QPoint((x1+x2)/2, (y1+y2)/2); }
00246 
00247 inline int QRect::width() const
00248 { return  x2 - x1 + 1; }
00249 
00250 inline int QRect::height() const
00251 { return  y2 - y1 + 1; }
00252 
00253 inline QSize QRect::size() const
00254 { return QSize(x2-x1+1, y2-y1+1); }
00255 
00256 inline bool QRect::contains( int x, int y, bool proper ) const
00257 {
00258     if ( proper )
00259         return x > x1 && x < x2 &&
00260                y > y1 && y < y2;
00261     else
00262         return x >= x1 && x <= x2 &&
00263                y >= y1 && y <= y2;
00264 }
00265 
00266 inline bool QRect::contains( int x, int y ) const
00267 {
00268     return x >= x1 && x <= x2 &&
00269            y >= y1 && y <= y2;
00270 }
00271 #define Q_DEFINED_QRECT
00272 #include "qwinexport.h"
00273 #endif // QRECT_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'