From e266949979624172bae7484b48c530cf48f8eb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 28 Nov 2024 18:00:15 +0100 Subject: [PATCH] Apple: Use automatic rendering mode for icon engine When requesting symbol icons the OS automatically chooses a rendering mode per icon. Most icons use the monochrome rendering mode by default, but some of them use the hierarchical. We don't want to override this choice by always using hierarchical, as that doesn't match the look of most icons in the system and may be surprising to the user. We still want to support tinted icons, based on the QPalette. For iOS this is easy via [UIImage withTintColor:] but for macOS we have to do an extra render pass. Unfortunately we can't use configurationWithPaletteColors with a single color, as for the hierarchical icons this will produce a different looking icon than if we tint the entire icon. [ChangeLog][macOS/iOS] The Apple icon engine, used for theme icons on macOS and iOS, will now use the default rendering mode for icons, typically monochrome, instead of always using hierarchical icons. Pick-to: 6.8 Change-Id: I9e66d848222e8ed0f7f20897454f27446bf0fd81 Reviewed-by: Volker Hilsheimer (cherry picked from commit 9f392c09a1d30e48494b4df0e2f5f531c7e4ec4b) Reviewed-by: Qt Cherry-pick Bot --- src/gui/platform/darwin/qappleiconengine.mm | 40 +++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/gui/platform/darwin/qappleiconengine.mm b/src/gui/platform/darwin/qappleiconengine.mm index d99da6da841..84e9ff4ea39 100644 --- a/src/gui/platform/darwin/qappleiconengine.mm +++ b/src/gui/platform/darwin/qappleiconengine.mm @@ -362,17 +362,23 @@ auto *config = [NSImageSymbolConfiguration configurationWithPointSize:48 weight:NSFontWeightRegular scale:NSImageSymbolScaleLarge]; - if (@available(macOS 12, *)) { - auto *primaryColor = [NSColor colorWithSRGBRed:color.redF() - green:color.greenF() - blue:color.blueF() - alpha:color.alphaF()]; - - auto *colorConfig = [NSImageSymbolConfiguration configurationWithHierarchicalColor:primaryColor]; - config = [config configurationByApplyingConfiguration:colorConfig]; - } - return [image imageWithSymbolConfiguration:config]; + NSImage *configuredImage = [image imageWithSymbolConfiguration:config]; + + auto *primaryColor = [NSColor colorWithSRGBRed:color.redF() + green:color.greenF() + blue:color.blueF() + alpha:color.alphaF()]; + + NSImage *tintedImage = [NSImage imageWithSize:configuredImage.size flipped:NO + drawingHandler:^BOOL(NSRect) { + [primaryColor set]; + NSRect imageRect = {NSZeroPoint, configuredImage.size}; + [configuredImage drawInRect:imageRect]; + NSRectFillUsingOperation(imageRect, NSCompositingOperationSourceIn); + return YES; + }]; + return tintedImage; } #elif defined(QT_PLATFORM_UIKIT) auto *configuredImage(const UIImage *image, const QColor &color) @@ -381,16 +387,12 @@ weight:UIImageSymbolWeightRegular scale:UIImageSymbolScaleLarge]; - if (@available(iOS 15, *)) { - auto *primaryColor = [UIColor colorWithRed:color.redF() - green:color.greenF() - blue:color.blueF() - alpha:color.alphaF()]; + auto *primaryColor = [UIColor colorWithRed:color.redF() + green:color.greenF() + blue:color.blueF() + alpha:color.alphaF()]; - auto *colorConfig = [UIImageSymbolConfiguration configurationWithHierarchicalColor:primaryColor]; - config = [config configurationByApplyingConfiguration:colorConfig]; - } - return [image imageByApplyingSymbolConfiguration:config]; + return [[image imageByApplyingSymbolConfiguration:config] imageWithTintColor:primaryColor]; } #endif }