diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-05-18 15:41:24 +0200 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2016-06-14 17:23:38 +0000 |
commit | 58566686fcfceee1caeab88d0531816f4df49192 (patch) | |
tree | cfc322f296b7c1f6066cdb0e2760889132b5aa55 /src/corelib | |
parent | 197471beacf5589802cb91f1ceba59ed99cbb511 (diff) |
darwin: Add Foundation conversion functions for QSize/QSizeF
The fromCGPoint function was left out for QSize, as the foundation type is
using CGFloats internally. Clients should use an explicit QSizeF::toSize()
when potentially throwing away precision.
Change-Id: I12d43ae0881f09ad8d79f2caaa000c3983f4ef30
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qcore_foundation.mm | 37 | ||||
-rw-r--r-- | src/corelib/tools/qsize.h | 13 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm index 4998b9e35a..2291017a5d 100644 --- a/src/corelib/kernel/qcore_foundation.mm +++ b/src/corelib/kernel/qcore_foundation.mm @@ -496,5 +496,42 @@ QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW return QPointF(point.x, point.y); } +// ---------------------------------------------------------------------------- + +/*! + \since 5.8 + + Creates a CGSize from a QSize. + + \sa fromCGSize() +*/ +CGSize QSize::toCGSize() const Q_DECL_NOTHROW +{ + return CGSizeMake(width(), height()); +} + +/*! + \since 5.8 + + Creates a CGSize from a QSizeF. + + \sa fromCGSize() +*/ +CGSize QSizeF::toCGSize() const Q_DECL_NOTHROW +{ + return CGSizeMake(width(), height()); +} + +/*! + \since 5.8 + + Creates a QRectF from a CGSize. + + \sa toCGSize() +*/ +QSizeF QSizeF::fromCGSize(CGSize size) Q_DECL_NOTHROW +{ + return QSizeF(size.width, size.height); +} QT_END_NAMESPACE diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index 5d40c4079a..74698224f2 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -42,6 +42,10 @@ #include <QtCore/qnamespace.h> +#if defined(Q_OS_DARWIN) +struct CGSize; +#endif + QT_BEGIN_NAMESPACE @@ -86,6 +90,10 @@ public: friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW; friend inline const QSize operator/(const QSize &, qreal); +#if defined(Q_OS_DARWIN) || defined(Q_QDOC) + CGSize toCGSize() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; +#endif + private: int wd; int ht; @@ -248,6 +256,11 @@ public: Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW; +#if defined(Q_OS_DARWIN) || defined(Q_QDOC) + static QSizeF fromCGSize(CGSize size) Q_DECL_NOTHROW Q_REQUIRED_RESULT; + CGSize toCGSize() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; +#endif + private: qreal wd; qreal ht; |