summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-24 21:20:37 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-08-22 11:38:54 +0200
commit5b2dfbc649a7c20a93223cd4c274a4b0fe847df8 (patch)
treefdfb311986db76f18443bd7094fa4b8b21c6597d /src/corelib/tools
parent529b27152068f02fc67dba6e4bb88be918220827 (diff)
Long live QSize(F)::grownBy/shrunkBy()
These functions tighten the integration of QMargins(F) with the rest of the geometry classes by providing a way to apply margins to sizes (and later, rects). Apply them in a few obvious cases across QtWidgets. [ChangeLog][QtCore][QSize/QSizeF] Added grownBy(QMargin(F))/shrunkBy(QMargin(F)). Change-Id: I8a549436824cdb7fb6125a8cde89d5bf02826934 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qsize.cpp18
-rw-r--r--src/corelib/tools/qsize.h11
2 files changed, 29 insertions, 0 deletions
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index fe508ad459..2cbaae117d 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -390,7 +390,25 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept
\sa expandedTo(), scale()
*/
+/*!
+ \fn QSize QSize::grownBy(QMargins margins) const
+ \fn QSizeF QSizeF::grownBy(QMarginsF margins) const
+ \since 5.14
+
+ Returns the size that results from growing this size by \a margins.
+
+ \sa shrunkBy()
+*/
+/*!
+ \fn QSize QSize::shrunkBy(QMargins margins) const
+ \fn QSizeF QSizeF::shrunkBy(QMarginsF margins) const
+ \since 5.14
+
+ Returns the size that results from shrinking this size by \a margins.
+
+ \sa grownBy()
+*/
/*****************************************************************************
QSize stream functions
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 4114609856..06de1cd63f 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -41,6 +41,7 @@
#define QSIZE_H
#include <QtCore/qnamespace.h>
+#include <QtCore/qmargins.h>
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
struct CGSize;
@@ -74,6 +75,11 @@ public:
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const noexcept;
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSize grownBy(QMargins m) const noexcept
+ { return {width() + m.left() + m.right(), height() + m.top() + m.bottom()}; }
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSize shrunkBy(QMargins m) const noexcept
+ { return {width() - m.left() - m.right(), height() - m.top() - m.bottom()}; }
+
Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() noexcept;
Q_DECL_RELAXED_CONSTEXPR inline int &rheight() noexcept;
@@ -238,6 +244,11 @@ public:
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const noexcept;
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSizeF grownBy(QMarginsF m) const noexcept
+ { return {width() + m.left() + m.right(), height() + m.top() + m.bottom()}; }
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSizeF shrunkBy(QMarginsF m) const noexcept
+ { return {width() - m.left() - m.right(), height() - m.top() - m.bottom()}; }
+
Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() noexcept;
Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() noexcept;