diff options
Diffstat (limited to 'src/corelib/tools/qrect.h')
-rw-r--r-- | src/corelib/tools/qrect.h | 242 |
1 files changed, 111 insertions, 131 deletions
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index bc9a4d68be..4bf10061ab 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -57,23 +57,23 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QRect { public: - QRect() { x1 = y1 = 0; x2 = y2 = -1; } - QRect(const QPoint &topleft, const QPoint &bottomright); - QRect(const QPoint &topleft, const QSize &size); - QRect(int left, int top, int width, int height); - - bool isNull() const; - bool isEmpty() const; - bool isValid() const; - - int left() const; - int top() const; - int right() const; - int bottom() const; + Q_DECL_CONSTEXPR QRect() : x1(0), y1(0), x2(-1), y2(-1) {} + Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright); + Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size); + Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height); + + Q_DECL_CONSTEXPR bool isNull() const; + Q_DECL_CONSTEXPR bool isEmpty() const; + Q_DECL_CONSTEXPR bool isValid() const; + + Q_DECL_CONSTEXPR int left() const; + Q_DECL_CONSTEXPR int top() const; + Q_DECL_CONSTEXPR int right() const; + Q_DECL_CONSTEXPR int bottom() const; QRect normalized() const; - int x() const; - int y() const; + Q_DECL_CONSTEXPR int x() const; + Q_DECL_CONSTEXPR int y() const; void setLeft(int pos); void setTop(int pos); void setRight(int pos); @@ -86,11 +86,11 @@ public: void setTopRight(const QPoint &p); void setBottomLeft(const QPoint &p); - QPoint topLeft() const; - QPoint bottomRight() const; - QPoint topRight() const; - QPoint bottomLeft() const; - QPoint center() const; + Q_DECL_CONSTEXPR QPoint topLeft() const; + Q_DECL_CONSTEXPR QPoint bottomRight() const; + Q_DECL_CONSTEXPR QPoint topRight() const; + Q_DECL_CONSTEXPR QPoint bottomLeft() const; + Q_DECL_CONSTEXPR QPoint center() const; void moveLeft(int pos); void moveTop(int pos); @@ -104,8 +104,8 @@ public: inline void translate(int dx, int dy); inline void translate(const QPoint &p); - inline QRect translated(int dx, int dy) const; - inline QRect translated(const QPoint &p) const; + Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const; + Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const; void moveTo(int x, int t); void moveTo(const QPoint &p); @@ -117,11 +117,11 @@ public: inline void getCoords(int *x1, int *y1, int *x2, int *y2) const; inline void adjust(int x1, int y1, int x2, int y2); - inline QRect adjusted(int x1, int y1, int x2, int y2) const; + Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const; - QSize size() const; - int width() const; - int height() const; + Q_DECL_CONSTEXPR QSize size() const; + Q_DECL_CONSTEXPR int width() const; + Q_DECL_CONSTEXPR int height() const; void setWidth(int w); void setHeight(int h); void setSize(const QSize &s); @@ -144,8 +144,8 @@ public: QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); } #endif - friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &); - friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &); + friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &); + friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &); private: int x1; @@ -155,8 +155,8 @@ private: }; Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE); -Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &); -Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &); +Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &); +Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &); /***************************************************************************** @@ -171,55 +171,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &); QRect inline member functions *****************************************************************************/ -inline QRect::QRect(int aleft, int atop, int awidth, int aheight) -{ - x1 = aleft; - y1 = atop; - x2 = (aleft + awidth - 1); - y2 = (atop + aheight - 1); -} +Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) + : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {} -inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) -{ - x1 = atopLeft.x(); - y1 = atopLeft.y(); - x2 = abottomRight.x(); - y2 = abottomRight.y(); -} +Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) + : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {} -inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) -{ - x1 = atopLeft.x(); - y1 = atopLeft.y(); - x2 = (x1+asize.width() - 1); - y2 = (y1+asize.height() - 1); -} +Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) + : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {} -inline bool QRect::isNull() const +Q_DECL_CONSTEXPR inline bool QRect::isNull() const { return x2 == x1 - 1 && y2 == y1 - 1; } -inline bool QRect::isEmpty() const +Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const { return x1 > x2 || y1 > y2; } -inline bool QRect::isValid() const +Q_DECL_CONSTEXPR inline bool QRect::isValid() const { return x1 <= x2 && y1 <= y2; } -inline int QRect::left() const +Q_DECL_CONSTEXPR inline int QRect::left() const { return x1; } -inline int QRect::top() const +Q_DECL_CONSTEXPR inline int QRect::top() const { return y1; } -inline int QRect::right() const +Q_DECL_CONSTEXPR inline int QRect::right() const { return x2; } -inline int QRect::bottom() const +Q_DECL_CONSTEXPR inline int QRect::bottom() const { return y2; } -inline int QRect::x() const +Q_DECL_CONSTEXPR inline int QRect::x() const { return x1; } -inline int QRect::y() const +Q_DECL_CONSTEXPR inline int QRect::y() const { return y1; } inline void QRect::setLeft(int pos) @@ -252,28 +237,28 @@ inline void QRect::setX(int ax) inline void QRect::setY(int ay) { y1 = ay; } -inline QPoint QRect::topLeft() const +Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const { return QPoint(x1, y1); } -inline QPoint QRect::bottomRight() const +Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const { return QPoint(x2, y2); } -inline QPoint QRect::topRight() const +Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const { return QPoint(x2, y1); } -inline QPoint QRect::bottomLeft() const +Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const { return QPoint(x1, y2); } -inline QPoint QRect::center() const +Q_DECL_CONSTEXPR inline QPoint QRect::center() const { return QPoint((x1+x2)/2, (y1+y2)/2); } -inline int QRect::width() const +Q_DECL_CONSTEXPR inline int QRect::width() const { return x2 - x1 + 1; } -inline int QRect::height() const +Q_DECL_CONSTEXPR inline int QRect::height() const { return y2 - y1 + 1; } -inline QSize QRect::size() const +Q_DECL_CONSTEXPR inline QSize QRect::size() const { return QSize(width(), height()); } inline void QRect::translate(int dx, int dy) @@ -292,10 +277,10 @@ inline void QRect::translate(const QPoint &p) y2 += p.y(); } -inline QRect QRect::translated(int dx, int dy) const +Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } -inline QRect QRect::translated(const QPoint &p) const +Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } inline void QRect::moveTo(int ax, int ay) @@ -388,7 +373,7 @@ inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) y2 = yp2; } -inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const +Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) @@ -443,12 +428,12 @@ inline QRect QRect::united(const QRect &r) const return *this | r; } -inline bool operator==(const QRect &r1, const QRect &r2) +Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) { return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; } -inline bool operator!=(const QRect &r1, const QRect &r2) +Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) { return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2; } @@ -461,24 +446,24 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &); class Q_CORE_EXPORT QRectF { public: - QRectF() { xp = yp = 0.; w = h = 0.; } - QRectF(const QPointF &topleft, const QSizeF &size); - QRectF(const QPointF &topleft, const QPointF &bottomRight); - QRectF(qreal left, qreal top, qreal width, qreal height); - QRectF(const QRect &rect); - - bool isNull() const; - bool isEmpty() const; - bool isValid() const; + Q_DECL_CONSTEXPR QRectF() : xp(0.), yp(0.), w(0.), h(0.) {} + Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size); + Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight); + Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height); + Q_DECL_CONSTEXPR QRectF(const QRect &rect); + + Q_DECL_CONSTEXPR bool isNull() const; + Q_DECL_CONSTEXPR bool isEmpty() const; + Q_DECL_CONSTEXPR bool isValid() const; QRectF normalized() const; - inline qreal left() const { return xp; } - inline qreal top() const { return yp; } - inline qreal right() const { return xp + w; } - inline qreal bottom() const { return yp + h; } + Q_DECL_CONSTEXPR inline qreal left() const { return xp; } + Q_DECL_CONSTEXPR inline qreal top() const { return yp; } + Q_DECL_CONSTEXPR inline qreal right() const { return xp + w; } + Q_DECL_CONSTEXPR inline qreal bottom() const { return yp + h; } - inline qreal x() const; - inline qreal y() const; + Q_DECL_CONSTEXPR inline qreal x() const; + Q_DECL_CONSTEXPR inline qreal y() const; inline void setLeft(qreal pos); inline void setTop(qreal pos); inline void setRight(qreal pos); @@ -486,11 +471,11 @@ public: inline void setX(qreal pos) { setLeft(pos); } inline void setY(qreal pos) { setTop(pos); } - inline QPointF topLeft() const { return QPointF(xp, yp); } - inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); } - inline QPointF topRight() const { return QPointF(xp+w, yp); } - inline QPointF bottomLeft() const { return QPointF(xp, yp+h); } - inline QPointF center() const; + Q_DECL_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); } + Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); } + Q_DECL_CONSTEXPR inline QPointF topRight() const { return QPointF(xp+w, yp); } + Q_DECL_CONSTEXPR inline QPointF bottomLeft() const { return QPointF(xp, yp+h); } + Q_DECL_CONSTEXPR inline QPointF center() const; void setTopLeft(const QPointF &p); void setBottomRight(const QPointF &p); @@ -510,8 +495,8 @@ public: void translate(qreal dx, qreal dy); void translate(const QPointF &p); - QRectF translated(qreal dx, qreal dy) const; - QRectF translated(const QPointF &p) const; + Q_DECL_CONSTEXPR QRectF translated(qreal dx, qreal dy) const; + Q_DECL_CONSTEXPR QRectF translated(const QPointF &p) const; void moveTo(qreal x, qreal t); void moveTo(const QPointF &p); @@ -523,11 +508,11 @@ public: void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const; inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2); - inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const; + Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const; - QSizeF size() const; - qreal width() const; - qreal height() const; + Q_DECL_CONSTEXPR QSizeF size() const; + Q_DECL_CONSTEXPR qreal width() const; + Q_DECL_CONSTEXPR qreal height() const; void setWidth(qreal w); void setHeight(qreal h); void setSize(const QSizeF &s); @@ -549,10 +534,10 @@ public: QT_DEPRECATED QRectF intersect(const QRectF &r) const { return intersected(r); } #endif - friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &); - friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &); + friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &); + friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &); - QRect toRect() const; + Q_DECL_CONSTEXPR QRect toRect() const; QRect toAlignedRect() const; private: @@ -563,8 +548,8 @@ private: }; Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE); -Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &); -Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &); +Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &); +Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &); /***************************************************************************** @@ -579,45 +564,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &); QRectF inline member functions *****************************************************************************/ -inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) +Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) : xp(aleft), yp(atop), w(awidth), h(aheight) { } -inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) + : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height()) { - xp = atopLeft.x(); - yp = atopLeft.y(); - w = asize.width(); - h = asize.height(); } -inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) + +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) + : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y()) { - xp = atopLeft.x(); - yp = atopLeft.y(); - w = abottomRight.x() - xp; - h = abottomRight.y() - yp; } -inline QRectF::QRectF(const QRect &r) +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) : xp(r.x()), yp(r.y()), w(r.width()), h(r.height()) { } -inline bool QRectF::isNull() const +Q_DECL_CONSTEXPR inline bool QRectF::isNull() const { return w == 0. && h == 0.; } -inline bool QRectF::isEmpty() const +Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const { return w <= 0. || h <= 0.; } -inline bool QRectF::isValid() const +Q_DECL_CONSTEXPR inline bool QRectF::isValid() const { return w > 0. && h > 0.; } -inline qreal QRectF::x() const +Q_DECL_CONSTEXPR inline qreal QRectF::x() const { return xp; } -inline qreal QRectF::y() const +Q_DECL_CONSTEXPR inline qreal QRectF::y() const { return yp; } inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; } @@ -636,7 +616,7 @@ inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom( inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); } -inline QPointF QRectF::center() const +Q_DECL_CONSTEXPR inline QPointF QRectF::center() const { return QPointF(xp + w/2, yp + h/2); } inline void QRectF::moveLeft(qreal pos) { xp = pos; } @@ -657,13 +637,13 @@ inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBo inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; } -inline qreal QRectF::width() const +Q_DECL_CONSTEXPR inline qreal QRectF::width() const { return w; } -inline qreal QRectF::height() const +Q_DECL_CONSTEXPR inline qreal QRectF::height() const { return h; } -inline QSizeF QRectF::size() const +Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const { return QSizeF(w, h); } inline void QRectF::translate(qreal dx, qreal dy) @@ -690,10 +670,10 @@ inline void QRectF::moveTo(const QPointF &p) yp = p.y(); } -inline QRectF QRectF::translated(qreal dx, qreal dy) const +Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const { return QRectF(xp + dx, yp + dy, w, h); } -inline QRectF QRectF::translated(const QPointF &p) const +Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const { return QRectF(xp + p.x(), yp + p.y(), w, h); } inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const @@ -731,7 +711,7 @@ inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } -inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const +Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } inline void QRectF::setWidth(qreal aw) @@ -773,19 +753,19 @@ inline QRectF QRectF::united(const QRectF &r) const return *this | r; } -inline bool operator==(const QRectF &r1, const QRectF &r2) +Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) { return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp) && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h); } -inline bool operator!=(const QRectF &r1, const QRectF &r2) +Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) { return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp) || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h); } -inline QRect QRectF::toRect() const +Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const { return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); } |