1
/****************************************************************************
4
** Definition of QRect class
8
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
10
** This file is part of the kernel module of the Qt GUI Toolkit.
12
** This file may be distributed under the terms of the Q Public License
13
** as defined by Trolltech AS of Norway and appearing in the file
14
** LICENSE.QPL included in the packaging of this file.
16
** This file may be distributed and/or modified under the terms of the
17
** GNU General Public License version 2 as published by the Free Software
18
** Foundation and appearing in the file LICENSE.GPL included in the
19
** packaging of this file.
21
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22
** licenses may use this file in accordance with the Qt Commercial License
23
** Agreement provided with the Software.
25
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29
** information about Qt Commercial License Agreements.
30
** See http://www.trolltech.com/qpl/ for QPL licensing information.
31
** See http://www.trolltech.com/gpl/ for GPL licensing information.
33
** Contact info@trolltech.com if any conditions of this licensing are
36
**********************************************************************/
46
#error "Macro definition of topLeft conflicts with QRect"
47
// don't just silently undo people's defines: #undef topLeft
50
class Q_EXPORT QRect // rectangle class
53
QRect() { x1 = y1 = 0; x2 = y2 = -1; }
54
QRect( const QPoint &topleft, const QPoint &bottomright );
55
QRect( const QPoint &topleft, const QSize &size );
56
QRect( int left, int top, int width, int height );
61
QRect normalize() const;
75
void setLeft( int pos );
76
void setTop( int pos );
77
void setRight( int pos );
78
void setBottom( int pos );
82
void setTopLeft( const QPoint &p );
83
void setBottomRight( const QPoint &p );
84
void setTopRight( const QPoint &p );
85
void setBottomLeft( const QPoint &p );
87
QPoint topLeft() const;
88
QPoint bottomRight() const;
89
QPoint topRight() const;
90
QPoint bottomLeft() const;
91
QPoint center() const;
93
void rect( int *x, int *y, int *w, int *h ) const;
94
void coords( int *x1, int *y1, int *x2, int *y2 ) const;
96
void moveLeft( int pos );
97
void moveTop( int pos );
98
void moveRight( int pos );
99
void moveBottom( int pos );
100
void moveTopLeft( const QPoint &p );
101
void moveBottomRight( const QPoint &p );
102
void moveTopRight( const QPoint &p );
103
void moveBottomLeft( const QPoint &p );
104
void moveCenter( const QPoint &p );
105
void moveBy( int dx, int dy );
107
void setRect( int x, int y, int w, int h );
108
void setCoords( int x1, int y1, int x2, int y2 );
109
void addCoords( int x1, int y1, int x2, int y2 );
114
void setWidth( int w );
115
void setHeight( int h );
116
void setSize( const QSize &s );
118
QRect operator|(const QRect &r) const;
119
QRect operator&(const QRect &r) const;
120
QRect& operator|=(const QRect &r);
121
QRect& operator&=(const QRect &r);
123
bool contains( const QPoint &p, bool proper=false ) const;
124
bool contains( int x, int y ) const; // inline methods, _don't_ merge these
125
bool contains( int x, int y, bool proper ) const;
126
bool contains( const QRect &r, bool proper=false ) const;
127
QRect unite( const QRect &r ) const;
128
QRect intersect( const QRect &r ) const;
129
bool intersects( const QRect &r ) const;
131
friend Q_EXPORT bool operator==( const QRect &, const QRect & );
132
friend Q_EXPORT bool operator!=( const QRect &, const QRect & );
135
#if defined(Q_WS_X11) || defined(Q_OS_TEMP)
136
friend void qt_setCoords( QRect *r, int xp1, int yp1, int xp2, int yp2 );
138
#if defined(Q_OS_MAC)
151
Q_EXPORT bool operator==( const QRect &, const QRect & );
152
Q_EXPORT bool operator!=( const QRect &, const QRect & );
155
/*****************************************************************************
156
QRect stream functions
157
*****************************************************************************/
158
#ifndef QT_NO_DATASTREAM
159
Q_EXPORT QDataStream &operator<<( QDataStream &, const QRect & );
160
Q_EXPORT QDataStream &operator>>( QDataStream &, QRect & );
163
/*****************************************************************************
164
QRect inline member functions
165
*****************************************************************************/
167
inline QRect::QRect( int left, int top, int width, int height )
171
x2 = (QCOORD)(left+width-1);
172
y2 = (QCOORD)(top+height-1);
175
inline bool QRect::isNull() const
176
{ return x2 == x1-1 && y2 == y1-1; }
178
inline bool QRect::isEmpty() const
179
{ return x1 > x2 || y1 > y2; }
181
inline bool QRect::isValid() const
182
{ return x1 <= x2 && y1 <= y2; }
184
inline int QRect::left() const
187
inline int QRect::top() const
190
inline int QRect::right() const
193
inline int QRect::bottom() const
196
inline QCOORD &QRect::rLeft()
199
inline QCOORD & QRect::rTop()
202
inline QCOORD & QRect::rRight()
205
inline QCOORD & QRect::rBottom()
208
inline int QRect::x() const
211
inline int QRect::y() const
214
inline void QRect::setLeft( int pos )
215
{ x1 = (QCOORD)pos; }
217
inline void QRect::setTop( int pos )
218
{ y1 = (QCOORD)pos; }
220
inline void QRect::setRight( int pos )
221
{ x2 = (QCOORD)pos; }
223
inline void QRect::setBottom( int pos )
224
{ y2 = (QCOORD)pos; }
226
inline void QRect::setX( int x )
229
inline void QRect::setY( int y )
232
inline QPoint QRect::topLeft() const
233
{ return QPoint(x1, y1); }
235
inline QPoint QRect::bottomRight() const
236
{ return QPoint(x2, y2); }
238
inline QPoint QRect::topRight() const
239
{ return QPoint(x2, y1); }
241
inline QPoint QRect::bottomLeft() const
242
{ return QPoint(x1, y2); }
244
inline QPoint QRect::center() const
245
{ return QPoint((x1+x2)/2, (y1+y2)/2); }
247
inline int QRect::width() const
248
{ return x2 - x1 + 1; }
250
inline int QRect::height() const
251
{ return y2 - y1 + 1; }
253
inline QSize QRect::size() const
254
{ return QSize(x2-x1+1, y2-y1+1); }
256
inline bool QRect::contains( int x, int y, bool proper ) const
259
return x > x1 && x < x2 &&
262
return x >= x1 && x <= x2 &&
266
inline bool QRect::contains( int x, int y ) const
268
return x >= x1 && x <= x2 &&
271
#define Q_DEFINED_QRECT
272
#include "qwinexport.h"