ThemeContrast.h header
#include <ew/app/ThemeContrast.h>
Namespace ew::app
ContrastFinding struct
struct ew::app::ContrastFinding
One colour pair that must meet a contrast threshold, and whether it does.
Members
QString ew::app::settings::ContrastFinding::theme
The theme the pair belongs to.
QString ew::app::settings::ContrastFinding::pair
What the pair is, in words ("window text on window").
double ew::app::settings::ContrastFinding::ratio = 1.0
The measured ratio.
double ew::app::settings::ContrastFinding::required = 4.5
The ratio this pair must meet.
Always 4.5 today, and deliberately. WCAG allows 3.0 for large text and for non-text contrast, but every pair measureContrast reports is ordinary body text – window text, editor text, button labels, selected text, links. Nothing measured here qualifies for the relaxed threshold, so nothing sets it. The field stays per-finding rather than becoming a constant because the first large-text or non-text pair added is the moment 3.0 becomes real, and it should land as data rather than as a second code path.
This comment replaced one that read "4.5 for text, 3.0 for large text and non-text", which described a rule the code has never applied – a reader would reasonably have assumed some pair was being held to 3.0.
bool ew::app::settings::ContrastFinding::passes = false
Whether it meets the requirement.
Functions
double ew::app::settings::contrastRatio(const QString &foreground, const QString &background)
The WCAG contrast ratio between foreground and background, from 1.0 to 21.0.
Computed by WCAG 2.1's own formula – relative luminance with the sRGB gamma expansion, then (lighter + 0.05) / (darker + 0.05). Not a perceptual approximation: the whole value of a contrast number is that it is the one an auditor would compute, so an eyeballed or simplified version would be a different measurement wearing the same name.
Each colour is given as a string the way Theme stores it (#rrggbb); an unparseable colour yields 1.0, which fails every threshold rather than passing silently.
std::vector< ContrastFinding > ew::app::settings::measureContrast(const Theme &theme)
Measures every text pair in theme against its WCAG threshold.
Only pairs that actually appear together are measured. Contrast between two colours the app never renders on top of each other is a number with no user behind it, and reporting it would bury the pairs that matter.