1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
2 | * Qwt Widget Library
|
---|
3 | * Copyright (C) 1997 Josef Wilgen
|
---|
4 | * Copyright (C) 2002 Uwe Rathmann
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
8 | *****************************************************************************/
|
---|
9 |
|
---|
10 | /*! \file */
|
---|
11 | #ifndef QWT_DOUBLE_RECT_H
|
---|
12 | #define QWT_DOUBLE_RECT_H 1
|
---|
13 |
|
---|
14 | #include "qwt_global.h"
|
---|
15 | #include "qwt_array.h"
|
---|
16 |
|
---|
17 | #if QT_VERSION >= 0x040000
|
---|
18 |
|
---|
19 | #include <QPointF>
|
---|
20 | #include <QSizeF>
|
---|
21 | #include <QRectF>
|
---|
22 |
|
---|
23 | /*!
|
---|
24 | \typedef QPointF QwtDoublePoint
|
---|
25 | \brief This is a typedef, see Trolltech Documentation for QPointF
|
---|
26 | in QT assistant 4.x. As soon as Qt3 compatibility is dropped
|
---|
27 | this typedef will disappear.
|
---|
28 | */
|
---|
29 | typedef QPointF QwtDoublePoint;
|
---|
30 |
|
---|
31 | /*!
|
---|
32 | \typedef QSizeF QwtDoubleSize
|
---|
33 | \brief This is a typedef, see Trolltech Documentation for QSizeF
|
---|
34 | in QT assistant 4.x. As soon as Qt3 compatibility is dropped
|
---|
35 | this typedef will disappear.
|
---|
36 | */
|
---|
37 | typedef QSizeF QwtDoubleSize;
|
---|
38 |
|
---|
39 | /*!
|
---|
40 | \typedef QRectF QwtDoubleRect
|
---|
41 | \brief This is a typedef, see Trolltech Documentation for QRectF
|
---|
42 | in QT assistant 4.x. As soon as Qt3 compatibility is dropped
|
---|
43 | this typedef will disappear.
|
---|
44 | */
|
---|
45 | typedef QRectF QwtDoubleRect;
|
---|
46 |
|
---|
47 | #else
|
---|
48 |
|
---|
49 | #include <qpoint.h>
|
---|
50 | #include <qsize.h>
|
---|
51 | #include <qrect.h>
|
---|
52 |
|
---|
53 | /*!
|
---|
54 | \brief The QwtDoublePoint class defines a point in double coordinates
|
---|
55 | */
|
---|
56 |
|
---|
57 | class QWT_EXPORT QwtDoublePoint
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | QwtDoublePoint();
|
---|
61 | QwtDoublePoint(double x, double y);
|
---|
62 | QwtDoublePoint(const QPoint &);
|
---|
63 |
|
---|
64 | QPoint toPoint() const;
|
---|
65 |
|
---|
66 | bool isNull() const;
|
---|
67 |
|
---|
68 | double x() const;
|
---|
69 | double y() const;
|
---|
70 |
|
---|
71 | double &rx();
|
---|
72 | double &ry();
|
---|
73 |
|
---|
74 | void setX(double x);
|
---|
75 | void setY(double y);
|
---|
76 |
|
---|
77 | bool operator==(const QwtDoublePoint &) const;
|
---|
78 | bool operator!=(const QwtDoublePoint &) const;
|
---|
79 |
|
---|
80 | const QwtDoublePoint operator-() const;
|
---|
81 | const QwtDoublePoint operator+(const QwtDoublePoint &) const;
|
---|
82 | const QwtDoublePoint operator-(const QwtDoublePoint &) const;
|
---|
83 | const QwtDoublePoint operator*(double) const;
|
---|
84 | const QwtDoublePoint operator/(double) const;
|
---|
85 |
|
---|
86 | QwtDoublePoint &operator+=(const QwtDoublePoint &);
|
---|
87 | QwtDoublePoint &operator-=(const QwtDoublePoint &);
|
---|
88 | QwtDoublePoint &operator*=(double);
|
---|
89 | QwtDoublePoint &operator/=(double);
|
---|
90 |
|
---|
91 | private:
|
---|
92 | double d_x;
|
---|
93 | double d_y;
|
---|
94 | };
|
---|
95 |
|
---|
96 | /*!
|
---|
97 | The QwtDoubleSize class defines a size in double coordinates
|
---|
98 | */
|
---|
99 |
|
---|
100 | class QWT_EXPORT QwtDoubleSize
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | QwtDoubleSize();
|
---|
104 | QwtDoubleSize(double width, double height);
|
---|
105 | QwtDoubleSize(const QSize &);
|
---|
106 |
|
---|
107 | bool isNull() const;
|
---|
108 | bool isEmpty() const;
|
---|
109 | bool isValid() const;
|
---|
110 |
|
---|
111 | double width() const;
|
---|
112 | double height() const;
|
---|
113 | void setWidth( double w );
|
---|
114 | void setHeight( double h );
|
---|
115 | void transpose();
|
---|
116 |
|
---|
117 | QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
|
---|
118 | QwtDoubleSize boundedTo(const QwtDoubleSize &) const;
|
---|
119 |
|
---|
120 | bool operator==(const QwtDoubleSize &) const;
|
---|
121 | bool operator!=(const QwtDoubleSize &) const;
|
---|
122 |
|
---|
123 | const QwtDoubleSize operator+(const QwtDoubleSize &) const;
|
---|
124 | const QwtDoubleSize operator-(const QwtDoubleSize &) const;
|
---|
125 | const QwtDoubleSize operator*(double) const;
|
---|
126 | const QwtDoubleSize operator/(double) const;
|
---|
127 |
|
---|
128 | QwtDoubleSize &operator+=(const QwtDoubleSize &);
|
---|
129 | QwtDoubleSize &operator-=(const QwtDoubleSize &);
|
---|
130 | QwtDoubleSize &operator*=(double c);
|
---|
131 | QwtDoubleSize &operator/=(double c);
|
---|
132 |
|
---|
133 | private:
|
---|
134 | double d_width;
|
---|
135 | double d_height;
|
---|
136 | };
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | The QwtDoubleRect class defines a size in double coordinates.
|
---|
140 | */
|
---|
141 |
|
---|
142 | class QWT_EXPORT QwtDoubleRect
|
---|
143 | {
|
---|
144 | public:
|
---|
145 | QwtDoubleRect();
|
---|
146 | QwtDoubleRect(double left, double top, double width, double height);
|
---|
147 | QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &);
|
---|
148 |
|
---|
149 | QwtDoubleRect(const QRect &);
|
---|
150 | QRect toRect() const;
|
---|
151 |
|
---|
152 | bool isNull() const;
|
---|
153 | bool isEmpty() const;
|
---|
154 | bool isValid() const;
|
---|
155 |
|
---|
156 | QwtDoubleRect normalized() const;
|
---|
157 |
|
---|
158 | double x() const;
|
---|
159 | double y() const;
|
---|
160 |
|
---|
161 | double left() const;
|
---|
162 | double right() const;
|
---|
163 | double top() const;
|
---|
164 | double bottom() const;
|
---|
165 |
|
---|
166 | void setX(double);
|
---|
167 | void setY(double);
|
---|
168 |
|
---|
169 | void setLeft(double);
|
---|
170 | void setRight(double);
|
---|
171 | void setTop(double);
|
---|
172 | void setBottom(double);
|
---|
173 |
|
---|
174 | QwtDoublePoint center() const;
|
---|
175 |
|
---|
176 | void moveLeft(double x);
|
---|
177 | void moveRight(double x);
|
---|
178 | void moveTop(double y );
|
---|
179 | void moveBottom(double y );
|
---|
180 | void moveTo(double x, double y);
|
---|
181 | void moveTo(const QwtDoublePoint &);
|
---|
182 | void moveBy(double dx, double dy);
|
---|
183 | void moveCenter(const QwtDoublePoint &);
|
---|
184 | void moveCenter(double dx, double dy);
|
---|
185 |
|
---|
186 | void setRect(double x1, double x2, double width, double height);
|
---|
187 |
|
---|
188 | double width() const;
|
---|
189 | double height() const;
|
---|
190 | QwtDoubleSize size() const;
|
---|
191 |
|
---|
192 | void setWidth(double w );
|
---|
193 | void setHeight(double h );
|
---|
194 | void setSize(const QwtDoubleSize &);
|
---|
195 |
|
---|
196 | QwtDoubleRect operator|(const QwtDoubleRect &r) const;
|
---|
197 | QwtDoubleRect operator&(const QwtDoubleRect &r) const;
|
---|
198 | QwtDoubleRect &operator|=(const QwtDoubleRect &r);
|
---|
199 | QwtDoubleRect &operator&=(const QwtDoubleRect &r);
|
---|
200 | bool operator==( const QwtDoubleRect &) const;
|
---|
201 | bool operator!=( const QwtDoubleRect &) const;
|
---|
202 |
|
---|
203 | bool contains(const QwtDoublePoint &p, bool proper = false) const;
|
---|
204 | bool contains(double x, double y, bool proper = false) const;
|
---|
205 | bool contains(const QwtDoubleRect &r, bool proper=false) const;
|
---|
206 |
|
---|
207 | QwtDoubleRect unite(const QwtDoubleRect &) const;
|
---|
208 | QwtDoubleRect intersect(const QwtDoubleRect &) const;
|
---|
209 | bool intersects(const QwtDoubleRect &) const;
|
---|
210 |
|
---|
211 | QwtDoublePoint bottomRight() const;
|
---|
212 | QwtDoublePoint topRight() const;
|
---|
213 | QwtDoublePoint topLeft() const;
|
---|
214 | QwtDoublePoint bottomLeft() const;
|
---|
215 |
|
---|
216 | private:
|
---|
217 | double d_left;
|
---|
218 | double d_right;
|
---|
219 | double d_top;
|
---|
220 | double d_bottom;
|
---|
221 | };
|
---|
222 |
|
---|
223 | /*!
|
---|
224 | Returns true if the point is null; otherwise returns false.
|
---|
225 |
|
---|
226 | A point is considered to be null if both the x- and y-coordinates
|
---|
227 | are equal to zero.
|
---|
228 | */
|
---|
229 | inline bool QwtDoublePoint::isNull() const
|
---|
230 | {
|
---|
231 | return d_x == 0.0 && d_y == 0.0;
|
---|
232 | }
|
---|
233 |
|
---|
234 | //! Returns the x-coordinate of the point.
|
---|
235 | inline double QwtDoublePoint::x() const
|
---|
236 | {
|
---|
237 | return d_x;
|
---|
238 | }
|
---|
239 |
|
---|
240 | //! Returns the y-coordinate of the point.
|
---|
241 | inline double QwtDoublePoint::y() const
|
---|
242 | {
|
---|
243 | return d_y;
|
---|
244 | }
|
---|
245 |
|
---|
246 | //! Returns a reference to the x-coordinate of the point.
|
---|
247 | inline double &QwtDoublePoint::rx()
|
---|
248 | {
|
---|
249 | return d_x;
|
---|
250 | }
|
---|
251 |
|
---|
252 | //! Returns a reference to the y-coordinate of the point.
|
---|
253 | inline double &QwtDoublePoint::ry()
|
---|
254 | {
|
---|
255 | return d_y;
|
---|
256 | }
|
---|
257 |
|
---|
258 | //! Sets the x-coordinate of the point to the value specified by x.
|
---|
259 | inline void QwtDoublePoint::setX(double x)
|
---|
260 | {
|
---|
261 | d_x = x;
|
---|
262 | }
|
---|
263 |
|
---|
264 | //! Sets the y-coordinate of the point to the value specified by y.
|
---|
265 | inline void QwtDoublePoint::setY(double y)
|
---|
266 | {
|
---|
267 | d_y = y;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /*!
|
---|
271 | Rounds the coordinates of this point to the nearest integer and
|
---|
272 | returns a QPoint with these rounded coordinates.
|
---|
273 | */
|
---|
274 | inline QPoint QwtDoublePoint::toPoint() const
|
---|
275 | {
|
---|
276 | return QPoint(qRound(d_x), qRound(d_y));
|
---|
277 | }
|
---|
278 |
|
---|
279 | /*!
|
---|
280 | Returns true if the width is 0 and the height is 0;
|
---|
281 | otherwise returns false.
|
---|
282 | */
|
---|
283 | inline bool QwtDoubleSize::isNull() const
|
---|
284 | {
|
---|
285 | return d_width == 0.0 && d_height == 0.0;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /*!
|
---|
289 | Returns true if the width is <= 0.0 or the height is <= 0.0,
|
---|
290 | otherwise false.
|
---|
291 | */
|
---|
292 | inline bool QwtDoubleSize::isEmpty() const
|
---|
293 | {
|
---|
294 | return d_width <= 0.0 || d_height <= 0.0;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /*!
|
---|
298 | Returns true if the width is equal to or greater than 0.0 and the height
|
---|
299 | is equal to or greater than 0.0; otherwise returns false.
|
---|
300 | */
|
---|
301 | inline bool QwtDoubleSize::isValid() const
|
---|
302 | {
|
---|
303 | return d_width >= 0.0 && d_height >= 0.0;
|
---|
304 | }
|
---|
305 |
|
---|
306 | //! Returns the width.
|
---|
307 | inline double QwtDoubleSize::width() const
|
---|
308 | {
|
---|
309 | return d_width;
|
---|
310 | }
|
---|
311 |
|
---|
312 | //! Returns the height.
|
---|
313 | inline double QwtDoubleSize::height() const
|
---|
314 | {
|
---|
315 | return d_height;
|
---|
316 | }
|
---|
317 |
|
---|
318 | //! Sets the width to width.
|
---|
319 | inline void QwtDoubleSize::setWidth(double width)
|
---|
320 | {
|
---|
321 | d_width = width;
|
---|
322 | }
|
---|
323 |
|
---|
324 | //! Sets the height to height.
|
---|
325 | inline void QwtDoubleSize::setHeight(double height)
|
---|
326 | {
|
---|
327 | d_height = height;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /*!
|
---|
331 | Returns true if the rectangle is a null rectangle; otherwise returns false.
|
---|
332 | A null rectangle has both the width and the height set to 0.
|
---|
333 | A null rectangle is also empty and invalid.
|
---|
334 |
|
---|
335 | \sa isEmpty(), isValid()
|
---|
336 | */
|
---|
337 | inline bool QwtDoubleRect::isNull() const
|
---|
338 | {
|
---|
339 | return d_right == d_left && d_bottom == d_top;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /*!
|
---|
343 | Returns true if the rectangle is empty; otherwise returns false.
|
---|
344 | An empty rectangle has a width() <= 0 or height() <= 0.
|
---|
345 | An empty rectangle is not valid. isEmpty() == !isValid()
|
---|
346 |
|
---|
347 | \sa isNull(), isValid()
|
---|
348 | */
|
---|
349 | inline bool QwtDoubleRect::isEmpty() const
|
---|
350 | {
|
---|
351 | return d_left >= d_right || d_top >= d_bottom;
|
---|
352 | }
|
---|
353 |
|
---|
354 | /*!
|
---|
355 | Returns true if the rectangle is valid; otherwise returns false.
|
---|
356 | A valid rectangle has a width() > 0 and height() > 0.
|
---|
357 | Note that non-trivial operations like intersections are not defined
|
---|
358 | for invalid rectangles. isValid() == !isEmpty()
|
---|
359 |
|
---|
360 | \sa isNull(), isEmpty(), and normalized().
|
---|
361 | */
|
---|
362 | inline bool QwtDoubleRect::isValid() const
|
---|
363 | {
|
---|
364 | return d_left < d_right && d_top < d_bottom;
|
---|
365 | }
|
---|
366 |
|
---|
367 | //! Returns x
|
---|
368 | inline double QwtDoubleRect::x() const
|
---|
369 | {
|
---|
370 | return d_left;
|
---|
371 | }
|
---|
372 |
|
---|
373 | //! Returns y
|
---|
374 | inline double QwtDoubleRect::y() const
|
---|
375 | {
|
---|
376 | return d_top;
|
---|
377 | }
|
---|
378 |
|
---|
379 | //! Returns left
|
---|
380 | inline double QwtDoubleRect::left() const
|
---|
381 | {
|
---|
382 | return d_left;
|
---|
383 | }
|
---|
384 |
|
---|
385 | //! Returns right
|
---|
386 | inline double QwtDoubleRect::right() const
|
---|
387 | {
|
---|
388 | return d_right;
|
---|
389 | }
|
---|
390 |
|
---|
391 | //! Returns top
|
---|
392 | inline double QwtDoubleRect::top() const
|
---|
393 | {
|
---|
394 | return d_top;
|
---|
395 | }
|
---|
396 |
|
---|
397 | //! Returns bottom
|
---|
398 | inline double QwtDoubleRect::bottom() const
|
---|
399 | {
|
---|
400 | return d_bottom;
|
---|
401 | }
|
---|
402 |
|
---|
403 | //! Set left
|
---|
404 | inline void QwtDoubleRect::setX(double x)
|
---|
405 | {
|
---|
406 | d_left = x;
|
---|
407 | }
|
---|
408 |
|
---|
409 | //! Set left
|
---|
410 | inline void QwtDoubleRect::setY(double y)
|
---|
411 | {
|
---|
412 | d_top = y;
|
---|
413 | }
|
---|
414 |
|
---|
415 | //! Set left
|
---|
416 | inline void QwtDoubleRect::setLeft(double x)
|
---|
417 | {
|
---|
418 | d_left = x;
|
---|
419 | }
|
---|
420 |
|
---|
421 | //! Set right
|
---|
422 | inline void QwtDoubleRect::setRight(double x)
|
---|
423 | {
|
---|
424 | d_right = x;
|
---|
425 | }
|
---|
426 |
|
---|
427 | //! Set top
|
---|
428 | inline void QwtDoubleRect::setTop(double y)
|
---|
429 | {
|
---|
430 | d_top = y;
|
---|
431 | }
|
---|
432 |
|
---|
433 | //! Set bottom
|
---|
434 | inline void QwtDoubleRect::setBottom(double y)
|
---|
435 | {
|
---|
436 | d_bottom = y;
|
---|
437 | }
|
---|
438 |
|
---|
439 | //! Returns the width
|
---|
440 | inline double QwtDoubleRect::width() const
|
---|
441 | {
|
---|
442 | return d_right - d_left;
|
---|
443 | }
|
---|
444 |
|
---|
445 | //! Returns the height
|
---|
446 | inline double QwtDoubleRect::height() const
|
---|
447 | {
|
---|
448 | return d_bottom - d_top;
|
---|
449 | }
|
---|
450 |
|
---|
451 | //! Returns the size
|
---|
452 | inline QwtDoubleSize QwtDoubleRect::size() const
|
---|
453 | {
|
---|
454 | return QwtDoubleSize(width(), height());
|
---|
455 | }
|
---|
456 |
|
---|
457 | //! Set the width, by right = left + w;
|
---|
458 | inline void QwtDoubleRect::setWidth(double w)
|
---|
459 | {
|
---|
460 | d_right = d_left + w;
|
---|
461 | }
|
---|
462 |
|
---|
463 | //! Set the height, by bottom = top + h;
|
---|
464 | inline void QwtDoubleRect::setHeight(double h)
|
---|
465 | {
|
---|
466 | d_bottom = d_top + h;
|
---|
467 | }
|
---|
468 |
|
---|
469 | /*!
|
---|
470 | Moves the top left corner of the rectangle to p,
|
---|
471 | without changing the rectangles size.
|
---|
472 | */
|
---|
473 | inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
|
---|
474 | {
|
---|
475 | moveTo(p.x(), p.y());
|
---|
476 | }
|
---|
477 |
|
---|
478 | inline QwtDoublePoint QwtDoubleRect::bottomRight() const
|
---|
479 | {
|
---|
480 | return QwtDoublePoint(bottom(), right());
|
---|
481 | }
|
---|
482 |
|
---|
483 | inline QwtDoublePoint QwtDoubleRect::topRight() const
|
---|
484 | {
|
---|
485 | return QwtDoublePoint(top(), right());
|
---|
486 | }
|
---|
487 |
|
---|
488 | inline QwtDoublePoint QwtDoubleRect::topLeft() const
|
---|
489 | {
|
---|
490 | return QwtDoublePoint(top(), left());
|
---|
491 | }
|
---|
492 |
|
---|
493 | inline QwtDoublePoint QwtDoubleRect::bottomLeft() const
|
---|
494 | {
|
---|
495 | return QwtDoublePoint(bottom(), left());
|
---|
496 | }
|
---|
497 |
|
---|
498 |
|
---|
499 | #endif // QT_VERSION < 0x040000
|
---|
500 |
|
---|
501 | #endif // QWT_DOUBLE_RECT_H
|
---|