From 5334a2cea76473060b4f20aa8f1d5819bb03e6c4 Mon Sep 17 00:00:00 2001 From: Kari Pihkala Date: Thu, 31 Oct 2013 15:23:21 +0200 Subject: [PATCH] Mac: Add support for high-dpi custom pixmap QCursors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For pixmaps with devicePixelRatio greater than 1, create a native cursor that has a normal and a high-dpi representation. Task-number: QTBUG-34116 Change-Id: I1c014d65749add25f2b828837555a1844ede97c1 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoacursor.mm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm index 13f6423701..592bfc8e50 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.mm +++ b/src/plugins/platforms/cocoa/qcocoacursor.mm @@ -308,8 +308,22 @@ NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBit NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot) { - NSPoint hotSpot = NSMakePoint(hotspot.x(), hotspot.y()); - NSImage *nsimage = static_cast(qt_mac_create_nsimage(pixmap)); + NSPoint hotSpot = NSMakePoint(hotspot.x() / pixmap.devicePixelRatio(), + hotspot.y() / pixmap.devicePixelRatio()); + NSImage *nsimage; + if (pixmap.devicePixelRatio() > 1.0) { + QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio(); + QPixmap scaledPixmap = pixmap.scaled(layoutSize); + nsimage = static_cast(qt_mac_create_nsimage(scaledPixmap)); + CGImageRef cgImage = qt_mac_toCGImage(pixmap.toImage()); + NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; + [nsimage addRepresentation:imageRep]; + [imageRep release]; + CGImageRelease(cgImage); + } else { + nsimage = static_cast(qt_mac_create_nsimage(pixmap)); + } + NSCursor *nsCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; [nsimage release]; return nsCursor;