From 52e9c8b4be6718bda1a46859d6b1c13664c57c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 9 Mar 2020 18:05:14 +0100 Subject: macOS: Streamline QImage to NSImage conversion The conversion uses NSBitmapImageRep and correctly sets the display pixel ratio and size of the resulting image, reducing the need for clients to deal with this. The function returns an auto-released object, as is customary for class-functions like these. Change-Id: I5124d1d8145a7f5266921b22fda1987798771ec1 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoadrag.mm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms/cocoa/qcocoadrag.mm') diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm index 95808b8a11..b4a16ab912 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.mm +++ b/src/plugins/platforms/cocoa/qcocoadrag.mm @@ -130,9 +130,8 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) QPoint hotSpot = m_drag->hotSpot(); QPixmap pm = dragPixmap(m_drag, hotSpot); - QSize pmDeviceIndependentSize = pm.size() / pm.devicePixelRatio(); - NSImage *nsimage = qt_mac_create_nsimage(pm); - [nsimage setSize:NSSizeFromCGSize(pmDeviceIndependentSize.toCGSize())]; + NSImage *dragImage = [NSImage imageFromQImage:pm.toImage()]; + Q_ASSERT(dragImage); QMacPasteboard dragBoard(CFStringRef(NSPasteboardNameDrag), QMacInternalPasteboardMime::MIME_DND); m_drag->mimeData()->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy")); @@ -142,12 +141,12 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) NSWindow *theWindow = [m_lastEvent window]; Q_ASSERT(theWindow); event_location.x -= hotSpot.x(); - CGFloat flippedY = pmDeviceIndependentSize.height() - hotSpot.y(); + CGFloat flippedY = dragImage.size.height - hotSpot.y(); event_location.y -= flippedY; NSSize mouseOffset_unused = NSMakeSize(0.0, 0.0); NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag]; - [theWindow dragImage:nsimage + [theWindow dragImage:dragImage at:event_location offset:mouseOffset_unused event:m_lastEvent @@ -155,8 +154,6 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) source:m_lastView slideBack:YES]; - [nsimage release]; - m_drag = nullptr; return m_executed_drop_action; } -- cgit v1.2.3