Qwt User's Guide 5.2.3

- Main Page
- Related Pages
- Classes

qwt_double_rect.h
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
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
29 typedef QPointF QwtDoublePoint;
30
37 typedef QSizeF QwtDoubleSize;
38
45 typedef QRectF QwtDoubleRect;
46
47 #else
48
49 #include <qpoint.h>
50 #include <qsize.h>
51 #include <qrect.h>
52
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
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
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
229 inline bool QwtDoublePoint::isNull() const
230 {
231 return d_x == 0.0 && d_y == 0.0;
232 }
233
235 inline double QwtDoublePoint::x() const
236 {
237 return d_x;
238 }
239
241 inline double QwtDoublePoint::y() const
242 {
243 return d_y;
244 }
245
247 inline double &QwtDoublePoint::rx()
248 {
249 return d_x;
250 }
251
253 inline double &QwtDoublePoint::ry()
254 {
255 return d_y;
256 }
257
259 inline void QwtDoublePoint::setX(double x)
260 {
261 d_x = x;
262 }
263
265 inline void QwtDoublePoint::setY(double y)
266 {
267 d_y = y;
268 }
269
274 inline QPoint QwtDoublePoint::toPoint() const
275 {
276 return QPoint(qRound(d_x), qRound(d_y));
277 }
278
283 inline bool QwtDoubleSize::isNull() const
284 {
285 return d_width == 0.0 && d_height == 0.0;
286 }
287
292 inline bool QwtDoubleSize::isEmpty() const
293 {
294 return d_width <= 0.0 || d_height <= 0.0;
295 }
296
301 inline bool QwtDoubleSize::isValid() const
302 {
303 return d_width >= 0.0 && d_height >= 0.0;
304 }
305
307 inline double QwtDoubleSize::width() const
308 {
309 return d_width;
310 }
311
313 inline double QwtDoubleSize::height() const
314 {
315 return d_height;
316 }
317
319 inline void QwtDoubleSize::setWidth(double width)
320 {
321 d_width = width;
322 }
323
325 inline void QwtDoubleSize::setHeight(double height)
326 {
327 d_height = height;
328 }
329
337 inline bool QwtDoubleRect::isNull() const
338 {
339 return d_right == d_left && d_bottom == d_top;
340 }
341
349 inline bool QwtDoubleRect::isEmpty() const
350 {
351 return d_left >= d_right || d_top >= d_bottom;
352 }
353
362 inline bool QwtDoubleRect::isValid() const
363 {
364 return d_left < d_right && d_top < d_bottom;
365 }
366
368 inline double QwtDoubleRect::x() const
369 {
370 return d_left;
371 }
372
374 inline double QwtDoubleRect::y() const
375 {
376 return d_top;
377 }
378
380 inline double QwtDoubleRect::left() const
381 {
382 return d_left;
383 }
384
386 inline double QwtDoubleRect::right() const
387 {
388 return d_right;
389 }
390
392 inline double QwtDoubleRect::top() const
393 {
394 return d_top;
395 }
396
398 inline double QwtDoubleRect::bottom() const
399 {
400 return d_bottom;
401 }
402
404 inline void QwtDoubleRect::setX(double x)
405 {
406 d_left = x;
407 }
408
410 inline void QwtDoubleRect::setY(double y)
411 {
412 d_top = y;
413 }
414
416 inline void QwtDoubleRect::setLeft(double x)
417 {
418 d_left = x;
419 }
420
422 inline void QwtDoubleRect::setRight(double x)
423 {
424 d_right = x;
425 }
426
428 inline void QwtDoubleRect::setTop(double y)
429 {
430 d_top = y;
431 }
432
434 inline void QwtDoubleRect::setBottom(double y)
435 {
436 d_bottom = y;
437 }
438
440 inline double QwtDoubleRect::width() const
441 {
442 return d_right - d_left;
443 }
444
446 inline double QwtDoubleRect::height() const
447 {
448 return d_bottom - d_top;
449 }
450
452 inline QwtDoubleSize QwtDoubleRect::size() const
453 {
454 return QwtDoubleSize(width(), height());
455 }
456
458 inline void QwtDoubleRect::setWidth(double w)
459 {
460 d_right = d_left + w;
461 }
462
464 inline void QwtDoubleRect::setHeight(double h)
465 {
466 d_bottom = d_top + h;
467 }
468
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