Skip to content

Commit

Permalink
Apple: Use automatic rendering mode for icon engine
Browse files Browse the repository at this point in the history
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.

Change-Id: I9e66d848222e8ed0f7f20897454f27446bf0fd81
Reviewed-by: Volker Hilsheimer <[email protected]>
(cherry picked from commit 9f392c0)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit e266949)
  • Loading branch information
torarnv authored and Qt Cherry-pick Bot committed Dec 20, 2024
1 parent e38834a commit 7e2b84b
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/gui/platform/darwin/qappleiconengine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 7e2b84b

Please sign in to comment.