qwt_double_rect.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_DOUBLE_RECT_H
00011 #define QWT_DOUBLE_RECT_H 1
00012 
00013 #include "qwt_global.h"
00014 #include "qwt_array.h"
00015 
00016 #if QT_VERSION >= 0x040000
00017 
00018 #include <QPointF>
00019 #include <QSizeF>
00020 #include <QRectF>
00021 
00022 typedef QPointF QwtDoublePoint;
00023 typedef QSizeF QwtDoubleSize;
00024 typedef QRectF QwtDoubleRect;
00025 
00026 #else
00027 
00028 #include <qpoint.h>
00029 #include <qsize.h>
00030 #include <qrect.h>
00031 
00036 class QWT_EXPORT QwtDoublePoint
00037 {
00038 public:
00039     QwtDoublePoint();
00040     QwtDoublePoint(double x, double y);
00041     QwtDoublePoint(const QPoint &);
00042 
00043     QPoint toPoint() const;
00044 
00045     bool isNull()    const;
00046 
00047     double x() const;
00048     double y() const;
00049 
00050     double &rx();
00051     double &ry();
00052 
00053     void setX(double x);
00054     void setY(double y);
00055 
00056     bool operator==(const QwtDoublePoint &) const;
00057     bool operator!=(const QwtDoublePoint &) const;
00058 
00059     const QwtDoublePoint operator-() const;
00060     const QwtDoublePoint operator+(const QwtDoublePoint &) const;
00061     const QwtDoublePoint operator-(const QwtDoublePoint &) const;
00062     const QwtDoublePoint operator*(double) const;
00063     const QwtDoublePoint operator/(double) const;
00064 
00065     QwtDoublePoint &operator+=(const QwtDoublePoint &);
00066     QwtDoublePoint &operator-=(const QwtDoublePoint &);
00067     QwtDoublePoint &operator*=(double);
00068     QwtDoublePoint &operator/=(double);
00069 
00070 private:
00071     double d_x;
00072     double d_y;
00073 };
00074 
00079 class QWT_EXPORT QwtDoubleSize
00080 {
00081 public:
00082     QwtDoubleSize();
00083     QwtDoubleSize(double width, double height);
00084     QwtDoubleSize(const QSize &);
00085 
00086     bool isNull() const;
00087     bool isEmpty() const;
00088     bool isValid() const;
00089 
00090     double width() const;
00091     double height() const;
00092     void setWidth( double w );
00093     void setHeight( double h );
00094     void transpose();
00095 
00096     QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
00097     QwtDoubleSize boundedTo(const QwtDoubleSize &) const;
00098 
00099     bool operator==(const QwtDoubleSize &) const;
00100     bool operator!=(const QwtDoubleSize &) const;
00101 
00102     const QwtDoubleSize operator+(const QwtDoubleSize &) const;
00103     const QwtDoubleSize operator-(const QwtDoubleSize &) const;
00104     const QwtDoubleSize operator*(double) const;
00105     const QwtDoubleSize operator/(double) const;
00106 
00107     QwtDoubleSize &operator+=(const QwtDoubleSize &);
00108     QwtDoubleSize &operator-=(const QwtDoubleSize &);
00109     QwtDoubleSize &operator*=(double c);
00110     QwtDoubleSize &operator/=(double c);
00111 
00112 private:
00113     double d_width;
00114     double d_height;
00115 };
00116 
00121 class QWT_EXPORT QwtDoubleRect  
00122 {
00123 public:
00124     QwtDoubleRect();
00125     QwtDoubleRect(double left, double top, double width, double height);
00126     QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &);
00127 
00128     bool isNull()    const;
00129     bool isEmpty()   const;
00130     bool isValid()   const;
00131 
00132     QwtDoubleRect normalized() const;
00133 
00134     double x()  const;
00135     double y()  const;
00136 
00137     double left()  const;
00138     double right()  const;
00139     double top()  const;
00140     double bottom()  const;
00141 
00142     void setX(double);
00143     void setY(double);
00144 
00145     void setLeft(double);
00146     void setRight(double);
00147     void setTop(double);
00148     void setBottom(double);
00149 
00150     QwtDoublePoint center()  const;
00151 
00152     void moveLeft(double x);
00153     void moveRight(double x);
00154     void moveTop(double y );
00155     void moveBottom(double y );
00156     void moveTo(double x, double y);
00157     void moveTo(const QwtDoublePoint &);
00158     void moveBy(double dx, double dy);
00159     void moveCenter(const QwtDoublePoint &);
00160     void moveCenter(double dx, double dy);
00161 
00162     void setRect(double x1, double x2, double width, double height);
00163 
00164     double width()   const;
00165     double height()  const;
00166     QwtDoubleSize size() const;
00167 
00168     void setWidth(double w );
00169     void setHeight(double h );
00170     void setSize(const QwtDoubleSize &);
00171 
00172     QwtDoubleRect  operator|(const QwtDoubleRect &r) const;
00173     QwtDoubleRect  operator&(const QwtDoubleRect &r) const;
00174     QwtDoubleRect &operator|=(const QwtDoubleRect &r);
00175     QwtDoubleRect &operator&=(const QwtDoubleRect &r);
00176     bool operator==( const QwtDoubleRect &) const;
00177     bool operator!=( const QwtDoubleRect &) const;
00178 
00179     bool contains(const QwtDoublePoint &p, bool proper = false) const;
00180     bool contains(double x, double y, bool proper = false) const; 
00181     bool contains(const QwtDoubleRect &r, bool proper=false) const;
00182 
00183     QwtDoubleRect unite(const QwtDoubleRect &) const;
00184     QwtDoubleRect intersect(const QwtDoubleRect &) const;
00185     bool intersects(const QwtDoubleRect &) const;
00186 
00187 private:
00188     double d_left;
00189     double d_right;
00190     double d_top;
00191     double d_bottom;
00192 };
00193 
00200 inline bool QwtDoublePoint::isNull() const
00201 { 
00202     return d_x == 0.0 && d_y == 0.0; 
00203 }
00204 
00206 inline double QwtDoublePoint::x() const
00207 { 
00208     return d_x; 
00209 }
00210 
00212 inline double QwtDoublePoint::y() const
00213 {   
00214     return d_y; 
00215 }
00216 
00218 inline double &QwtDoublePoint::rx()
00219 {
00220     return d_x;
00221 }
00222 
00224 inline double &QwtDoublePoint::ry()
00225 {
00226     return d_y;
00227 }
00228 
00230 inline void QwtDoublePoint::setX(double x)
00231 { 
00232     d_x = x; 
00233 }
00234 
00236 inline void QwtDoublePoint::setY(double y)
00237 { 
00238     d_y = y; 
00239 }
00240 
00245 inline QPoint QwtDoublePoint::toPoint() const
00246 {
00247     return QPoint(qRound(d_x), qRound(d_y));
00248 }
00249 
00254 inline bool QwtDoubleSize::isNull() const
00255 { 
00256     return d_width == 0.0 && d_height == 0.0; 
00257 }
00258 
00263 inline bool QwtDoubleSize::isEmpty() const
00264 { 
00265     return d_width <= 0.0 || d_height <= 0.0; 
00266 }
00267 
00272 inline bool QwtDoubleSize::isValid() const
00273 { 
00274     return d_width >= 0.0 && d_height >= 0.0; 
00275 }
00276 
00278 inline double QwtDoubleSize::width() const
00279 { 
00280     return d_width; 
00281 }
00282 
00284 inline double QwtDoubleSize::height() const
00285 { 
00286     return d_height; 
00287 }
00288 
00290 inline void QwtDoubleSize::setWidth(double width)
00291 { 
00292     d_width = width; 
00293 }
00294 
00296 inline void QwtDoubleSize::setHeight(double height)
00297 { 
00298     d_height = height; 
00299 }
00300 
00308 inline bool QwtDoubleRect::isNull() const
00309 { 
00310     return d_right == d_left && d_bottom == d_top;
00311 }
00312 
00320 inline bool QwtDoubleRect::isEmpty() const
00321 { 
00322     return d_left >= d_right || d_top >= d_bottom; 
00323 }
00324 
00333 inline bool QwtDoubleRect::isValid() const
00334 { 
00335     return d_left < d_right && d_top < d_bottom; 
00336 }
00337 
00339 inline double QwtDoubleRect::x() const
00340 { 
00341     return d_left; 
00342 }
00343 
00345 inline double QwtDoubleRect::y() const
00346 { 
00347     return d_top; 
00348 }
00349 
00351 inline double QwtDoubleRect::left() const
00352 { 
00353     return d_left; 
00354 }
00355 
00357 inline double QwtDoubleRect::right() const
00358 { 
00359     return d_right; 
00360 }
00361 
00363 inline double QwtDoubleRect::top() const
00364 { 
00365     return d_top; 
00366 }
00367 
00369 inline double QwtDoubleRect::bottom() const
00370 { 
00371     return d_bottom; 
00372 }
00373 
00375 inline void QwtDoubleRect::setX(double x)
00376 { 
00377     d_left = x;
00378 }
00379 
00381 inline void QwtDoubleRect::setY(double y)
00382 { 
00383     d_top = y;
00384 }
00385 
00387 inline void QwtDoubleRect::setLeft(double x)
00388 { 
00389     d_left = x;
00390 }
00391 
00393 inline void QwtDoubleRect::setRight(double x)
00394 { 
00395     d_right = x;
00396 }
00397 
00399 inline void QwtDoubleRect::setTop(double y)
00400 { 
00401     d_top = y;
00402 }
00403 
00405 inline void QwtDoubleRect::setBottom(double y)
00406 { 
00407     d_bottom = y;
00408 }
00409 
00411 inline double QwtDoubleRect::width() const
00412 { 
00413     return  d_right - d_left; 
00414 }
00415 
00417 inline double QwtDoubleRect::height() const
00418 { 
00419     return  d_bottom - d_top; 
00420 }
00421 
00423 inline QwtDoubleSize QwtDoubleRect::size() const
00424 { 
00425     return QwtDoubleSize(width(), height());
00426 }
00427 
00429 inline void QwtDoubleRect::setWidth(double w)
00430 {
00431     d_right = d_left + w;
00432 }
00433 
00435 inline void QwtDoubleRect::setHeight(double h)
00436 {
00437     d_bottom = d_top + h;
00438 }
00439 
00444 inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
00445 {
00446     moveTo(p.x(), p.y());
00447 }
00448 
00449 #endif // QT_VERSION < 0x040000
00450 
00451 #endif // QWT_DOUBLE_RECT_H

Generated on Mon Feb 26 21:22:36 2007 for Qwt User's Guide by  doxygen 1.4.6