src/corelib/tools/qrect.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QRECT_H
00025 #define QRECT_H
00026 
00027 #include <QtCore/qsize.h>
00028 #include <QtCore/qpoint.h>
00029 
00030 #ifdef topLeft
00031 #error qrect.h must be included before any header file that defines topLeft
00032 #endif
00033 
00034 QT_BEGIN_HEADER
00035 
00036 QT_MODULE(Core)
00037 
00038 class Q_CORE_EXPORT QRect
00039 {
00040 public:
00041     QRect() { x1 = y1 = 0; x2 = y2 = -1; }
00042     QRect(const QPoint &topleft, const QPoint &bottomright);
00043     QRect(const QPoint &topleft, const QSize &size);
00044     QRect(int left, int top, int width, int height);
00045 
00046     bool isNull() const;
00047     bool isEmpty() const;
00048     bool isValid() const;
00049 
00050     int left() const;
00051     int top() const;
00052     int right() const;
00053     int bottom() const;
00054     QRect normalized() const;
00055 
00056 #ifdef QT3_SUPPORT
00057     QT3_SUPPORT int &rLeft() { return x1; }
00058     QT3_SUPPORT int &rTop() { return y1; }
00059     QT3_SUPPORT int &rRight() { return x2; }
00060     QT3_SUPPORT int &rBottom() { return y2; }
00061 
00062     QT3_SUPPORT QRect normalize() const { return normalized(); }
00063 #endif
00064 
00065     int x() const;
00066     int y() const;
00067     void setLeft(int pos);
00068     void setTop(int pos);
00069     void setRight(int pos);
00070     void setBottom(int pos);
00071     void setX(int x);
00072     void setY(int y);
00073 
00074     void setTopLeft(const QPoint &p);
00075     void setBottomRight(const QPoint &p);
00076     void setTopRight(const QPoint &p);
00077     void setBottomLeft(const QPoint &p);
00078 
00079     QPoint topLeft() const;
00080     QPoint bottomRight() const;
00081     QPoint topRight() const;
00082     QPoint bottomLeft() const;
00083     QPoint center() const;
00084 
00085     void moveLeft(int pos);
00086     void moveTop(int pos);
00087     void moveRight(int pos);
00088     void moveBottom(int pos);
00089     void moveTopLeft(const QPoint &p);
00090     void moveBottomRight(const QPoint &p);
00091     void moveTopRight(const QPoint &p);
00092     void moveBottomLeft(const QPoint &p);
00093     void moveCenter(const QPoint &p);
00094 
00095     inline void translate(int dx, int dy);
00096     inline void translate(const QPoint &p);
00097     inline QRect translated(int dx, int dy) const;
00098     inline QRect translated(const QPoint &p) const;
00099 
00100     void moveTo(int x, int t);
00101     void moveTo(const QPoint &p);
00102 
00103 #ifdef QT3_SUPPORT
00104     QT3_SUPPORT void moveBy(int dx, int dy) { translate(dx, dy); }
00105     QT3_SUPPORT void moveBy(const QPoint &p) { translate(p); }
00106 #endif
00107 
00108     void setRect(int x, int y, int w, int h);
00109     inline void getRect(int *x, int *y, int *w, int *h) const;
00110 
00111     void setCoords(int x1, int y1, int x2, int y2);
00112 #ifdef QT3_SUPPORT
00113     QT3_SUPPORT void addCoords(int x1, int y1, int x2, int y2);
00114 #endif
00115     inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
00116 
00117     inline void adjust(int x1, int y1, int x2, int y2);
00118     inline QRect adjusted(int x1, int y1, int x2, int y2) const;
00119 
00120     QSize size() const;
00121     int width() const;
00122     int height() const;
00123     void setWidth(int w);
00124     void setHeight(int h);
00125     void setSize(const QSize &s);
00126 
00127     QRect operator|(const QRect &r) const;
00128     QRect operator&(const QRect &r) const;
00129     QRect& operator|=(const QRect &r);
00130     QRect& operator&=(const QRect &r);
00131 
00132     bool contains(const QPoint &p, bool proper=false) const;
00133     bool contains(int x, int y) const; // inline methods, _don't_ merge these
00134     bool contains(int x, int y, bool proper) const;
00135     bool contains(const QRect &r, bool proper = false) const;
00136     QRect unite(const QRect &r) const;  // ### Qt 5: make QT4_SUPPORT
00137     QRect united(const QRect &other) const;
00138     QRect intersect(const QRect &r) const;  // ### Qt 5: make QT4_SUPPORT
00139     QRect intersected(const QRect &other) const;
00140     bool intersects(const QRect &r) const;
00141 
00142     friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
00143     friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
00144 
00145 #ifdef QT3_SUPPORT
00146     inline QT3_SUPPORT void rect(int *x, int *y, int *w, int *h) const { getRect(x, y, w, h); }
00147     inline QT3_SUPPORT void coords(int *ax1, int *ay1, int *ax2, int *ay2) const
00148     { getCoords(ax1, ay1, ax2, ay2); }
00149 #endif
00150 
00151 private:
00152 #if defined(Q_WS_X11) || defined(Q_OS_TEMP)
00153     friend void qt_setCoords(QRect *r, int xp1, int yp1, int xp2, int yp2);
00154 #endif
00155 #if defined(Q_OS_MAC)
00156     int y1;
00157     int x1;
00158     int y2;
00159     int x2;
00160 #else
00161     int x1;
00162     int y1;
00163     int x2;
00164     int y2;
00165 #endif
00166 
00167 };
00168 Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
00169 
00170 Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
00171 Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
00172 
00173 
00174 /*****************************************************************************
00175   QRect stream functions
00176  *****************************************************************************/
00177 #ifndef QT_NO_DATASTREAM
00178 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRect &);
00179 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
00180 #endif
00181 
00182 /*****************************************************************************
00183   QRect inline member functions
00184  *****************************************************************************/
00185 
00186 inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
00187 {
00188     x1 = aleft;
00189     y1 = atop;
00190     x2 = (aleft + awidth - 1);
00191     y2 = (atop + aheight - 1);
00192 }
00193 
00194 inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
00195 {
00196     x1 = atopLeft.x();
00197     y1 = atopLeft.y();
00198     x2 = abottomRight.x();
00199     y2 = abottomRight.y();
00200 }
00201 
00202 inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
00203 {
00204     x1 = atopLeft.x();
00205     y1 = atopLeft.y();
00206     x2 = (x1+asize.width() - 1);
00207     y2 = (y1+asize.height() - 1);
00208 }
00209 
00210 inline bool QRect::isNull() const
00211 { return x2 == x1 - 1 && y2 == y1 - 1; }
00212 
00213 inline bool QRect::isEmpty() const
00214 { return x1 > x2 || y1 > y2; }
00215 
00216 inline bool QRect::isValid() const
00217 { return x1 <= x2 && y1 <= y2; }
00218 
00219 inline int QRect::left() const
00220 { return x1; }
00221 
00222 inline int QRect::top() const
00223 { return y1; }
00224 
00225 inline int QRect::right() const
00226 { return x2; }
00227 
00228 inline int QRect::bottom() const
00229 { return y2; }
00230 
00231 inline int QRect::x() const
00232 { return x1; }
00233 
00234 inline int QRect::y() const
00235 { return y1; }
00236 
00237 inline void QRect::setLeft(int pos)
00238 { x1 = pos; }
00239 
00240 inline void QRect::setTop(int pos)
00241 { y1 = pos; }
00242 
00243 inline void QRect::setRight(int pos)
00244 { x2 = pos; }
00245 
00246 inline void QRect::setBottom(int pos)
00247 { y2 = pos; }
00248 
00249 inline void QRect::setTopLeft(const QPoint &p)
00250 { x1 = p.x(); y1 = p.y(); }
00251 
00252 inline void QRect::setBottomRight(const QPoint &p)
00253 { x2 = p.x(); y2 = p.y(); }
00254 
00255 inline void QRect::setTopRight(const QPoint &p)
00256 { x2 = p.x(); y1 = p.y(); }
00257 
00258 inline void QRect::setBottomLeft(const QPoint &p)
00259 { x1 = p.x(); y2 = p.y(); }
00260 
00261 inline void QRect::setX(int ax)
00262 { x1 = ax; }
00263 
00264 inline void QRect::setY(int ay)
00265 { y1 = ay; }
00266 
00267 inline QPoint QRect::topLeft() const
00268 { return QPoint(x1, y1); }
00269 
00270 inline QPoint QRect::bottomRight() const
00271 { return QPoint(x2, y2); }
00272 
00273 inline QPoint QRect::topRight() const
00274 { return QPoint(x2, y1); }
00275 
00276 inline QPoint QRect::bottomLeft() const
00277 { return QPoint(x1, y2); }
00278 
00279 inline QPoint QRect::center() const
00280 { return QPoint((x1+x2)/2, (y1+y2)/2); }
00281 
00282 inline int QRect::width() const
00283 { return  x2 - x1 + 1; }
00284 
00285 inline int QRect::height() const
00286 { return  y2 - y1 + 1; }
00287 
00288 inline QSize QRect::size() const
00289 { return QSize(width(), height()); }
00290 
00291 inline void QRect::translate(int dx, int dy)
00292 {
00293     x1 += dx;
00294     y1 += dy;
00295     x2 += dx;
00296     y2 += dy;
00297 }
00298 
00299 inline void QRect::translate(const QPoint &p)
00300 {
00301     x1 += p.x();
00302     y1 += p.y();
00303     x2 += p.x();
00304     y2 += p.y();
00305 }
00306 
00307 inline QRect QRect::translated(int dx, int dy) const
00308 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
00309 
00310 inline QRect QRect::translated(const QPoint &p) const
00311 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
00312 
00313 inline void QRect::moveTo(int ax, int ay)
00314 {
00315     x2 += ax - x1;
00316     y2 += ay - y1;
00317     x1 = ax;
00318     y1 = ay;
00319 }
00320 
00321 inline void QRect::moveTo(const QPoint &p)
00322 {
00323     x2 += p.x() - x1;
00324     y2 += p.y() - y1;
00325     x1 = p.x();
00326     y1 = p.y();
00327 }
00328 
00329 inline void QRect::moveLeft(int pos)
00330 { x2 += (pos - x1); x1 = pos; }
00331 
00332 inline void QRect::moveTop(int pos)
00333 { y2 += (pos - y1); y1 = pos; }
00334 
00335 inline void QRect::moveRight(int pos)
00336 {
00337     x1 += (pos - x2);
00338     x2 = pos;
00339 }
00340 
00341 inline void QRect::moveBottom(int pos)
00342 {
00343     y1 += (pos - y2);
00344     y2 = pos;
00345 }
00346 
00347 inline void QRect::moveTopLeft(const QPoint &p)
00348 {
00349     moveLeft(p.x());
00350     moveTop(p.y());
00351 }
00352 
00353 inline void QRect::moveBottomRight(const QPoint &p)
00354 {
00355     moveRight(p.x());
00356     moveBottom(p.y());
00357 }
00358 
00359 inline void QRect::moveTopRight(const QPoint &p)
00360 {
00361     moveRight(p.x());
00362     moveTop(p.y());
00363 }
00364 
00365 inline void QRect::moveBottomLeft(const QPoint &p)
00366 {
00367     moveLeft(p.x());
00368     moveBottom(p.y());
00369 }
00370 
00371 inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
00372 {
00373     *ax = x1;
00374     *ay = y1;
00375     *aw = x2 - x1 + 1;
00376     *ah = y2 - y1 + 1;
00377 }
00378 
00379 inline void QRect::setRect(int ax, int ay, int aw, int ah)
00380 {
00381     x1 = ax;
00382     y1 = ay;
00383     x2 = (ax + aw - 1);
00384     y2 = (ay + ah - 1);
00385 }
00386 
00387 inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
00388 {
00389     *xp1 = x1;
00390     *yp1 = y1;
00391     *xp2 = x2;
00392     *yp2 = y2;
00393 }
00394 
00395 inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
00396 {
00397     x1 = xp1;
00398     y1 = yp1;
00399     x2 = xp2;
00400     y2 = yp2;
00401 }
00402 
00403 #ifdef QT3_SUPPORT
00404 inline void QRect::addCoords(int dx1, int dy1, int dx2, int dy2)
00405 {
00406     adjust(dx1, dy1, dx2, dy2);
00407 }
00408 #endif
00409 
00410 inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
00411 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
00412 
00413 inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
00414 {
00415     x1 += dx1;
00416     y1 += dy1;
00417     x2 += dx2;
00418     y2 += dy2;
00419 }
00420 
00421 inline void QRect::setWidth(int w)
00422 { x2 = (x1 + w - 1); }
00423 
00424 inline void QRect::setHeight(int h)
00425 { y2 = (y1 + h - 1); }
00426 
00427 inline void QRect::setSize(const QSize &s)
00428 {
00429     x2 = (s.width()  + x1 - 1);
00430     y2 = (s.height() + y1 - 1);
00431 }
00432 
00433 inline bool QRect::contains(int ax, int ay, bool aproper) const
00434 {
00435     return contains(QPoint(ax, ay), aproper);
00436 }
00437 
00438 inline bool QRect::contains(int ax, int ay) const
00439 {
00440     return contains(QPoint(ax, ay), false);
00441 }
00442 
00443 inline QRect& QRect::operator|=(const QRect &r)
00444 {
00445     *this = *this | r;
00446     return *this;
00447 }
00448 
00449 inline QRect& QRect::operator&=(const QRect &r)
00450 {
00451     *this = *this & r;
00452     return *this;
00453 }
00454 
00455 inline QRect QRect::intersect(const QRect &r) const
00456 {
00457     return *this & r;
00458 }
00459 
00460 inline QRect QRect::intersected(const QRect &other) const 
00461 { 
00462     return intersect(other); 
00463 }
00464 
00465 inline QRect QRect::unite(const QRect &r) const
00466 {
00467     return *this | r;
00468 }
00469 
00470 inline QRect QRect::united(const QRect &r) const
00471 { 
00472      return unite(r); 
00473 }
00474 
00475 inline bool operator==(const QRect &r1, const QRect &r2)
00476 {
00477     return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
00478 }
00479 
00480 inline bool operator!=(const QRect &r1, const QRect &r2)
00481 {
00482     return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
00483 }
00484 
00485 #ifndef QT_NO_DEBUG_STREAM
00486 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
00487 #endif
00488 
00489 
00490 class Q_CORE_EXPORT QRectF
00491 {
00492 public:
00493     QRectF() { xp = yp = 0.; w = h = 0.; }
00494     QRectF(const QPointF &topleft, const QSizeF &size);
00495     QRectF(qreal left, qreal top, qreal width, qreal height);
00496     QRectF(const QRect &rect);
00497 
00498     bool isNull() const;
00499     bool isEmpty() const;
00500     bool isValid() const;
00501     QRectF normalized() const;
00502 
00503     inline qreal left() const { return xp; }
00504     inline qreal top() const { return yp; }
00505     inline qreal right() const { return xp + w; }
00506     inline qreal bottom() const { return yp + h; }
00507 
00508     inline qreal x() const;
00509     inline qreal y() const;
00510     inline void setLeft(qreal pos);
00511     inline void setTop(qreal pos);
00512     inline void setRight(qreal pos);
00513     inline void setBottom(qreal pos);
00514     inline void setX(qreal pos) { setLeft(pos); }
00515     inline void setY(qreal pos) { setTop(pos); }
00516 
00517     inline QPointF topLeft() const { return QPointF(xp, yp); }
00518     inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
00519     inline QPointF topRight() const { return QPointF(xp+w, yp); }
00520     inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
00521     inline QPointF center() const;
00522 
00523     void setTopLeft(const QPointF &p);
00524     void setBottomRight(const QPointF &p);
00525     void setTopRight(const QPointF &p);
00526     void setBottomLeft(const QPointF &p);
00527 
00528     void moveLeft(qreal pos);
00529     void moveTop(qreal pos);
00530     void moveRight(qreal pos);
00531     void moveBottom(qreal pos);
00532     void moveTopLeft(const QPointF &p);
00533     void moveBottomRight(const QPointF &p);
00534     void moveTopRight(const QPointF &p);
00535     void moveBottomLeft(const QPointF &p);
00536     void moveCenter(const QPointF &p);
00537 
00538     void translate(qreal dx, qreal dy);
00539     void translate(const QPointF &p);
00540 
00541     QRectF translated(qreal dx, qreal dy) const;
00542     QRectF translated(const QPointF &p) const;
00543 
00544     void moveTo(qreal x, qreal t);
00545     void moveTo(const QPointF &p);
00546 
00547     void setRect(qreal x, qreal y, qreal w, qreal h);
00548     void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
00549 
00550     void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
00551     void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
00552 
00553     inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
00554     inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const;
00555 
00556     QSizeF size() const;
00557     qreal width() const;
00558     qreal height() const;
00559     void setWidth(qreal w);
00560     void setHeight(qreal h);
00561     void setSize(const QSizeF &s);
00562 
00563     QRectF operator|(const QRectF &r) const;
00564     QRectF operator&(const QRectF &r) const;
00565     QRectF& operator|=(const QRectF &r);
00566     QRectF& operator&=(const QRectF &r);
00567 
00568     bool contains(const QPointF &p) const;
00569     bool contains(qreal x, qreal y) const;
00570     bool contains(const QRectF &r) const;
00571     QRectF unite(const QRectF &r) const;  // ### Qt 5: make QT4_SUPPORT
00572     QRectF united(const QRectF &other) const;
00573     QRectF intersect(const QRectF &r) const;  // ### Qt 5: make QT4_SUPPORT
00574     QRectF intersected(const QRectF &other) const;
00575     bool intersects(const QRectF &r) const;
00576 
00577     friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
00578     friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
00579 
00580     QRect toRect() const;
00581 
00582 private:
00583     qreal xp;
00584     qreal yp;
00585     qreal w;
00586     qreal h;
00587 };
00588 Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
00589 
00590 Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
00591 Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
00592 
00593 
00594 /*****************************************************************************
00595   QRectF stream functions
00596  *****************************************************************************/
00597 #ifndef QT_NO_DATASTREAM
00598 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRectF &);
00599 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
00600 #endif
00601 
00602 /*****************************************************************************
00603   QRectF inline member functions
00604  *****************************************************************************/
00605 
00606 inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
00607     : xp(aleft), yp(atop), w(awidth), h(aheight)
00608 {
00609 }
00610 
00611 inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
00612 {
00613     xp = atopLeft.x();
00614     yp = atopLeft.y();
00615     w = asize.width();
00616     h = asize.height();
00617 }
00618 
00619 inline QRectF::QRectF(const QRect &r)
00620     : xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
00621 {
00622 }
00623 
00624 inline bool QRectF::isNull() const
00625 { return qIsNull(w) && qIsNull(h); }
00626 
00627 inline bool QRectF::isEmpty() const
00628 { return w <= 0. || h <= 0.; }
00629 
00630 inline bool QRectF::isValid() const
00631 { return w > 0. && h > 0.; }
00632 
00633 inline qreal QRectF::x() const
00634 { return xp; }
00635 
00636 inline qreal QRectF::y() const
00637 { return yp; }
00638 
00639 inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
00640 
00641 inline void QRectF::setRight(qreal pos) { w = pos - xp; }
00642 
00643 inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
00644 
00645 inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
00646 
00647 inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
00648 
00649 inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
00650 
00651 inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
00652 
00653 inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
00654 
00655 inline QPointF QRectF::center() const
00656 { return QPointF(xp + w/2, yp + h/2); }
00657 
00658 inline void QRectF::moveLeft(qreal pos) { xp = pos; }
00659 
00660 inline void QRectF::moveTop(qreal pos) { yp = pos; }
00661 
00662 inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
00663 
00664 inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
00665 
00666 inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
00667 
00668 inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
00669 
00670 inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
00671 
00672 inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
00673 
00674 inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
00675 
00676 inline qreal QRectF::width() const
00677 { return w; }
00678 
00679 inline qreal QRectF::height() const
00680 { return h; }
00681 
00682 inline QSizeF QRectF::size() const
00683 { return QSizeF(w, h); }
00684 
00685 inline void QRectF::translate(qreal dx, qreal dy)
00686 {
00687     xp += dx;
00688     yp += dy;
00689 }
00690 
00691 inline void QRectF::translate(const QPointF &p)
00692 {
00693     xp += p.x();
00694     yp += p.y();
00695 }
00696 
00697 inline void QRectF::moveTo(qreal ax, qreal ay)
00698 {
00699     xp = ax;
00700     yp = ay;
00701 }
00702 
00703 inline void QRectF::moveTo(const QPointF &p)
00704 {
00705     xp = p.x();
00706     yp = p.y();
00707 }
00708 
00709 inline QRectF QRectF::translated(qreal dx, qreal dy) const
00710 { return QRectF(xp + dx, yp + dy, w, h); }
00711 
00712 inline QRectF QRectF::translated(const QPointF &p) const
00713 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
00714 
00715 inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
00716 {
00717     *ax = this->xp;
00718     *ay = this->yp;
00719     *aaw = this->w;
00720     *aah = this->h;
00721 }
00722 
00723 inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
00724 {
00725     this->xp = ax;
00726     this->yp = ay;
00727     this->w = aaw;
00728     this->h = aah;
00729 }
00730 
00731 inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
00732 {
00733     *xp1 = xp;
00734     *yp1 = yp;
00735     *xp2 = xp + w;
00736     *yp2 = yp + h;
00737 }
00738 
00739 inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
00740 {
00741     xp = xp1;
00742     yp = yp1;
00743     w = xp2 - xp1;
00744     h = yp2 - yp1;
00745 }
00746 
00747 inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
00748 { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
00749 
00750 inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
00751 { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
00752 
00753 inline void QRectF::setWidth(qreal aw)
00754 { this->w = aw; }
00755 
00756 inline void QRectF::setHeight(qreal ah)
00757 { this->h = ah; }
00758 
00759 inline void QRectF::setSize(const QSizeF &s)
00760 {
00761     w = s.width();
00762     h = s.height();
00763 }
00764 
00765 inline bool QRectF::contains(qreal ax, qreal ay) const
00766 {
00767     return contains(QPointF(ax, ay));
00768 }
00769 
00770 inline QRectF& QRectF::operator|=(const QRectF &r)
00771 {
00772     *this = *this | r;
00773     return *this;
00774 }
00775 
00776 inline QRectF& QRectF::operator&=(const QRectF &r)
00777 {
00778     *this = *this & r;
00779     return *this;
00780 }
00781 
00782 inline QRectF QRectF::intersect(const QRectF &r) const
00783 {
00784     return *this & r;
00785 }
00786 
00787 inline QRectF QRectF::intersected(const QRectF &r) const
00788 { 
00789     return intersect(r); 
00790 }
00791 
00792 inline QRectF QRectF::unite(const QRectF &r) const
00793 {
00794     return *this | r;
00795 }
00796 
00797 inline QRectF QRectF::united(const QRectF &r) const
00798 {
00799     return unite(r);
00800 }
00801 
00802 inline bool operator==(const QRectF &r1, const QRectF &r2)
00803 {
00804     return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
00805            && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
00806 }
00807 
00808 inline bool operator!=(const QRectF &r1, const QRectF &r2)
00809 {
00810     return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
00811            || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
00812 }
00813 
00814 inline QRect QRectF::toRect() const
00815 {
00816     return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
00817 }
00818 
00819 #ifndef QT_NO_DEBUG_STREAM
00820 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &);
00821 #endif
00822 
00823 QT_END_HEADER
00824 
00825 #endif // QRECT_H

Generated on Thu Mar 15 11:54:10 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1