summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qmargins.h
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2014-02-07 11:47:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-21 20:33:10 +0100
commit3aae3e81ef55b4131eff0520d67f2594ee9e507c (patch)
treeee33784d65b3683aaf8aae17dda494560e3c8a24 /src/corelib/tools/qmargins.h
parentc7aa3a69253c82b8ae814c88ebbdfad7e48d0b2d (diff)
QMarginsF - Add new QMarginsF class
Add a new QMarginsF class to complement QMargins in the style of QSize/QSizeF and QRect/QRectF. [ChangeLog][QtCore] Added class QMarginsF to support handling margins with floating-point values. Change-Id: Iaaa95ec85f5d126d9d864fc4b607241a8c8a8f3a Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/corelib/tools/qmargins.h')
-rw-r--r--src/corelib/tools/qmargins.h211
1 files changed, 211 insertions, 0 deletions
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 55355ac859..d96ccaccae 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -46,6 +46,9 @@
QT_BEGIN_NAMESPACE
+/*****************************************************************************
+ QMargins class
+ *****************************************************************************/
class QMargins
{
@@ -277,6 +280,214 @@ Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins)
Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
#endif
+/*****************************************************************************
+ QMarginsF class
+ *****************************************************************************/
+
+class QMarginsF
+{
+public:
+ Q_DECL_CONSTEXPR QMarginsF();
+ Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom);
+ Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins);
+
+ Q_DECL_CONSTEXPR bool isNull() const;
+
+ Q_DECL_CONSTEXPR qreal left() const;
+ Q_DECL_CONSTEXPR qreal top() const;
+ Q_DECL_CONSTEXPR qreal right() const;
+ Q_DECL_CONSTEXPR qreal bottom() const;
+
+ void setLeft(qreal left);
+ void setTop(qreal top);
+ void setRight(qreal right);
+ void setBottom(qreal bottom);
+
+ QMarginsF &operator+=(const QMarginsF &margins);
+ QMarginsF &operator-=(const QMarginsF &margins);
+ QMarginsF &operator+=(qreal addend);
+ QMarginsF &operator-=(qreal subtrahend);
+ QMarginsF &operator*=(qreal factor);
+ QMarginsF &operator/=(qreal divisor);
+
+ Q_DECL_CONSTEXPR inline QMargins toMargins() const;
+
+private:
+ qreal m_left;
+ qreal m_top;
+ qreal m_right;
+ qreal m_bottom;
+};
+
+Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE);
+
+/*****************************************************************************
+ QMarginsF stream functions
+ *****************************************************************************/
+
+#ifndef QT_NO_DATASTREAM
+Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &);
+Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
+#endif
+
+/*****************************************************************************
+ QMarginsF inline functions
+ *****************************************************************************/
+
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
+
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom)
+ : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
+
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins)
+ : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {}
+
+Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const
+{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
+
+Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const
+{ return m_left; }
+
+Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const
+{ return m_top; }
+
+Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const
+{ return m_right; }
+
+Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const
+{ return m_bottom; }
+
+
+inline void QMarginsF::setLeft(qreal aleft)
+{ m_left = aleft; }
+
+inline void QMarginsF::setTop(qreal atop)
+{ m_top = atop; }
+
+inline void QMarginsF::setRight(qreal aright)
+{ m_right = aright; }
+
+inline void QMarginsF::setBottom(qreal abottom)
+{ m_bottom = abottom; }
+
+Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
+{
+ return qFuzzyCompare(lhs.left(), rhs.left())
+ && qFuzzyCompare(lhs.top(), rhs.top())
+ && qFuzzyCompare(lhs.right(), rhs.right())
+ && qFuzzyCompare(lhs.bottom(), rhs.bottom());
+}
+
+Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
+{
+ return !operator==(lhs, rhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs)
+{
+ return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
+ lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs)
+{
+ return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
+ lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs)
+{
+ return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
+ lhs.right() + rhs, lhs.bottom() + rhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs)
+{
+ return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
+ rhs.right() + lhs, rhs.bottom() + lhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs)
+{
+ return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
+ lhs.right() - rhs, lhs.bottom() - rhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs)
+{
+ return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
+ lhs.right() * rhs, lhs.bottom() * rhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs)
+{
+ return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
+ rhs.right() * lhs, rhs.bottom() * lhs);
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
+{
+ return QMarginsF(lhs.left() / divisor, lhs.top() / divisor,
+ lhs.right() / divisor, lhs.bottom() / divisor);
+}
+
+inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
+{
+ return *this = *this + margins;
+}
+
+inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
+{
+ return *this = *this - margins;
+}
+
+inline QMarginsF &QMarginsF::operator+=(qreal addend)
+{
+ m_left += addend;
+ m_top += addend;
+ m_right += addend;
+ m_bottom += addend;
+ return *this;
+}
+
+inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
+{
+ m_left -= subtrahend;
+ m_top -= subtrahend;
+ m_right -= subtrahend;
+ m_bottom -= subtrahend;
+ return *this;
+}
+
+inline QMarginsF &QMarginsF::operator*=(qreal factor)
+{
+ return *this = *this * factor;
+}
+
+inline QMarginsF &QMarginsF::operator/=(qreal divisor)
+{
+ return *this = *this / divisor;
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins)
+{
+ return margins;
+}
+
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins)
+{
+ return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
+}
+
+Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const
+{
+ return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &);
+#endif
+
QT_END_NAMESPACE
#endif // QMARGINS_H