summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoacursor.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-03-09 18:05:14 +0100
committerTor Arne Vestbø <torarnv@gmail.com>2020-03-12 11:49:06 +0100
commit52e9c8b4be6718bda1a46859d6b1c13664c57c2a (patch)
treebbf77c7a432b201a8e09ea0dbe0c9e8902d9551c /src/plugins/platforms/cocoa/qcocoacursor.mm
parent28d3d82a0d2f0fe8e4784a17a167c2f9f2e2420e (diff)
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 <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoacursor.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoacursor.mm13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm
index e0d623fc4c..658a7670f0 100644
--- a/src/plugins/platforms/cocoa/qcocoacursor.mm
+++ b/src/plugins/platforms/cocoa/qcocoacursor.mm
@@ -340,19 +340,12 @@ NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoin
QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio();
QPixmap scaledPixmap = pixmap.scaled(layoutSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
scaledPixmap.setDevicePixelRatio(1.0);
- nsimage = static_cast<NSImage *>(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);
+ nsimage = [NSImage imageFromQImage:scaledPixmap.toImage()];
} else {
- nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
+ nsimage = [NSImage imageFromQImage:pixmap.toImage()];
}
- NSCursor *nsCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
- [nsimage release];
- return nsCursor;
+ return [[NSCursor alloc] initWithImage:nsimage hotSpot:hotSpot];
}
QT_END_NAMESPACE