Rev 18204 | Rev 23705 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6144 | avox | 1 | /**************************************************************************** |
2 | ** $Id: frect.h 23700 2020-05-05 20:27:20Z craig $ |
||
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 | |||
6159 | jghali | 50 | class FRect // rectangle class |
6144 | avox | 51 | { |
52 | public: |
||
53 | FRect() { x1 = y1 = 0; x2 = y2 = -1; } |
||
54 | FRect( FPoint &topleft, FPoint &bottomright ); |
||
55 | FRect( FPoint &topleft, FSize &size ); |
||
13161 | malex | 56 | FRect( qreal left, qreal top, qreal width, qreal height ); |
6144 | avox | 57 | |
58 | bool isNull() const; |
||
59 | bool isEmpty() const; |
||
60 | bool isValid() const; |
||
61 | FRect normalize() const; |
||
62 | |||
13161 | malex | 63 | qreal left() const; |
64 | qreal top() const; |
||
65 | qreal right() const; |
||
66 | qreal bottom() const; |
||
6144 | avox | 67 | |
13161 | malex | 68 | qreal &rLeft(); |
69 | qreal &rTop(); |
||
70 | qreal &rRight(); |
||
71 | qreal &rBottom(); |
||
6144 | avox | 72 | |
13161 | malex | 73 | qreal x() const; |
74 | qreal y() const; |
||
75 | void setLeft( qreal pos ); |
||
76 | void setTop( qreal pos ); |
||
77 | void setRight( qreal pos ); |
||
78 | void setBottom( qreal pos ); |
||
79 | void setX( qreal x ); |
||
80 | void setY( qreal y ); |
||
6144 | avox | 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 | |||
13161 | malex | 93 | void rect( qreal *x, qreal *y, qreal *w, qreal *h ) const; |
23700 | craig | 94 | void coords( qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2 ) const; |
6144 | avox | 95 | |
13161 | malex | 96 | void moveLeft( qreal pos ); |
97 | void moveTop( qreal pos ); |
||
98 | void moveRight( qreal pos ); |
||
99 | void moveBottom( qreal pos ); |
||
6144 | avox | 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 ); |
||
13161 | malex | 105 | void moveBy( qreal dx, qreal dy ); |
6144 | avox | 106 | |
13161 | malex | 107 | void setRect( qreal x, qreal y, qreal w, qreal h ); |
23700 | craig | 108 | void setCoords( qreal xp1, qreal yp1, qreal xp2, qreal yp ); |
109 | void addCoords( qreal xp1, qreal yp1, qreal xp2, qreal yp2 ); |
||
6144 | avox | 110 | |
111 | FSize size() const; |
||
23700 | craig | 112 | qreal width() const; |
113 | qreal height() const; |
||
13161 | malex | 114 | void setWidth( qreal w ); |
115 | void setHeight( qreal h ); |
||
6144 | avox | 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 | |||
18194 | fschmid | 123 | bool contains( FPoint &p, bool proper=false ) const; |
13161 | malex | 124 | bool contains( qreal x, qreal y ) const; // inline methods, _don't_ merge these |
125 | bool contains( qreal x, qreal y, bool proper ) const; |
||
18194 | fschmid | 126 | bool contains( const FRect &r, bool proper=false ) const; |
6144 | avox | 127 | FRect unite( const FRect &r ) const; |
128 | FRect intersect( const FRect &r ) const; |
||
129 | bool intersects( const FRect &r ) const; |
||
130 | |||
6159 | jghali | 131 | friend bool operator==( const FRect &, const FRect & ); |
132 | friend bool operator!=( const FRect &, const FRect & ); |
||
6144 | avox | 133 | |
134 | private: |
||
18204 | fschmid | 135 | #if defined(Q_OS_LINUX) || defined(Q_OS_TEMP) |
13161 | malex | 136 | friend void qt_setCoords( FRect *r, qreal xp1, qreal yp1, qreal xp2, qreal yp2 ); |
6144 | avox | 137 | #endif |
138 | |||
13161 | malex | 139 | qreal x1; |
140 | qreal y1; |
||
141 | qreal x2; |
||
142 | qreal y2; |
||
6144 | avox | 143 | |
144 | }; |
||
145 | |||
6159 | jghali | 146 | bool operator==( const FRect &, const FRect & ); |
147 | bool operator!=( const FRect &, const FRect & ); |
||
6144 | avox | 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 | |||
13161 | malex | 162 | inline FRect::FRect( qreal left, qreal top, qreal width, qreal height ) |
6144 | avox | 163 | { |
13161 | malex | 164 | x1 = (qreal)left; |
165 | y1 = (qreal)top; |
||
166 | x2 = (qreal)(left+width-1); |
||
167 | y2 = (qreal)(top+height-1); |
||
6144 | avox | 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 | |||
13161 | malex | 179 | inline qreal FRect::left() const |
6144 | avox | 180 | { return x1; } |
181 | |||
13161 | malex | 182 | inline qreal FRect::top() const |
6144 | avox | 183 | { return y1; } |
184 | |||
13161 | malex | 185 | inline qreal FRect::right() const |
6144 | avox | 186 | { return x2; } |
187 | |||
13161 | malex | 188 | inline qreal FRect::bottom() const |
6144 | avox | 189 | { return y2; } |
190 | |||
13161 | malex | 191 | inline qreal &FRect::rLeft() |
6144 | avox | 192 | { return x1; } |
193 | |||
13161 | malex | 194 | inline qreal & FRect::rTop() |
6144 | avox | 195 | { return y1; } |
196 | |||
13161 | malex | 197 | inline qreal & FRect::rRight() |
6144 | avox | 198 | { return x2; } |
199 | |||
13161 | malex | 200 | inline qreal & FRect::rBottom() |
6144 | avox | 201 | { return y2; } |
202 | |||
13161 | malex | 203 | inline qreal FRect::x() const |
6144 | avox | 204 | { return x1; } |
205 | |||
13161 | malex | 206 | inline qreal FRect::y() const |
6144 | avox | 207 | { return y1; } |
208 | |||
13161 | malex | 209 | inline void FRect::setLeft( qreal pos ) |
210 | { x1 = (qreal)pos; } |
||
6144 | avox | 211 | |
13161 | malex | 212 | inline void FRect::setTop( qreal pos ) |
213 | { y1 = (qreal)pos; } |
||
6144 | avox | 214 | |
13161 | malex | 215 | inline void FRect::setRight( qreal pos ) |
216 | { x2 = (qreal)pos; } |
||
6144 | avox | 217 | |
13161 | malex | 218 | inline void FRect::setBottom( qreal pos ) |
219 | { y2 = (qreal)pos; } |
||
6144 | avox | 220 | |
13161 | malex | 221 | inline void FRect::setX( qreal x ) |
222 | { x1 = (qreal)x; } |
||
6144 | avox | 223 | |
13161 | malex | 224 | inline void FRect::setY( qreal y ) |
225 | { y1 = (qreal)y; } |
||
6144 | avox | 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 | |||
13161 | malex | 242 | inline qreal FRect::width() const |
6144 | avox | 243 | { return x2 - x1 + 1; } |
244 | |||
13161 | malex | 245 | inline qreal FRect::height() const |
6144 | avox | 246 | { return y2 - y1 + 1; } |
247 | |||
248 | inline FSize FRect::size() const |
||
249 | { return FSize(x2-x1+1, y2-y1+1); } |
||
250 | |||
13161 | malex | 251 | inline bool FRect::contains( qreal x, qreal y, bool proper ) const |
6144 | avox | 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 | |||
13161 | malex | 261 | inline bool FRect::contains( qreal x, qreal y ) const |
6144 | avox | 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 |