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.9 6.8 Change-Id: I9e66d848222e8ed0f7f20897454f27446bf0fd81 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
75d87caef7
commit
9f392c09a1
@ -362,17 +362,23 @@ auto *configuredImage(const NSImage *image, const QColor &color)
|
|||||||
auto *config = [NSImageSymbolConfiguration configurationWithPointSize:48
|
auto *config = [NSImageSymbolConfiguration configurationWithPointSize:48
|
||||||
weight:NSFontWeightRegular
|
weight:NSFontWeightRegular
|
||||||
scale:NSImageSymbolScaleLarge];
|
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];
|
NSImage *configuredImage = [image imageWithSymbolConfiguration:config];
|
||||||
config = [config configurationByApplyingConfiguration:colorConfig];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [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)
|
#elif defined(QT_PLATFORM_UIKIT)
|
||||||
auto *configuredImage(const UIImage *image, const QColor &color)
|
auto *configuredImage(const UIImage *image, const QColor &color)
|
||||||
@ -381,16 +387,12 @@ auto *configuredImage(const UIImage *image, const QColor &color)
|
|||||||
weight:UIImageSymbolWeightRegular
|
weight:UIImageSymbolWeightRegular
|
||||||
scale:UIImageSymbolScaleLarge];
|
scale:UIImageSymbolScaleLarge];
|
||||||
|
|
||||||
if (@available(iOS 15, *)) {
|
auto *primaryColor = [UIColor colorWithRed:color.redF()
|
||||||
auto *primaryColor = [UIColor colorWithRed:color.redF()
|
green:color.greenF()
|
||||||
green:color.greenF()
|
blue:color.blueF()
|
||||||
blue:color.blueF()
|
alpha:color.alphaF()];
|
||||||
alpha:color.alphaF()];
|
|
||||||
|
|
||||||
auto *colorConfig = [UIImageSymbolConfiguration configurationWithHierarchicalColor:primaryColor];
|
return [[image imageByApplyingSymbolConfiguration:config] imageWithTintColor:primaryColor];
|
||||||
config = [config configurationByApplyingConfiguration:colorConfig];
|
|
||||||
}
|
|
||||||
return [image imageByApplyingSymbolConfiguration:config];
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user