Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 #ifndef QWT_DOUBLE_RECT_H
00012 #define QWT_DOUBLE_RECT_H 1
00013
00014 #include "qwt_global.h"
00015 #include "qwt_array.h"
00016
00017 #if QT_VERSION >= 0x040000
00018
00019 #include <QPointF>
00020 #include <QSizeF>
00021 #include <QRectF>
00022
00029 typedef QPointF QwtDoublePoint;
00030
00037 typedef QSizeF QwtDoubleSize;
00038
00045 typedef QRectF QwtDoubleRect;
00046
00047 #else
00048
00049 #include <qpoint.h>
00050 #include <qsize.h>
00051 #include <qrect.h>
00052
00057 class QWT_EXPORT QwtDoublePoint
00058 {
00059 public:
00060 QwtDoublePoint();
00061 QwtDoublePoint(double x, double y);
00062 QwtDoublePoint(const QPoint &);
00063
00064 QPoint toPoint() const;
00065
00066 bool isNull() const;
00067
00068 double x() const;
00069 double y() const;
00070
00071 double &rx();
00072 double &ry();
00073
00074 void setX(double x);
00075 void setY(double y);
00076
00077 bool operator==(const QwtDoublePoint &) const;
00078 bool operator!=(const QwtDoublePoint &) const;
00079
00080 const QwtDoublePoint operator-() const;
00081 const QwtDoublePoint operator+(const QwtDoublePoint &) const;
00082 const QwtDoublePoint operator-(const QwtDoublePoint &) const;
00083 const QwtDoublePoint operator*(double) const;
00084 const QwtDoublePoint operator/(double) const;
00085
00086 QwtDoublePoint &operator+=(const QwtDoublePoint &);
00087 QwtDoublePoint &operator-=(const QwtDoublePoint &);
00088 QwtDoublePoint &operator*=(double);
00089 QwtDoublePoint &operator/=(double);
00090
00091 private:
00092 double d_x;
00093 double d_y;
00094 };
00095
00100 class QWT_EXPORT QwtDoubleSize
00101 {
00102 public:
00103 QwtDoubleSize();
00104 QwtDoubleSize(double width, double height);
00105 QwtDoubleSize(const QSize &);
00106
00107 bool isNull() const;
00108 bool isEmpty() const;
00109 bool isValid() const;
00110
00111 double width() const;
00112 double height() const;
00113 void setWidth( double w );
00114 void setHeight( double h );
00115 void transpose();
00116
00117 QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
00118 QwtDoubleSize boundedTo(const QwtDoubleSize &) const;
00119
00120 bool operator==(const QwtDoubleSize &) const;
00121 bool operator!=(const QwtDoubleSize &) const;
00122
00123 const QwtDoubleSize operator+(const QwtDoubleSize &) const;
00124 const QwtDoubleSize operator-(const QwtDoubleSize &) const;
00125 const QwtDoubleSize operator*(double) const;
00126 const QwtDoubleSize operator/(double) const;
00127
00128 QwtDoubleSize &operator+=(const QwtDoubleSize &);
00129 QwtDoubleSize &operator-=(const QwtDoubleSize &);
00130 QwtDoubleSize &operator*=(double c);
00131 QwtDoubleSize &operator/=(double c);
00132
00133 private:
00134 double d_width;
00135 double d_height;
00136 };
00137
00142 class QWT_EXPORT QwtDoubleRect
00143 {
00144 public:
00145 QwtDoubleRect();
00146 QwtDoubleRect(double left, double top, double width, double height);
00147 QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &);
00148
00149 QwtDoubleRect(const QRect &);
00150 QRect toRect() const;
00151
00152 bool isNull() const;
00153 bool isEmpty() const;
00154 bool isValid() const;
00155
00156 QwtDoubleRect normalized() const;
00157
00158 double x() const;
00159 double y() const;
00160
00161 double left() const;
00162 double right() const;
00163 double top() const;
00164 double bottom() const;
00165
00166 void setX(double);
00167 void setY(double);
00168
00169 void setLeft(double);
00170 void setRight(double);
00171 void setTop(double);
00172 void setBottom(double);
00173
00174 QwtDoublePoint center() const;
00175
00176 void moveLeft(double x);
00177 void moveRight(double x);
00178 void moveTop(double y );
00179 void moveBottom(double y );
00180 void moveTo(double x, double y);
00181 void moveTo(const QwtDoublePoint &);
00182 void moveBy(double dx, double dy);
00183 void moveCenter(const QwtDoublePoint &);
00184 void moveCenter(double dx, double dy);
00185
00186 void setRect(double x1, double x2, double width, double height);
00187
00188 double width() const;
00189 double height() const;
00190 QwtDoubleSize size() const;
00191
00192 void setWidth(double w );
00193 void setHeight(double h );
00194 void setSize(const QwtDoubleSize &);
00195
00196 QwtDoubleRect operator|(const QwtDoubleRect &r) const;
00197 QwtDoubleRect operator&(const QwtDoubleRect &r) const;
00198 QwtDoubleRect &operator|=(const QwtDoubleRect &r);
00199 QwtDoubleRect &operator&=(const QwtDoubleRect &r);
00200 bool operator==( const QwtDoubleRect &) const;
00201 bool operator!=( const QwtDoubleRect &) const;
00202
00203 bool contains(const QwtDoublePoint &p, bool proper = false) const;
00204 bool contains(double x, double y, bool proper = false) const;
00205 bool contains(const QwtDoubleRect &r, bool proper=false) const;
00206
00207 QwtDoubleRect unite(const QwtDoubleRect &) const;
00208 QwtDoubleRect intersect(const QwtDoubleRect &) const;
00209 bool intersects(const QwtDoubleRect &) const;
00210
00211 QwtDoublePoint bottomRight() const;
00212 QwtDoublePoint topRight() const;
00213 QwtDoublePoint topLeft() const;
00214 QwtDoublePoint bottomLeft() const;
00215
00216 private:
00217 double d_left;
00218 double d_right;
00219 double d_top;
00220 double d_bottom;
00221 };
00222
00229 inline bool QwtDoublePoint::isNull() const
00230 {
00231 return d_x == 0.0 && d_y == 0.0;
00232 }
00233
00235 inline double QwtDoublePoint::x() const
00236 {
00237 return d_x;
00238 }
00239
00241 inline double QwtDoublePoint::y() const
00242 {
00243 return d_y;
00244 }
00245
00247 inline double &QwtDoublePoint::rx()
00248 {
00249 return d_x;
00250 }
00251
00253 inline double &QwtDoublePoint::ry()
00254 {
00255 return d_y;
00256 }
00257
00259 inline void QwtDoublePoint::setX(double x)
00260 {
00261 d_x = x;
00262 }
00263
00265 inline void QwtDoublePoint::setY(double y)
00266 {
00267 d_y = y;
00268 }
00269
00274 inline QPoint QwtDoublePoint::toPoint() const
00275 {
00276 return QPoint(qRound(d_x), qRound(d_y));
00277 }
00278
00283 inline bool QwtDoubleSize::isNull() const
00284 {
00285 return d_width == 0.0 && d_height == 0.0;
00286 }
00287
00292 inline bool QwtDoubleSize::isEmpty() const
00293 {
00294 return d_width <= 0.0 || d_height <= 0.0;
00295 }
00296
00301 inline bool QwtDoubleSize::isValid() const
00302 {
00303 return d_width >= 0.0 && d_height >= 0.0;
00304 }
00305
00307 inline double QwtDoubleSize::width() const
00308 {
00309 return d_width;
00310 }
00311
00313 inline double QwtDoubleSize::height() const
00314 {
00315 return d_height;
00316 }
00317
00319 inline void QwtDoubleSize::setWidth(double width)
00320 {
00321 d_width = width;
00322 }
00323
00325 inline void QwtDoubleSize::setHeight(double height)
00326 {
00327 d_height = height;
00328 }
00329
00337 inline bool QwtDoubleRect::isNull() const
00338 {
00339 return d_right == d_left && d_bottom == d_top;
00340 }
00341
00349 inline bool QwtDoubleRect::isEmpty() const
00350 {
00351 return d_left >= d_right || d_top >= d_bottom;
00352 }
00353
00362 inline bool QwtDoubleRect::isValid() const
00363 {
00364 return d_left < d_right && d_top < d_bottom;
00365 }
00366
00368 inline double QwtDoubleRect::x() const
00369 {
00370 return d_left;
00371 }
00372
00374 inline double QwtDoubleRect::y() const
00375 {
00376 return d_top;
00377 }
00378
00380 inline double QwtDoubleRect::left() const
00381 {
00382 return d_left;
00383 }
00384
00386 inline double QwtDoubleRect::right() const
00387 {
00388 return d_right;
00389 }
00390
00392 inline double QwtDoubleRect::top() const
00393 {
00394 return d_top;
00395 }
00396
00398 inline double QwtDoubleRect::bottom() const
00399 {
00400 return d_bottom;
00401 }
00402
00404 inline void QwtDoubleRect::setX(double x)
00405 {
00406 d_left = x;
00407 }
00408
00410 inline void QwtDoubleRect::setY(double y)
00411 {
00412 d_top = y;
00413 }
00414
00416 inline void QwtDoubleRect::setLeft(double x)
00417 {
00418 d_left = x;
00419 }
00420
00422 inline void QwtDoubleRect::setRight(double x)
00423 {
00424 d_right = x;
00425 }
00426
00428 inline void QwtDoubleRect::setTop(double y)
00429 {
00430 d_top = y;
00431 }
00432
00434 inline void QwtDoubleRect::setBottom(double y)
00435 {
00436 d_bottom = y;
00437 }
00438
00440 inline double QwtDoubleRect::width() const
00441 {
00442 return d_right - d_left;
00443 }
00444
00446 inline double QwtDoubleRect::height() const
00447 {
00448 return d_bottom - d_top;
00449 }
00450
00452 inline QwtDoubleSize QwtDoubleRect::size() const
00453 {
00454 return QwtDoubleSize(width(), height());
00455 }
00456
00458 inline void QwtDoubleRect::setWidth(double w)
00459 {
00460 d_right = d_left + w;
00461 }
00462
00464 inline void QwtDoubleRect::setHeight(double h)
00465 {
00466 d_bottom = d_top + h;
00467 }
00468
00473 inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
00474 {
00475 moveTo(p.x(), p.y());
00476 }
00477
00478 inline QwtDoublePoint QwtDoubleRect::bottomRight() const
00479 {
00480 return QwtDoublePoint(bottom(), right());
00481 }
00482
00483 inline QwtDoublePoint QwtDoubleRect::topRight() const
00484 {
00485 return QwtDoublePoint(top(), right());
00486 }
00487
00488 inline QwtDoublePoint QwtDoubleRect::topLeft() const
00489 {
00490 return QwtDoublePoint(top(), left());
00491 }
00492
00493 inline QwtDoublePoint QwtDoubleRect::bottomLeft() const
00494 {
00495 return QwtDoublePoint(bottom(), left());
00496 }
00497
00498
00499 #endif // QT_VERSION < 0x040000
00500
00501 #endif // QWT_DOUBLE_RECT_H