summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qrect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qrect.cpp')
-rw-r--r--src/corelib/tools/qrect.cpp62
1 files changed, 28 insertions, 34 deletions
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index 2082794c2a..b4fe07009a 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -2154,48 +2154,42 @@ bool QRectF::contains(const QRectF &r) const
QRectF QRectF::operator|(const QRectF &r) const
{
- qreal l1 = xp;
- qreal r1 = xp;
- if (w < 0)
- l1 += w;
- else
- r1 += w;
- if (l1 == r1) // null rect
+ if (isNull())
return r;
+ if (r.isNull())
+ return *this;
- qreal l2 = r.xp;
- qreal r2 = r.xp;
- if (r.w < 0)
- l2 += r.w;
+ qreal left = xp;
+ qreal right = xp;
+ if (w < 0)
+ left += w;
else
- r2 += r.w;
- if (l2 == r2) // null rect
- return *this;
+ right += w;
- qreal t1 = yp;
- qreal b1 = yp;
+ if (r.w < 0) {
+ left = qMin(left, r.xp + r.w);
+ right = qMax(right, r.xp);
+ } else {
+ left = qMin(left, r.xp);
+ right = qMax(right, r.xp + r.w);
+ }
+
+ qreal top = yp;
+ qreal bottom = yp;
if (h < 0)
- t1 += h;
+ top += h;
else
- b1 += h;
- if (t1 == b1) // null rect
- return r;
+ bottom += h;
- qreal t2 = r.yp;
- qreal b2 = r.yp;
- if (r.h < 0)
- t2 += r.h;
- else
- b2 += r.h;
- if (t2 == b2) // null rect
- return *this;
+ if (r.h < 0) {
+ top = qMin(top, r.yp + r.h);
+ bottom = qMax(bottom, r.yp);
+ } else {
+ top = qMin(top, r.yp);
+ bottom = qMax(bottom, r.yp + r.h);
+ }
- QRectF tmp;
- tmp.xp = qMin(l1, l2);
- tmp.yp = qMin(t1, t2);
- tmp.w = qMax(r1, r2) - tmp.xp;
- tmp.h = qMax(b1, b2) - tmp.yp;
- return tmp;
+ return QRectF(left, top, right - left, bottom - top);
}
/*!