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:
parent
197471beac
commit
58566686fc
@ -496,5 +496,42 @@ QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW
|
|||||||
return QPointF(point.x, point.y);
|
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
|
QT_END_NAMESPACE
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
|
|
||||||
#include <QtCore/qnamespace.h>
|
#include <QtCore/qnamespace.h>
|
||||||
|
|
||||||
|
#if defined(Q_OS_DARWIN)
|
||||||
|
struct CGSize;
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +90,10 @@ public:
|
|||||||
friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW;
|
friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW;
|
||||||
friend inline const QSize operator/(const QSize &, qreal);
|
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:
|
private:
|
||||||
int wd;
|
int wd;
|
||||||
int ht;
|
int ht;
|
||||||
@ -248,6 +256,11 @@ public:
|
|||||||
|
|
||||||
Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW;
|
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:
|
private:
|
||||||
qreal wd;
|
qreal wd;
|
||||||
qreal ht;
|
qreal ht;
|
||||||
|
@ -128,7 +128,7 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o)
|
|||||||
QPixmap pm = dragPixmap(m_drag, hotSpot);
|
QPixmap pm = dragPixmap(m_drag, hotSpot);
|
||||||
QSize pmDeviceIndependentSize = pm.size() / pm.devicePixelRatio();
|
QSize pmDeviceIndependentSize = pm.size() / pm.devicePixelRatio();
|
||||||
NSImage *nsimage = qt_mac_create_nsimage(pm);
|
NSImage *nsimage = qt_mac_create_nsimage(pm);
|
||||||
[nsimage setSize : qt_mac_toNSSize(pmDeviceIndependentSize)];
|
[nsimage setSize:pmDeviceIndependentSize.toCGSize()];
|
||||||
|
|
||||||
QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacInternalPasteboardMime::MIME_DND);
|
QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacInternalPasteboardMime::MIME_DND);
|
||||||
m_drag->mimeData()->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy"));
|
m_drag->mimeData()->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy"));
|
||||||
|
@ -77,8 +77,6 @@ CGImageRef qt_mac_toCGImageMask(const QImage &qImage);
|
|||||||
QImage qt_mac_toQImage(CGImageRef image);
|
QImage qt_mac_toQImage(CGImageRef image);
|
||||||
QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size);
|
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(const NSColor *color);
|
||||||
QColor qt_mac_toQColor(CGColorRef color);
|
QColor qt_mac_toQColor(CGColorRef color);
|
||||||
|
|
||||||
|
@ -209,11 +209,6 @@ HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion ®ion)
|
|||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSSize qt_mac_toNSSize(const QSize &qtSize)
|
|
||||||
{
|
|
||||||
return NSMakeSize(qtSize.width(), qtSize.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor qt_mac_toQColor(const NSColor *color)
|
QColor qt_mac_toQColor(const NSColor *color)
|
||||||
{
|
{
|
||||||
QColor qtColor;
|
QColor qtColor;
|
||||||
|
@ -1107,11 +1107,10 @@ void QCocoaWindow::propagateSizeHints()
|
|||||||
|
|
||||||
// sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be
|
// 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.
|
// resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case.
|
||||||
const QSize sizeIncrement = windowSizeIncrement();
|
QSize sizeIncrement = windowSizeIncrement();
|
||||||
if (!sizeIncrement.isEmpty())
|
if (sizeIncrement.isEmpty())
|
||||||
[m_nsWindow setResizeIncrements : qt_mac_toNSSize(sizeIncrement)];
|
sizeIncrement = QSize(1, 1);
|
||||||
else
|
[m_nsWindow setResizeIncrements:sizeIncrement.toCGSize()];
|
||||||
[m_nsWindow setResizeIncrements : NSMakeSize(1.0, 1.0)];
|
|
||||||
|
|
||||||
QRect rect = geometry();
|
QRect rect = geometry();
|
||||||
QSize baseSize = windowBaseSize();
|
QSize baseSize = windowBaseSize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user