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>
This commit is contained in:
parent
4d56c86f80
commit
5334a2cea7
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user