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>
This commit is contained in:
Tor Arne Vestbø 2016-05-18 15:41:24 +02:00 committed by Jake Petroules
parent 197471beac
commit 58566686fc
6 changed files with 55 additions and 13 deletions

View File

@ -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

View File

@ -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;

View File

@ -128,7 +128,7 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o)
QPixmap pm = dragPixmap(m_drag, hotSpot);
QSize pmDeviceIndependentSize = pm.size() / pm.devicePixelRatio();
NSImage *nsimage = qt_mac_create_nsimage(pm);
[nsimage setSize : qt_mac_toNSSize(pmDeviceIndependentSize)];
[nsimage setSize:pmDeviceIndependentSize.toCGSize()];
QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacInternalPasteboardMime::MIME_DND);
m_drag->mimeData()->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy"));

View File

@ -77,8 +77,6 @@ CGImageRef qt_mac_toCGImageMask(const QImage &qImage);
QImage qt_mac_toQImage(CGImageRef image);
QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size);
NSSize qt_mac_toNSSize(const QSize &qtSize);
QColor qt_mac_toQColor(const NSColor *color);
QColor qt_mac_toQColor(CGColorRef color);

View File

@ -209,11 +209,6 @@ HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion &region)
return shape;
}
NSSize qt_mac_toNSSize(const QSize &qtSize)
{
return NSMakeSize(qtSize.width(), qtSize.height());
}
QColor qt_mac_toQColor(const NSColor *color)
{
QColor qtColor;

View File

@ -1107,11 +1107,10 @@ void QCocoaWindow::propagateSizeHints()
// sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be
// resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case.
const QSize sizeIncrement = windowSizeIncrement();
if (!sizeIncrement.isEmpty())
[m_nsWindow setResizeIncrements : qt_mac_toNSSize(sizeIncrement)];
else
[m_nsWindow setResizeIncrements : NSMakeSize(1.0, 1.0)];
QSize sizeIncrement = windowSizeIncrement();
if (sizeIncrement.isEmpty())
sizeIncrement = QSize(1, 1);
[m_nsWindow setResizeIncrements:sizeIncrement.toCGSize()];
QRect rect = geometry();
QSize baseSize = windowBaseSize();