Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksplash / ksplashx / qrect.h
blobeeb15981b5a482cc0bed01e14e6227143fbb64b1
1 /****************************************************************************
2 **
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
5 ** notice below).
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:
12 **
14 ** Definition of QRect class
16 ** Created : 931028
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
44 ** not clear to you.
46 **********************************************************************/
48 #ifndef QRECT_H
49 #define QRECT_H
51 #ifndef QT_H
52 #include "qsize.h"
53 #endif // QT_H
55 #if defined(topLeft)
56 #error "Macro definition of topLeft conflicts with QRect"
57 // don't just silently undo people's defines: #undef topLeft
58 #endif
60 class Q_EXPORT QRect // rectangle class
62 public:
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 );
68 bool isNull() const;
69 bool isEmpty() const;
70 bool isValid() const;
71 QRect normalize() const;
73 int left() const;
74 int top() const;
75 int right() const;
76 int bottom() const;
78 QCOORD &rLeft();
79 QCOORD &rTop();
80 QCOORD &rRight();
81 QCOORD &rBottom();
83 int x() const;
84 int y() const;
85 void setLeft( int pos );
86 void setTop( int pos );
87 void setRight( int pos );
88 void setBottom( int pos );
89 void setX( int x );
90 void setY( int y );
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 );
121 QSize size() const;
122 int width() const;
123 int height() const;
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 & );
144 private:
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 );
147 #endif
148 #if defined(Q_OS_MAC)
149 QCOORD y1;
150 QCOORD x1;
151 QCOORD y2;
152 QCOORD x2;
153 #else
154 QCOORD x1;
155 QCOORD y1;
156 QCOORD x2;
157 QCOORD y2;
158 #endif
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 & );
171 #endif
173 /*****************************************************************************
174 QRect inline member functions
175 *****************************************************************************/
177 inline QRect::QRect( int left, int top, int width, int height )
179 x1 = (QCOORD)left;
180 y1 = (QCOORD)top;
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
195 { return x1; }
197 inline int QRect::top() const
198 { return y1; }
200 inline int QRect::right() const
201 { return x2; }
203 inline int QRect::bottom() const
204 { return y2; }
206 inline QCOORD &QRect::rLeft()
207 { return x1; }
209 inline QCOORD & QRect::rTop()
210 { return y1; }
212 inline QCOORD & QRect::rRight()
213 { return x2; }
215 inline QCOORD & QRect::rBottom()
216 { return y2; }
218 inline int QRect::x() const
219 { return x1; }
221 inline int QRect::y() const
222 { return y1; }
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 )
237 { x1 = (QCOORD)x; }
239 inline void QRect::setY( int y )
240 { y1 = (QCOORD)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
268 if ( proper )
269 return x > x1 && x < x2 &&
270 y > y1 && y < y2;
271 else
272 return x >= x1 && x <= x2 &&
273 y >= y1 && y <= y2;
276 inline bool QRect::contains( int x, int y ) const
278 return x >= x1 && x <= x2 &&
279 y >= y1 && y <= y2;
281 #define Q_DEFINED_QRECT
282 #include "qwinexport.h"
283 #endif // QRECT_H