fix: ensuring contrasting text color for highlighted menuitems

Signed-off-by: Tamás Bari <adaorcpp@gmail.com>
This commit is contained in:
Tamás Bari 2025-10-15 15:12:07 +02:00 committed by Jyrki Gadinger
parent 8145c1ef7a
commit be3a001edc
3 changed files with 13 additions and 7 deletions

View File

@ -147,7 +147,7 @@ Button {
color: !parent.enabled
? parent.palette.mid
: (parent.highlighted || parent.down
? parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: parent.palette.text)
}
}
@ -171,7 +171,7 @@ Button {
color: !parent.enabled
? parent.palette.mid
: (parent.highlighted || parent.down
? parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: parent.palette.text)
}
}
@ -195,7 +195,7 @@ Button {
color: !parent.enabled
? parent.palette.mid
: (parent.highlighted || parent.down
? parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: parent.palette.text)
}
}

View File

@ -83,7 +83,7 @@ AbstractButton {
color: !userLine.parent.enabled
? userLine.parent.palette.mid
: (userLine.parent.highlighted || userLine.parent.down
? userLine.parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: userLine.parent.palette.text)
}
@ -103,7 +103,7 @@ AbstractButton {
color: !userLine.parent.enabled
? userLine.parent.palette.mid
: (userLine.parent.highlighted || userLine.parent.down
? userLine.parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: userLine.parent.palette.text)
}
@ -135,7 +135,7 @@ AbstractButton {
color: !userLine.parent.enabled
? userLine.parent.palette.mid
: (userLine.parent.highlighted || userLine.parent.down
? userLine.parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: userLine.parent.palette.text)
}
}
@ -159,7 +159,7 @@ AbstractButton {
property var iconColor: !userLine.parent.enabled
? userLine.parent.palette.mid
: (!hovered && (userLine.parent.highlighted || userLine.parent.down)
? userLine.parent.palette.highlightedText
? Style.contrastingColor( parent.palette.highlight )
: userLine.parent.palette.text)
icon.source: "image://svgimage-custom-color/more.svg/" + iconColor

View File

@ -211,4 +211,10 @@ QtObject {
function colorWithoutTransparency(color) {
return Qt.rgba(color.r, color.g, color.b, 1)
}
function contrastingColor(color) {
// sRGB relative luminance formula
const luminance = 0.299 * color.r + 0.587 * color.g + 0.114 * color.b
return luminance > 0.5 ? Qt.darker( color, 2.0 ) : Qt.lighter( color, 2.0 )
}
}