1 /****************************************************************************
3 ** This file is based on sources of the Qt GUI Toolkit, used under the terms
4 ** of the GNU General Public License version 2 (see the original copyright
6 ** All further contributions to this file are (and are required to be)
7 ** licensed under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** The original Qt license header follows:
14 ** Definition of QRect class
18 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
20 ** This file is part of the kernel module of the Qt GUI Toolkit.
22 ** This file may be distributed under the terms of the Q Public License
23 ** as defined by Trolltech AS of Norway and appearing in the file
24 ** LICENSE.QPL included in the packaging of this file.
26 ** This file may be distributed and/or modified under the terms of the
27 ** GNU General Public License version 2 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file.
31 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
32 ** licenses may use this file in accordance with the Qt Commercial License
33 ** Agreement provided with the Software.
35 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
36 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
38 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
39 ** information about Qt Commercial License Agreements.
40 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
41 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
43 ** Contact info@trolltech.com if any conditions of this licensing are
46 **********************************************************************/
56 #error "Macro definition of topLeft conflicts with QRect"
57 // don't just silently undo people's defines: #undef topLeft
60 class Q_EXPORT QRect
// rectangle class
63 QRect() { x1
= y1
= 0; x2
= y2
= -1; }
64 QRect( const QPoint
&topleft
, const QPoint
&bottomright
);
65 QRect( const QPoint
&topleft
, const QSize
&size
);
66 QRect( int left
, int top
, int width
, int height
);
71 QRect
normalize() const;
85 void setLeft( int pos
);
86 void setTop( int pos
);
87 void setRight( int pos
);
88 void setBottom( int pos
);
92 void setTopLeft( const QPoint
&p
);
93 void setBottomRight( const QPoint
&p
);
94 void setTopRight( const QPoint
&p
);
95 void setBottomLeft( const QPoint
&p
);
97 QPoint
topLeft() const;
98 QPoint
bottomRight() const;
99 QPoint
topRight() const;
100 QPoint
bottomLeft() const;
101 QPoint
center() const;
103 void rect( int *x
, int *y
, int *w
, int *h
) const;
104 void coords( int *x1
, int *y1
, int *x2
, int *y2
) const;
106 void moveLeft( int pos
);
107 void moveTop( int pos
);
108 void moveRight( int pos
);
109 void moveBottom( int pos
);
110 void moveTopLeft( const QPoint
&p
);
111 void moveBottomRight( const QPoint
&p
);
112 void moveTopRight( const QPoint
&p
);
113 void moveBottomLeft( const QPoint
&p
);
114 void moveCenter( const QPoint
&p
);
115 void moveBy( int dx
, int dy
);
117 void setRect( int x
, int y
, int w
, int h
);
118 void setCoords( int x1
, int y1
, int x2
, int y2
);
119 void addCoords( int x1
, int y1
, int x2
, int y2
);
124 void setWidth( int w
);
125 void setHeight( int h
);
126 void setSize( const QSize
&s
);
128 QRect
operator|(const QRect
&r
) const;
129 QRect
operator&(const QRect
&r
) const;
130 QRect
& operator|=(const QRect
&r
);
131 QRect
& operator&=(const QRect
&r
);
133 bool contains( const QPoint
&p
, bool proper
=false ) const;
134 bool contains( int x
, int y
) const; // inline methods, _don't_ merge these
135 bool contains( int x
, int y
, bool proper
) const;
136 bool contains( const QRect
&r
, bool proper
=false ) const;
137 QRect
unite( const QRect
&r
) const;
138 QRect
intersect( const QRect
&r
) const;
139 bool intersects( const QRect
&r
) const;
141 friend Q_EXPORT
bool operator==( const QRect
&, const QRect
& );
142 friend Q_EXPORT
bool operator!=( const QRect
&, const QRect
& );
145 #if defined(Q_WS_X11) || defined(Q_OS_TEMP)
146 friend void qt_setCoords( QRect
*r
, int xp1
, int yp1
, int xp2
, int yp2
);
148 #if defined(Q_OS_MAC)
161 Q_EXPORT
bool operator==( const QRect
&, const QRect
& );
162 Q_EXPORT
bool operator!=( const QRect
&, const QRect
& );
165 /*****************************************************************************
166 QRect stream functions
167 *****************************************************************************/
168 #ifndef QT_NO_DATASTREAM
169 Q_EXPORT QDataStream
&operator<<( QDataStream
&, const QRect
& );
170 Q_EXPORT QDataStream
&operator>>( QDataStream
&, QRect
& );
173 /*****************************************************************************
174 QRect inline member functions
175 *****************************************************************************/
177 inline QRect::QRect( int left
, int top
, int width
, int height
)
181 x2
= (QCOORD
)(left
+width
-1);
182 y2
= (QCOORD
)(top
+height
-1);
185 inline bool QRect::isNull() const
186 { return x2
== x1
-1 && y2
== y1
-1; }
188 inline bool QRect::isEmpty() const
189 { return x1
> x2
|| y1
> y2
; }
191 inline bool QRect::isValid() const
192 { return x1
<= x2
&& y1
<= y2
; }
194 inline int QRect::left() const
197 inline int QRect::top() const
200 inline int QRect::right() const
203 inline int QRect::bottom() const
206 inline QCOORD
&QRect::rLeft()
209 inline QCOORD
& QRect::rTop()
212 inline QCOORD
& QRect::rRight()
215 inline QCOORD
& QRect::rBottom()
218 inline int QRect::x() const
221 inline int QRect::y() const
224 inline void QRect::setLeft( int pos
)
225 { x1
= (QCOORD
)pos
; }
227 inline void QRect::setTop( int pos
)
228 { y1
= (QCOORD
)pos
; }
230 inline void QRect::setRight( int pos
)
231 { x2
= (QCOORD
)pos
; }
233 inline void QRect::setBottom( int pos
)
234 { y2
= (QCOORD
)pos
; }
236 inline void QRect::setX( int x
)
239 inline void QRect::setY( int y
)
242 inline QPoint
QRect::topLeft() const
243 { return QPoint(x1
, y1
); }
245 inline QPoint
QRect::bottomRight() const
246 { return QPoint(x2
, y2
); }
248 inline QPoint
QRect::topRight() const
249 { return QPoint(x2
, y1
); }
251 inline QPoint
QRect::bottomLeft() const
252 { return QPoint(x1
, y2
); }
254 inline QPoint
QRect::center() const
255 { return QPoint((x1
+x2
)/2, (y1
+y2
)/2); }
257 inline int QRect::width() const
258 { return x2
- x1
+ 1; }
260 inline int QRect::height() const
261 { return y2
- y1
+ 1; }
263 inline QSize
QRect::size() const
264 { return QSize(x2
-x1
+1, y2
-y1
+1); }
266 inline bool QRect::contains( int x
, int y
, bool proper
) const
269 return x
> x1
&& x
< x2
&&
272 return x
>= x1
&& x
<= x2
&&
276 inline bool QRect::contains( int x
, int y
) const
278 return x
>= x1
&& x
<= x2
&&
281 #define Q_DEFINED_QRECT
282 #include "qwinexport.h"