From 41ee6846b4605bf50f1f5b12acffc71a76257e5d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 5 Aug 2024 11:15:53 +0200 Subject: Merging upstream version 4.2.6. Signed-off-by: Daniel Baumann --- ui/qt/utils/color_utils.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ui/qt/utils') diff --git a/ui/qt/utils/color_utils.cpp b/ui/qt/utils/color_utils.cpp index e7d7c6c5..e7e396d0 100644 --- a/ui/qt/utils/color_utils.cpp +++ b/ui/qt/utils/color_utils.cpp @@ -148,10 +148,16 @@ QRgb ColorUtils::sequenceColor(int item) bool ColorUtils::themeIsDark() { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - return qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark; -#else - return qApp->palette().windowText().color().lightness() > qApp->palette().window().color().lightness(); + switch (qApp->styleHints()->colorScheme()) { + case Qt::ColorScheme::Dark: + return true; + case Qt::ColorScheme::Light: + return false; + case Qt::ColorScheme::Unknown: + break; + } #endif + return qApp->palette().windowText().color().lightness() > qApp->palette().window().color().lightness(); } // Qt < 5.12.6 on macOS always uses Qt::blue for the link color, which is @@ -191,8 +197,10 @@ const QColor ColorUtils::contrastingTextColor(const QColor color) { bool background_is_light = color.lightness() > 127; if ( (background_is_light && !ColorUtils::themeIsDark()) || (!background_is_light && ColorUtils::themeIsDark()) ) { + // usually black/darker color in light mode and white/lighter color in dark mode return QApplication::palette().text().color(); } + // usually white/lighter color in light mode and black/darker color in dark mode return QApplication::palette().base().color(); } -- cgit v1.2.3