From 58566686fcfceee1caeab88d0531816f4df49192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 18 May 2016 15:41:24 +0200 Subject: darwin: Add Foundation conversion functions for QSize/QSizeF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø Reviewed-by: Jake Petroules --- src/corelib/kernel/qcore_foundation.mm | 37 ++++++++++++++++++++++++++++++++++ src/corelib/tools/qsize.h | 13 ++++++++++++ 2 files changed, 50 insertions(+) (limited to 'src/corelib') 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 +#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; -- cgit v1.2.3