From e4d6488ffa46fb3505376d656835470675a59fef Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 21 Nov 2013 17:21:57 +0100 Subject: QCocoaTheme: Fix size of pixmap returned by fileIconPixmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/platforms/cocoa/qcocoatheme.mm | 24 ++++++++++++++++-------- 1 file 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 sizes; - sizes << 16 << 32 << 64 << 128; + sizes << 16 * devicePixelRatio + << 32 * devicePixelRatio + << 64 * devicePixelRatio + << 128 * devicePixelRatio; return QVariant::fromValue(sizes); } case QPlatformTheme::PasswordMaskCharacter: -- cgit v1.2.3