Rev 6159 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6144 | avox | 1 | /**************************************************************************** |
2 | ** $Id: frect.h 6144 2006-08-15 23:30:58Z avox $ |
||
3 | ** |
||
4 | ** Definition of FRect class |
||
5 | ** |
||
6 | ** Created : 931028 |
||
7 | ** |
||
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
||
9 | ** |
||
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. |
||
11 | ** |
||
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. |
||
15 | ** |
||
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. |
||
20 | ** |
||
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. |
||
24 | ** |
||
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. |
||
27 | ** |
||
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. |
||
32 | ** |
||
33 | ** Contact info@trolltech.com if any conditions of this licensing are |
||
34 | ** not clear to you. |
||
35 | ** |
||
36 | **********************************************************************/ |
||
37 | |||
38 | #ifndef FRECT_H |
||
39 | #define FRECT_H |
||
40 | |||
41 | //#ifndef QT_H |
||
42 | #include "fsize.h" |
||
43 | //#endif // QT_H |
||
44 | |||
45 | #if defined(topLeft) |
||
46 | #error "Macro definition of topLeft conflicts with FRect" |
||
47 | // don't just silently undo people's defines: #undef topLeft |
||
48 | #endif |
||
49 | |||
50 | class Q_EXPORT FRect // rectangle class |
||
51 | { |
||
52 | public: |
||
53 | FRect() { x1 = y1 = 0; x2 = y2 = -1; } |
||
54 | FRect( FPoint &topleft, FPoint &bottomright ); |
||
55 | FRect( FPoint &topleft, FSize &size ); |
||
56 | FRect( double left, double top, double width, double height ); |
||
57 | |||
58 | bool isNull() const; |
||
59 | bool isEmpty() const; |
||
60 | bool isValid() const; |
||
61 | FRect normalize() const; |
||
62 | |||
63 | double left() const; |
||
64 | double top() const; |
||
65 | double right() const; |
||
66 | double bottom() const; |
||
67 | |||
68 | double &rLeft(); |
||
69 | double &rTop(); |
||
70 | double &rRight(); |
||
71 | double &rBottom(); |
||
72 | |||
73 | double x() const; |
||
74 | double y() const; |
||
75 | void setLeft( double pos ); |
||
76 | void setTop( double pos ); |
||
77 | void setRight( double pos ); |
||
78 | void setBottom( double pos ); |
||
79 | void setX( double x ); |
||
80 | void setY( double y ); |
||
81 | |||
82 | void setTopLeft( FPoint &p ); |
||
83 | void setBottomRight( FPoint &p ); |
||
84 | void setTopRight( FPoint &p ); |
||
85 | void setBottomLeft( FPoint &p ); |
||
86 | |||
87 | FPoint topLeft() const; |
||
88 | FPoint bottomRight() const; |
||
89 | FPoint topRight() const; |
||
90 | FPoint bottomLeft() const; |
||
91 | FPoint center() const; |
||
92 | |||
93 | void rect( double *x, double *y, double *w, double *h ) const; |
||
94 | void coords( double *x1, double *y1, double *x2, double *y2 ) const; |
||
95 | |||
96 | void moveLeft( double pos ); |
||
97 | void moveTop( double pos ); |
||
98 | void moveRight( double pos ); |
||
99 | void moveBottom( double pos ); |
||
100 | void moveTopLeft( FPoint &p ); |
||
101 | void moveBottomRight( FPoint &p ); |
||
102 | void moveTopRight( FPoint &p ); |
||
103 | void moveBottomLeft( FPoint &p ); |
||
104 | void moveCenter( FPoint &p ); |
||
105 | void moveBy( double dx, double dy ); |
||
106 | |||
107 | void setRect( double x, double y, double w, double h ); |
||
108 | void setCoords( double x1, double y1, double x2, double y2 ); |
||
109 | void addCoords( double x1, double y1, double x2, double y2 ); |
||
110 | |||
111 | FSize size() const; |
||
112 | double width() const; |
||
113 | double height() const; |
||
114 | void setWidth( double w ); |
||
115 | void setHeight( double h ); |
||
116 | void setSize( const FSize &s ); |
||
117 | |||
118 | FRect operator|(const FRect &r) const; |
||
119 | FRect operator&(const FRect &r) const; |
||
120 | FRect& operator|=(const FRect &r); |
||
121 | FRect& operator&=(const FRect &r); |
||
122 | |||
123 | bool contains( FPoint &p, bool proper=FALSE ) const; |
||
124 | bool contains( double x, double y ) const; // inline methods, _don't_ merge these |
||
125 | bool contains( double x, double y, bool proper ) const; |
||
126 | bool contains( const FRect &r, bool proper=FALSE ) const; |
||
127 | FRect unite( const FRect &r ) const; |
||
128 | FRect intersect( const FRect &r ) const; |
||
129 | bool intersects( const FRect &r ) const; |
||
130 | |||
131 | friend Q_EXPORT bool operator==( const FRect &, const FRect & ); |
||
132 | friend Q_EXPORT bool operator!=( const FRect &, const FRect & ); |
||
133 | |||
134 | private: |
||
135 | #if defined(Q_WS_X11) || defined(Q_OS_TEMP) |
||
136 | friend void qt_setCoords( FRect *r, double xp1, double yp1, double xp2, double yp2 ); |
||
137 | #endif |
||
138 | |||
139 | double x1; |
||
140 | double y1; |
||
141 | double x2; |
||
142 | double y2; |
||
143 | |||
144 | }; |
||
145 | |||
146 | Q_EXPORT bool operator==( const FRect &, const FRect & ); |
||
147 | Q_EXPORT bool operator!=( const FRect &, const FRect & ); |
||
148 | |||
149 | |||
150 | /***************************************************************************** |
||
151 | FRect stream functions |
||
152 | *****************************************************************************/ |
||
153 | // #ifndef QT_NO_DATASTREAM |
||
154 | // Q_EXPORT QDataStream &operator<<( QDataStream &, const FRect & ); |
||
155 | // Q_EXPORT QDataStream &operator>>( QDataStream &, FRect & ); |
||
156 | // #endif |
||
157 | |||
158 | /***************************************************************************** |
||
159 | FRect inline member functions |
||
160 | *****************************************************************************/ |
||
161 | |||
162 | inline FRect::FRect( double left, double top, double width, double height ) |
||
163 | { |
||
164 | x1 = (double)left; |
||
165 | y1 = (double)top; |
||
166 | x2 = (double)(left+width-1); |
||
167 | y2 = (double)(top+height-1); |
||
168 | } |
||
169 | |||
170 | inline bool FRect::isNull() const |
||
171 | { return x2 == x1-1 && y2 == y1-1; } |
||
172 | |||
173 | inline bool FRect::isEmpty() const |
||
174 | { return x1 > x2 || y1 > y2; } |
||
175 | |||
176 | inline bool FRect::isValid() const |
||
177 | { return x1 <= x2 && y1 <= y2; } |
||
178 | |||
179 | inline double FRect::left() const |
||
180 | { return x1; } |
||
181 | |||
182 | inline double FRect::top() const |
||
183 | { return y1; } |
||
184 | |||
185 | inline double FRect::right() const |
||
186 | { return x2; } |
||
187 | |||
188 | inline double FRect::bottom() const |
||
189 | { return y2; } |
||
190 | |||
191 | inline double &FRect::rLeft() |
||
192 | { return x1; } |
||
193 | |||
194 | inline double & FRect::rTop() |
||
195 | { return y1; } |
||
196 | |||
197 | inline double & FRect::rRight() |
||
198 | { return x2; } |
||
199 | |||
200 | inline double & FRect::rBottom() |
||
201 | { return y2; } |
||
202 | |||
203 | inline double FRect::x() const |
||
204 | { return x1; } |
||
205 | |||
206 | inline double FRect::y() const |
||
207 | { return y1; } |
||
208 | |||
209 | inline void FRect::setLeft( double pos ) |
||
210 | { x1 = (double)pos; } |
||
211 | |||
212 | inline void FRect::setTop( double pos ) |
||
213 | { y1 = (double)pos; } |
||
214 | |||
215 | inline void FRect::setRight( double pos ) |
||
216 | { x2 = (double)pos; } |
||
217 | |||
218 | inline void FRect::setBottom( double pos ) |
||
219 | { y2 = (double)pos; } |
||
220 | |||
221 | inline void FRect::setX( double x ) |
||
222 | { x1 = (double)x; } |
||
223 | |||
224 | inline void FRect::setY( double y ) |
||
225 | { y1 = (double)y; } |
||
226 | |||
227 | inline FPoint FRect::topLeft() const |
||
228 | { return FPoint(x1, y1); } |
||
229 | |||
230 | inline FPoint FRect::bottomRight() const |
||
231 | { return FPoint(x2, y2); } |
||
232 | |||
233 | inline FPoint FRect::topRight() const |
||
234 | { return FPoint(x2, y1); } |
||
235 | |||
236 | inline FPoint FRect::bottomLeft() const |
||
237 | { return FPoint(x1, y2); } |
||
238 | |||
239 | inline FPoint FRect::center() const |
||
240 | { return FPoint((x1+x2)/2, (y1+y2)/2); } |
||
241 | |||
242 | inline double FRect::width() const |
||
243 | { return x2 - x1 + 1; } |
||
244 | |||
245 | inline double FRect::height() const |
||
246 | { return y2 - y1 + 1; } |
||
247 | |||
248 | inline FSize FRect::size() const |
||
249 | { return FSize(x2-x1+1, y2-y1+1); } |
||
250 | |||
251 | inline bool FRect::contains( double x, double y, bool proper ) const |
||
252 | { |
||
253 | if ( proper ) |
||
254 | return x > x1 && x < x2 && |
||
255 | y > y1 && y < y2; |
||
256 | else |
||
257 | return x >= x1 && x <= x2 && |
||
258 | y >= y1 && y <= y2; |
||
259 | } |
||
260 | |||
261 | inline bool FRect::contains( double x, double y ) const |
||
262 | { |
||
263 | return x >= x1 && x <= x2 && |
||
264 | y >= y1 && y <= y2; |
||
265 | } |
||
266 | // #define Q_DEFINED_QRECT |
||
267 | // #include "qwinexport.h" |
||
268 | #endif // QRECT_H |