summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorKari Pihkala <kari.pihkala@gmail.com>2013-10-31 15:23:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-15 10:45:53 +0100
commit5334a2cea76473060b4f20aa8f1d5819bb03e6c4 (patch)
treebab94267739ff0cc17ac70c689ea22b9e0e3db65 /src/plugins/platforms
parent4d56c86f802a49e0fa5481e13ab1f000ff284637 (diff)
Mac: Add support for high-dpi custom pixmap QCursors
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 <allan.jensen@digia.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoacursor.mm18
1 files 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<NSImage *>(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<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);
+ } else {
+ nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
+ }
+
NSCursor *nsCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
[nsimage release];
return nsCursor;