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