mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
Darken the hover ink on a light button face
QETStyle::hoverColor() lightened the highlight color until it read at 3.5:1 against the Light role. On a dark face that is the way to go; on a light face lightening only fades the ink, so with a pale platform accent that QET keeps (macOS's green selection color, black selection text) the loop ran to white and every hovered line-art icon vanished. The ink now moves away from the face, darker on a light face, lighter on a dark one, and falls back to the button text color if twenty steps are not enough. The hover test gets a row with that accent on each palette, and a new test sweeps accents across hues and lightness on both palettes and requires the hover ink to read at 3:1 on the face. Fixes #962
This commit is contained in:
+11
-4
@@ -67,20 +67,27 @@ bool QETStyle::isLineArt(const QImage &image)
|
||||
/**
|
||||
@brief QETStyle::hoverColor
|
||||
The palette's highlight color is the accent users already know from
|
||||
selections. On a dark palette it is too dark to read on a hovered
|
||||
button face, so it is lightened, a step at a time, until it reaches
|
||||
selections, moved away from the hovered button face until it reaches
|
||||
3:1 (WCAG 1.4.11) against the Light role: Fusion paints a hovered
|
||||
auto-raise button with a gradient that runs from Button up to about
|
||||
that color, and the icon has to read on the lightest part of it.
|
||||
that color, and the icon has to read on the lightest part of it. On a
|
||||
dark face the accent is lightened, a step at a time; on a light face it
|
||||
is darkened, which keeps a pale accent (macOS's green or yellow
|
||||
selection color, which comes with black selection text) from being
|
||||
pushed to white. Should twenty steps not get there, the button text
|
||||
color serves, which reads on the face by construction.
|
||||
*/
|
||||
QColor QETStyle::hoverColor(const QPalette &palette)
|
||||
{
|
||||
const QColor face = palette.color(QPalette::Active, QPalette::Light);
|
||||
const bool light_face = face.lightnessF() > 0.5;
|
||||
QColor ink = palette.color(QPalette::Active, QPalette::Highlight);
|
||||
// 3.5 rather than 3.0: the top of Fusion's hover gradient is a shade
|
||||
// lighter than the Light role, so the icon needs some headroom there.
|
||||
for (int step = 0; step < 20 && QET::Palette::contrastRatio(ink, face) < 3.5; ++step)
|
||||
ink = ink.lighter(110);
|
||||
ink = light_face ? ink.darker(110) : ink.lighter(110);
|
||||
if (QET::Palette::contrastRatio(ink, face) < 3.5)
|
||||
ink = palette.color(QPalette::Active, QPalette::ButtonText);
|
||||
return ink;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user