00001
00002
00003
00004
00005
00006
00007
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
00027 #if defined(QWT_TEMPLATEDLL)
00028
00029 #if defined(Q_CC_MSVC_NET)
00030
00031 extern template class __declspec(dllimport) QwtArray<QPointF>;
00032 #else
00033 template class QWT_EXPORT QwtArray<QPointF>;
00034 #endif
00035
00036 #endif
00037
00038
00039 #else
00040
00041 #include <qpoint.h>
00042 #include <qsize.h>
00043 #include <qrect.h>
00044
00049 class QWT_EXPORT QwtDoublePoint
00050 {
00051 public:
00052 QwtDoublePoint();
00053 QwtDoublePoint(double x, double y);
00054 QwtDoublePoint(const QPoint &);
00055
00056 QPoint toPoint() const;
00057
00058 bool isNull() const;
00059
00060 double x() const;
00061 double y() const;
00062
00063 double &rx();
00064 double &ry();
00065
00066 void setX(double x);
00067 void setY(double y);
00068
00069 bool operator==(const QwtDoublePoint &) const;
00070 bool operator!=(const QwtDoublePoint &) const;
00071
00072 const QwtDoublePoint operator-() const;
00073 const QwtDoublePoint operator+(const QwtDoublePoint &) const;
00074 const QwtDoublePoint operator-(const QwtDoublePoint &) const;
00075 const QwtDoublePoint operator*(double) const;
00076 const QwtDoublePoint operator/(double) const;
00077
00078 QwtDoublePoint &operator+=(const QwtDoublePoint &);
00079 QwtDoublePoint &operator-=(const QwtDoublePoint &);
00080 QwtDoublePoint &operator*=(double);
00081 QwtDoublePoint &operator/=(double);
00082
00083 private:
00084 double d_x;
00085 double d_y;
00086 };
00087
00092 class QWT_EXPORT QwtDoubleSize
00093 {
00094 public:
00095 QwtDoubleSize();
00096 QwtDoubleSize(double width, double height);
00097 QwtDoubleSize(const QSize &);
00098
00099 bool isNull() const;
00100 bool isEmpty() const;
00101 bool isValid() const;
00102
00103 double width() const;
00104 double height() const;
00105 void setWidth( double w );
00106 void setHeight( double h );
00107 void transpose();
00108
00109 QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
00110 QwtDoubleSize boundedTo(const QwtDoubleSize &) const;
00111
00112 bool operator==(const QwtDoubleSize &) const;
00113 bool operator!=(const QwtDoubleSize &) const;
00114
00115 const QwtDoubleSize operator+(const QwtDoubleSize &) const;
00116 const QwtDoubleSize operator-(const QwtDoubleSize &) const;
00117 const QwtDoubleSize operator*(double) const;
00118 const QwtDoubleSize operator/(double) const;
00119
00120 QwtDoubleSize &operator+=(const QwtDoubleSize &);
00121 QwtDoubleSize &operator-=(const QwtDoubleSize &);
00122 QwtDoubleSize &operator*=(double c);
00123 QwtDoubleSize &operator/=(double c);
00124
00125 private:
00126 double d_width;
00127 double d_height;
00128 };
00129
00134 class QWT_EXPORT QwtDoubleRect
00135 {
00136 public:
00137 QwtDoubleRect();
00138 QwtDoubleRect(double left, double top, double width, double height);
00139 QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &);
00140
00141 bool isNull() const;
00142 bool isEmpty() const;
00143 bool isValid() const;
00144
00145 QwtDoubleRect normalized() const;
00146
00147 double left() const;
00148 double right() const;
00149 double top() const;
00150 double bottom() const;
00151
00152 void setLeft(double);
00153 void setRight(double);
00154 void setTop(double);
00155 void setBottom(double);
00156
00157 QwtDoublePoint center() const;
00158
00159 void moveLeft(double x);
00160 void moveRight(double x);
00161 void moveTop(double y );
00162 void moveBottom(double y );
00163 void moveTo(double x, double y);
00164 void moveTo(const QwtDoublePoint &);
00165 void moveBy(double dx, double dy);
00166 void moveCenter(const QwtDoublePoint &);
00167 void moveCenter(double dx, double dy);
00168
00169 void setRect(double x1, double x2, double width, double height);
00170
00171 double width() const;
00172 double height() const;
00173 QwtDoubleSize size() const;
00174
00175 void setWidth(double w );
00176 void setHeight(double h );
00177 void setSize(const QwtDoubleSize &);
00178
00179 QwtDoubleRect operator|(const QwtDoubleRect &r) const;
00180 QwtDoubleRect operator&(const QwtDoubleRect &r) const;
00181 QwtDoubleRect &operator|=(const QwtDoubleRect &r);
00182 QwtDoubleRect &operator&=(const QwtDoubleRect &r);
00183 bool operator==( const QwtDoubleRect &) const;
00184 bool operator!=( const QwtDoubleRect &) const;
00185
00186 bool contains(const QwtDoublePoint &p, bool proper = false) const;
00187 bool contains(double x, double y, bool proper = false) const;
00188 bool contains(const QwtDoubleRect &r, bool proper=false) const;
00189
00190 QwtDoubleRect unite(const QwtDoubleRect &) const;
00191 QwtDoubleRect intersect(const QwtDoubleRect &) const;
00192 bool intersects(const QwtDoubleRect &) const;
00193
00194 private:
00195 double d_left;
00196 double d_right;
00197 double d_top;
00198 double d_bottom;
00199 };
00200
00207 inline bool QwtDoublePoint::isNull() const
00208 {
00209 return d_x == 0.0 && d_y == 0.0;
00210 }
00211
00213 inline double QwtDoublePoint::x() const
00214 {
00215 return d_x;
00216 }
00217
00219 inline double QwtDoublePoint::y() const
00220 {
00221 return d_y;
00222 }
00223
00225 inline double &QwtDoublePoint::rx()
00226 {
00227 return d_x;
00228 }
00229
00231 inline double &QwtDoublePoint::ry()
00232 {
00233 return d_y;
00234 }
00235
00237 inline void QwtDoublePoint::setX(double x)
00238 {
00239 d_x = x;
00240 }
00241
00243 inline void QwtDoublePoint::setY(double y)
00244 {
00245 d_y = y;
00246 }
00247
00252 inline QPoint QwtDoublePoint::toPoint() const
00253 {
00254 return QPoint(qRound(d_x), qRound(d_y));
00255 }
00256
00261 inline bool QwtDoubleSize::isNull() const
00262 {
00263 return d_width == 0.0 && d_height == 0.0;
00264 }
00265
00270 inline bool QwtDoubleSize::isEmpty() const
00271 {
00272 return d_width <= 0.0 || d_height <= 0.0;
00273 }
00274
00279 inline bool QwtDoubleSize::isValid() const
00280 {
00281 return d_width >= 0.0 && d_height >= 0.0;
00282 }
00283
00285 inline double QwtDoubleSize::width() const
00286 {
00287 return d_width;
00288 }
00289
00291 inline double QwtDoubleSize::height() const
00292 {
00293 return d_height;
00294 }
00295
00297 inline void QwtDoubleSize::setWidth(double width)
00298 {
00299 d_width = width;
00300 }
00301
00303 inline void QwtDoubleSize::setHeight(double height)
00304 {
00305 d_height = height;
00306 }
00307
00315 inline bool QwtDoubleRect::isNull() const
00316 {
00317 return d_right == d_left && d_bottom == d_top;
00318 }
00319
00327 inline bool QwtDoubleRect::isEmpty() const
00328 {
00329 return d_left >= d_right || d_top >= d_bottom;
00330 }
00331
00340 inline bool QwtDoubleRect::isValid() const
00341 {
00342 return d_left < d_right && d_top < d_bottom;
00343 }
00344
00346 inline double QwtDoubleRect::left() const
00347 {
00348 return d_left;
00349 }
00350
00352 inline double QwtDoubleRect::right() const
00353 {
00354 return d_right;
00355 }
00356
00358 inline double QwtDoubleRect::top() const
00359 {
00360 return d_top;
00361 }
00362
00364 inline double QwtDoubleRect::bottom() const
00365 {
00366 return d_bottom;
00367 }
00368
00370 inline void QwtDoubleRect::setLeft(double x)
00371 {
00372 d_left = x;
00373 }
00374
00376 inline void QwtDoubleRect::setRight(double x)
00377 {
00378 d_right = x;
00379 }
00380
00382 inline void QwtDoubleRect::setTop(double y)
00383 {
00384 d_top = y;
00385 }
00386
00388 inline void QwtDoubleRect::setBottom(double y)
00389 {
00390 d_bottom = y;
00391 }
00392
00394 inline double QwtDoubleRect::width() const
00395 {
00396 return d_right - d_left;
00397 }
00398
00400 inline double QwtDoubleRect::height() const
00401 {
00402 return d_bottom - d_top;
00403 }
00404
00406 inline QwtDoubleSize QwtDoubleRect::size() const
00407 {
00408 return QwtDoubleSize(width(), height());
00409 }
00410
00412 inline void QwtDoubleRect::setWidth(double w)
00413 {
00414 d_right = d_left + w;
00415 }
00416
00418 inline void QwtDoubleRect::setHeight(double h)
00419 {
00420 d_bottom = d_top + h;
00421 }
00422
00427 inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
00428 {
00429 moveTo(p.x(), p.y());
00430 }
00431
00432
00433 #if defined(QWT_TEMPLATEDLL)
00434 template class QWT_EXPORT QwtArray<QwtDoublePoint>;
00435 #endif
00436
00437
00438 #endif // QT_VERSION < 0x040000
00439
00440 #endif // QWT_DOUBLE_RECT_H