summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-11-21 17:21:57 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-17 09:13:56 +0100
commite4d6488ffa46fb3505376d656835470675a59fef (patch)
treea892075cfec47dfe7deae4fd46c505649e69dbb9 /src
parentcc2079c85032f51e7bb0ac5a296d25777fb652c0 (diff)
QCocoaTheme: Fix size of pixmap returned by fileIconPixmap
The code assumed that CGImageForProposedRect would return a sensible sized image, but that can return basically any size (depending on the NSImage's image representations). In the case of the bug report this is a 1024x1024 pixmap when requesting a pixmap of size 64x64 and larger. Make sure that we return a pixmap of the exact requested size. For this, themeHint must also return sizes in device coordinates. Task-number: QTBUG-35009 Change-Id: Iaae11023bab6d4122815ca4010aab6967dfb18a0 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm
index 1484ae2ba3..d863861288 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.mm
+++ b/src/plugins/platforms/cocoa/qcocoatheme.mm
@@ -258,13 +258,17 @@ QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &siz
NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:QCFString::toNSString(fileInfo.canonicalFilePath())];
if (!iconImage)
return QPixmap();
-
- NSRect iconRect = NSMakeRect(0, 0, size.width(), size.height());
- NSGraphicsContext *gc = [NSGraphicsContext currentContext];
- CGImageRef cgImage = [iconImage CGImageForProposedRect:&iconRect
- context:([gc graphicsPort] ? gc : nil)
- hints:nil];
- QPixmap pixmap = QPixmap::fromImage(qt_mac_toQImage(cgImage));
+ NSSize pixmapSize = NSMakeSize(size.width(), size.height());
+ QPixmap pixmap(pixmapSize.width, pixmapSize.height);
+ pixmap.fill(Qt::transparent);
+ [iconImage setSize:pixmapSize];
+ NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height);
+ CGContextRef ctx = qt_mac_cg_context(&pixmap);
+ NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:gc];
+ [iconImage drawInRect:iconRect fromRect:iconRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
+ [NSGraphicsContext restoreGraphicsState];
return pixmap;
}
@@ -280,8 +284,12 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
case TabAllWidgets:
return QVariant(bool([[NSApplication sharedApplication] isFullKeyboardAccessEnabled]));
case IconPixmapSizes: {
+ qreal devicePixelRatio = qGuiApp->devicePixelRatio();
QList<int> sizes;
- sizes << 16 << 32 << 64 << 128;
+ sizes << 16 * devicePixelRatio
+ << 32 * devicePixelRatio
+ << 64 * devicePixelRatio
+ << 128 * devicePixelRatio;
return QVariant::fromValue(sizes);
}
case QPlatformTheme::PasswordMaskCharacter: