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 bool isNull() const;
00150 bool isEmpty() const;
00151 bool isValid() const;
00152
00153 QwtDoubleRect normalized() const;
00154
00155 double x() const;
00156 double y() const;
00157
00158 double left() const;
00159 double right() const;
00160 double top() const;
00161 double bottom() const;
00162
00163 void setX(double);
00164 void setY(double);
00165
00166 void setLeft(double);
00167 void setRight(double);
00168 void setTop(double);
00169 void setBottom(double);
00170
00171 QwtDoublePoint center() const;
00172
00173 void moveLeft(double x);
00174 void moveRight(double x);
00175 void moveTop(double y );
00176 void moveBottom(double y );
00177 void moveTo(double x, double y);
00178 void moveTo(const QwtDoublePoint &);
00179 void moveBy(double dx, double dy);
00180 void moveCenter(const QwtDoublePoint &);
00181 void moveCenter(double dx, double dy);
00182
00183 void setRect(double x1, double x2, double width, double height);
00184
00185 double width() const;
00186 double height() const;
00187 QwtDoubleSize size() const;
00188
00189 void setWidth(double w );
00190 void setHeight(double h );
00191 void setSize(const QwtDoubleSize &);
00192
00193 QwtDoubleRect operator|(const QwtDoubleRect &r) const;
00194 QwtDoubleRect operator&(const QwtDoubleRect &r) const;
00195 QwtDoubleRect &operator|=(const QwtDoubleRect &r);
00196 QwtDoubleRect &operator&=(const QwtDoubleRect &r);
00197 bool operator==( const QwtDoubleRect &) const;
00198 bool operator!=( const QwtDoubleRect &) const;
00199
00200 bool contains(const QwtDoublePoint &p, bool proper = false) const;
00201 bool contains(double x, double y, bool proper = false) const;
00202 bool contains(const QwtDoubleRect &r, bool proper=false) const;
00203
00204 QwtDoubleRect unite(const QwtDoubleRect &) const;
00205 QwtDoubleRect intersect(const QwtDoubleRect &) const;
00206 bool intersects(const QwtDoubleRect &) const;
00207
00208 private:
00209 double d_left;
00210 double d_right;
00211 double d_top;
00212 double d_bottom;
00213 };
00214
00221 inline bool QwtDoublePoint::isNull() const
00222 {
00223 return d_x == 0.0 && d_y == 0.0;
00224 }
00225
00227 inline double QwtDoublePoint::x() const
00228 {
00229 return d_x;
00230 }
00231
00233 inline double QwtDoublePoint::y() const
00234 {
00235 return d_y;
00236 }
00237
00239 inline double &QwtDoublePoint::rx()
00240 {
00241 return d_x;
00242 }
00243
00245 inline double &QwtDoublePoint::ry()
00246 {
00247 return d_y;
00248 }
00249
00251 inline void QwtDoublePoint::setX(double x)
00252 {
00253 d_x = x;
00254 }
00255
00257 inline void QwtDoublePoint::setY(double y)
00258 {
00259 d_y = y;
00260 }
00261
00266 inline QPoint QwtDoublePoint::toPoint() const
00267 {
00268 return QPoint(qRound(d_x), qRound(d_y));
00269 }
00270
00275 inline bool QwtDoubleSize::isNull() const
00276 {
00277 return d_width == 0.0 && d_height == 0.0;
00278 }
00279
00284 inline bool QwtDoubleSize::isEmpty() const
00285 {
00286 return d_width <= 0.0 || d_height <= 0.0;
00287 }
00288
00293 inline bool QwtDoubleSize::isValid() const
00294 {
00295 return d_width >= 0.0 && d_height >= 0.0;
00296 }
00297
00299 inline double QwtDoubleSize::width() const
00300 {
00301 return d_width;
00302 }
00303
00305 inline double QwtDoubleSize::height() const
00306 {
00307 return d_height;
00308 }
00309
00311 inline void QwtDoubleSize::setWidth(double width)
00312 {
00313 d_width = width;
00314 }
00315
00317 inline void QwtDoubleSize::setHeight(double height)
00318 {
00319 d_height = height;
00320 }
00321
00329 inline bool QwtDoubleRect::isNull() const
00330 {
00331 return d_right == d_left && d_bottom == d_top;
00332 }
00333
00341 inline bool QwtDoubleRect::isEmpty() const
00342 {
00343 return d_left >= d_right || d_top >= d_bottom;
00344 }
00345
00354 inline bool QwtDoubleRect::isValid() const
00355 {
00356 return d_left < d_right && d_top < d_bottom;
00357 }
00358
00360 inline double QwtDoubleRect::x() const
00361 {
00362 return d_left;
00363 }
00364
00366 inline double QwtDoubleRect::y() const
00367 {
00368 return d_top;
00369 }
00370
00372 inline double QwtDoubleRect::left() const
00373 {
00374 return d_left;
00375 }
00376
00378 inline double QwtDoubleRect::right() const
00379 {
00380 return d_right;
00381 }
00382
00384 inline double QwtDoubleRect::top() const
00385 {
00386 return d_top;
00387 }
00388
00390 inline double QwtDoubleRect::bottom() const
00391 {
00392 return d_bottom;
00393 }
00394
00396 inline void QwtDoubleRect::setX(double x)
00397 {
00398 d_left = x;
00399 }
00400
00402 inline void QwtDoubleRect::setY(double y)
00403 {
00404 d_top = y;
00405 }
00406
00408 inline void QwtDoubleRect::setLeft(double x)
00409 {
00410 d_left = x;
00411 }
00412
00414 inline void QwtDoubleRect::setRight(double x)
00415 {
00416 d_right = x;
00417 }
00418
00420 inline void QwtDoubleRect::setTop(double y)
00421 {
00422 d_top = y;
00423 }
00424
00426 inline void QwtDoubleRect::setBottom(double y)
00427 {
00428 d_bottom = y;
00429 }
00430
00432 inline double QwtDoubleRect::width() const
00433 {
00434 return d_right - d_left;
00435 }
00436
00438 inline double QwtDoubleRect::height() const
00439 {
00440 return d_bottom - d_top;
00441 }
00442
00444 inline QwtDoubleSize QwtDoubleRect::size() const
00445 {
00446 return QwtDoubleSize(width(), height());
00447 }
00448
00450 inline void QwtDoubleRect::setWidth(double w)
00451 {
00452 d_right = d_left + w;
00453 }
00454
00456 inline void QwtDoubleRect::setHeight(double h)
00457 {
00458 d_bottom = d_top + h;
00459 }
00460
00465 inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
00466 {
00467 moveTo(p.x(), p.y());
00468 }
00469
00470 #endif // QT_VERSION < 0x040000
00471
00472 #endif // QWT_DOUBLE_RECT_H