feat(StatusLetterIdenticon): use luminance to determine letter color

This commit is contained in:
Patryk Osmaczko 2022-04-07 21:08:16 +02:00 committed by Michał Cieślak
parent 9a93f152cc
commit fe214b32a0
3 changed files with 11 additions and 3 deletions

View File

@ -29,7 +29,7 @@ Rectangle {
font.weight: Font.Bold
font.pixelSize: root.letterSize
color: Qt.rgba(255, 255, 255, 0.7)
color: d.luminance(root.color) > 0.5 ? Qt.rgba(0, 0, 0, 0.5) : Qt.rgba(255, 255, 255, 0.7)
text: {
if (emoji) {
@ -45,5 +45,15 @@ Rectangle {
return root.name.substring(shift, shift + charactersLen).toUpperCase()
}
}
QtObject {
id: d
function luminance(color) {
let r = Math.pow(color.r, 2.2) * 0.2126
let g = Math.pow(color.g, 2.2) * 0.7151
let b = Math.pow(color.b, 2.2) * 0.0721
return r + g + b
}
}
}

View File

@ -86,7 +86,6 @@ Loader {
emoji: statusSmartIdenticon.icon.emoji
emojiSize: statusSmartIdenticon.icon.emojiSize
letterSize: statusSmartIdenticon.icon.letterSize
identiconText.color: statusSmartIdenticon.icon.textColor
charactersLen: statusSmartIdenticon.icon.charactersLen
}
}

View File

@ -8,7 +8,6 @@ QtObject {
property real width
property real height
property color color
property color textColor: Qt.rgba(255, 255, 255, 0.7)
property color disabledColor
property url source
property int rotation