Add API dealing with QMargins to QRect.
- Addition of a QMargin to a QRect. - Removal of a QMargin from a QRect. - Remove implementation from Windows platform plugin. Change-Id: Iae54bc13e94a7ece48853b1d3f3de2bfc154d2dd Reviewed-by: Oliver Wolff <oliver.wolff@digia.com> Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
This commit is contained in:
parent
41ec7c32ac
commit
6ecc3e76e8
5
dist/changes-5.1.0
vendored
5
dist/changes-5.1.0
vendored
@ -46,6 +46,11 @@ Third party components
|
||||
QtCore
|
||||
------
|
||||
|
||||
- QRect:
|
||||
* Added marginsAdded(), marginsRemoved() and operators +, -, +=, -=
|
||||
taking a QMargins object allowing for conveniently adding or removing
|
||||
margins.
|
||||
|
||||
-
|
||||
|
||||
QtGui
|
||||
|
@ -157,6 +157,65 @@ QT_BEGIN_NAMESPACE
|
||||
Returns true if \a m1 and \a m2 are different; otherwise returns false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect operator+(const QRect &rectangle, const QMargins &margins)
|
||||
\relates QRect
|
||||
|
||||
Returns the \a rectangle grown by the \a margins.
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect operator+(const QMargins &margins, const QRect &rectangle)
|
||||
\relates QRect
|
||||
\overload
|
||||
|
||||
Returns the \a rectangle grown by the \a margins.
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect QRect::marginsAdded(const QMargins &margins) const
|
||||
|
||||
Returns a rectangle grown by the \a margins.
|
||||
|
||||
\sa operator+=(), marginsRemoved(), operator-=()
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect QRect::operator+=(const QMargins &margins) const
|
||||
|
||||
Adds the \a margins to the rectangle, growing it.
|
||||
|
||||
\sa marginsAdded(), marginsRemoved(), operator-=()
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect QRect::marginsRemoved(const QMargins &margins) const
|
||||
|
||||
Removes the \a margins from the rectangle, shrinking it.
|
||||
|
||||
\sa marginsAdded(), operator+=(), operator-=()
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QRect QRect::operator -=(const QMargins &margins) const
|
||||
|
||||
Returns a rectangle shrunk by the \a margins.
|
||||
|
||||
\sa marginsRemoved(), operator+=(), marginsAdded()
|
||||
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
QMargins stream functions
|
||||
*****************************************************************************/
|
||||
|
@ -42,7 +42,7 @@
|
||||
#ifndef QMARGINS_H
|
||||
#define QMARGINS_H
|
||||
|
||||
#include <QtCore/qnamespace.h>
|
||||
#include <QtCore/qrect.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
@ -142,6 +142,41 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
|
||||
m1.m_bottom != m2.m_bottom;
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins)
|
||||
{
|
||||
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
|
||||
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle)
|
||||
{
|
||||
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
|
||||
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
|
||||
}
|
||||
|
||||
inline QRect QRect::marginsAdded(const QMargins &margins) const
|
||||
{
|
||||
return *this + margins;
|
||||
}
|
||||
|
||||
inline QRect QRect::marginsRemoved(const QMargins &margins) const
|
||||
{
|
||||
return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
|
||||
QPoint(x2 - margins.right(), y2 - margins.bottom()));
|
||||
}
|
||||
|
||||
inline QRect &QRect::operator+=(const QMargins &margins)
|
||||
{
|
||||
*this = marginsAdded(margins);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline QRect &QRect::operator-=(const QMargins &margins)
|
||||
{
|
||||
*this = marginsRemoved(margins);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
|
||||
#endif
|
||||
|
@ -53,6 +53,7 @@ QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QMargins;
|
||||
|
||||
class Q_CORE_EXPORT QRect
|
||||
{
|
||||
@ -139,6 +140,11 @@ public:
|
||||
inline QRect intersected(const QRect &other) const;
|
||||
bool intersects(const QRect &r) const;
|
||||
|
||||
inline QRect marginsAdded(const QMargins &margins) const;
|
||||
inline QRect marginsRemoved(const QMargins &margins) const;
|
||||
inline QRect &operator+=(const QMargins &margins);
|
||||
inline QRect &operator-=(const QMargins &margins);
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 0)
|
||||
QT_DEPRECATED QRect unite(const QRect &r) const { return united(r); }
|
||||
QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); }
|
||||
|
@ -1118,7 +1118,7 @@ QRect QWindowsWindow::frameGeometry_sys() const
|
||||
|
||||
QRect QWindowsWindow::geometry_sys() const
|
||||
{
|
||||
return frameGeometry_sys() - frameMargins();
|
||||
return frameGeometry_sys().marginsRemoved(frameMargins());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -283,17 +283,6 @@ private:
|
||||
HICON m_iconBig;
|
||||
};
|
||||
|
||||
// Conveniences for window frames.
|
||||
inline QRect operator+(const QRect &r, const QMargins &m)
|
||||
{
|
||||
return r.adjusted(-m.left(), -m.top(), m.right(), m.bottom());
|
||||
}
|
||||
|
||||
inline QRect operator-(const QRect &r, const QMargins &m)
|
||||
{
|
||||
return r.adjusted(m.left(), m.top(), -m.right(), -m.bottom());
|
||||
}
|
||||
|
||||
// Debug
|
||||
QDebug operator<<(QDebug d, const RECT &r);
|
||||
#ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO/WM_NCCALCSIZE
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <qrect.h>
|
||||
#include <qmargins.h>
|
||||
#include <limits.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
@ -137,6 +138,7 @@ private slots:
|
||||
void newMoveTopLeft();
|
||||
void newMoveBottomRight_data();
|
||||
void newMoveBottomRight();
|
||||
void margins();
|
||||
|
||||
void translate_data();
|
||||
void translate();
|
||||
@ -3488,6 +3490,25 @@ void tst_QRect::newMoveBottomRight()
|
||||
QCOMPARE(r,nr);
|
||||
}
|
||||
|
||||
void tst_QRect::margins()
|
||||
{
|
||||
const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50));
|
||||
const QMargins margins = QMargins(2, 3, 4, 5);
|
||||
|
||||
const QRect added = rectangle + margins;
|
||||
QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58)));
|
||||
QCOMPARE(added, margins + rectangle);
|
||||
QCOMPARE(added, rectangle.marginsAdded(margins));
|
||||
|
||||
QRect a = rectangle;
|
||||
a += margins;
|
||||
QCOMPARE(added, a);
|
||||
|
||||
a = rectangle;
|
||||
a -= margins;
|
||||
QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42)));
|
||||
QCOMPARE(a, rectangle.marginsRemoved(margins));
|
||||
}
|
||||
|
||||
void tst_QRect::translate_data()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user