QRect - Add missing QMargins subtraction operator

[ChangeLog][QtCore][QRect] Added QMargins subtraction operator.

Change-Id: I64d449e2bae81a34df2cd019cff3fb186f8aaaae
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
John Layt 2014-02-15 16:07:52 +01:00 committed by The Qt Project
parent 9c6447e081
commit c7aa3a6925
3 changed files with 19 additions and 0 deletions

View File

@ -1181,6 +1181,15 @@ bool QRect::intersects(const QRect &r) const
\since 5.1
*/
/*!
\fn QRect operator-(const QRect &lhs, const QMargins &rhs)
\relates QRect
Returns the \a lhs rectangle shrunken by the \a rhs margins.
\since 5.3
*/
/*!
\fn QRect QRect::marginsAdded(const QMargins &margins) const

View File

@ -463,6 +463,12 @@ Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &re
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
}
Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs)
{
return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
}
Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const
{
return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),

View File

@ -3496,6 +3496,10 @@ void tst_QRect::margins()
QCOMPARE(added, margins + rectangle);
QCOMPARE(added, rectangle.marginsAdded(margins));
const QRect subtracted = rectangle - margins;
QCOMPARE(subtracted, QRect(QPoint(12, 13), QSize(44, 42)));
QCOMPARE(subtracted, rectangle.marginsRemoved(margins));
QRect a = rectangle;
a += margins;
QCOMPARE(added, a);