feat(StatusLetterIdenticon): introduce strictBackgroundColor flag to decouple coloring and useAcronymForLetterIdenticon flag

This commit is contained in:
Michał Cieślak 2024-05-17 14:11:15 +02:00 committed by Michał
parent 4c61c115d4
commit aeb9929fcd
3 changed files with 14 additions and 7 deletions

View File

@ -14,12 +14,15 @@ Rectangle {
property int charactersLen: 1 property int charactersLen: 1
property color letterIdenticonColor: Theme.palette.miscColor5 property color letterIdenticonColor: Theme.palette.miscColor5
property bool useAcronymForLetterIdenticon: false property bool useAcronymForLetterIdenticon: false
property bool strictBackgroundColor: !useAcronymForLetterIdenticon
color: { color: {
if (root.useAcronymForLetterIdenticon) { if (root.strictBackgroundColor)
return Qt.rgba(root.letterIdenticonColor.r, root.letterIdenticonColor.g, root.letterIdenticonColor.b, 0.2) return root.letterIdenticonColor
}
return root.letterIdenticonColor return Qt.rgba(root.letterIdenticonColor.r,
root.letterIdenticonColor.g,
root.letterIdenticonColor.b, 0.2)
} }
width: 40 width: 40
@ -33,7 +36,7 @@ Rectangle {
height: Math.round(parent.height / 2) height: Math.round(parent.height / 2)
emojiId: Emoji.iconId(root.emoji, root.emojiSize) || Emoji.iconHex(root.emoji) || "" emojiId: Emoji.iconId(root.emoji, root.emojiSize) || Emoji.iconHex(root.emoji) || ""
} }
StatusBaseText { StatusBaseText {
id: identiconText id: identiconText
@ -47,9 +50,9 @@ Rectangle {
font.weight: Font.Bold font.weight: Font.Bold
font.pixelSize: root.letterSize font.pixelSize: root.letterSize
color: { color: {
if (root.useAcronymForLetterIdenticon) { if (!root.strictBackgroundColor)
return root.letterIdenticonColor return root.letterIdenticonColor
}
return d.luminance(root.letterIdenticonColor) > 0.5 ? Qt.rgba(0, 0, 0, 0.5) : Qt.rgba(1, 1, 1, 0.7) return d.luminance(root.letterIdenticonColor) > 0.5 ? Qt.rgba(0, 0, 0, 0.5) : Qt.rgba(1, 1, 1, 0.7)
} }

View File

@ -120,6 +120,7 @@ Loader {
letterSize: root.asset.letterSize letterSize: root.asset.letterSize
charactersLen: root.asset.charactersLen charactersLen: root.asset.charactersLen
useAcronymForLetterIdenticon: root.asset.useAcronymForLetterIdenticon useAcronymForLetterIdenticon: root.asset.useAcronymForLetterIdenticon
strictBackgroundColor: root.asset.useLetterIdenticonStrictBgColor
} }
} }

View File

@ -13,10 +13,13 @@ QtObject {
property color hoverColor property color hoverColor
property color disabledColor property color disabledColor
property int rotation property int rotation
property bool isLetterIdenticon property bool isLetterIdenticon
property bool useAcronymForLetterIdenticon property bool useAcronymForLetterIdenticon
property bool useLetterIdenticonStrictBgColor: !useAcronymForLetterIdenticon
property int letterSize: emoji ? 11 : (charactersLen == 1 ? _oneLetterSize : _twoLettersSize) property int letterSize: emoji ? 11 : (charactersLen == 1 ? _oneLetterSize : _twoLettersSize)
property int charactersLen: 1 property int charactersLen: 1
property string emoji property string emoji
property string emojiSize: _emojiSize property string emojiSize: _emojiSize