macOS: Pass on QIcon as NSImage if possible, instead of going via QPixmap

The QIcon can be turned into a NSImage directly, with all the supported
representations that the icon contains. This allows macOS to choose the
best representation for whatever context it's rendering the NSImage in,
and will likely do a better job of scaling it if none of the sizes fit
target context.

This fixes e.g. application window icons not taking retina screens into
account.

Change-Id: Idbd97cae4ef50cc0dd3f38c355cfceec007e0d19
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-03-09 19:10:10 +01:00
parent bee3d0fc13
commit 059c3ae66a
2 changed files with 5 additions and 14 deletions

View File

@ -472,13 +472,7 @@ QList<QCocoaWindow *> *QCocoaIntegration::popupWindowStack()
void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const
{
NSImage *image = nil;
if (!icon.isNull()) {
NSSize size = [[[NSApplication sharedApplication] dockTile] size];
QPixmap pixmap = icon.pixmap(size.width, size.height);
image = [NSImage imageFromQImage:pixmap.toImage()];
}
[[NSApplication sharedApplication] setApplicationIconImage:image];
NSApp.applicationIconImage = [NSImage imageFromQIcon:icon];
}
void QCocoaIntegration::beep() const

View File

@ -894,13 +894,10 @@ void QCocoaWindow::setWindowIcon(const QIcon &icon)
QMacAutoReleasePool pool;
if (icon.isNull()) {
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
[iconButton setImage:[workspace iconForFile:m_view.window.representedFilename]];
} else {
QPixmap pixmap = icon.pixmap(QSize(22, 22));
iconButton.image = [NSImage imageFromQImage:pixmap.toImage()];
}
if (icon.isNull())
iconButton.image = [NSWorkspace.sharedWorkspace iconForFile:m_view.window.representedFilename];
else
iconButton.image = [NSImage imageFromQIcon:icon];
}
void QCocoaWindow::setAlertState(bool enabled)