From ddde4bdd273749fc244613c04d88856667e0920a Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 21 Mar 2016 12:48:06 +0100 Subject: Utils: Improved handling of StyleHelper::baseColor This change makes sure that the "UI coloring" feature respects the original brightness of the current theme. It prevents dark themes from getting a too light recoloring and vice versa. Extra benefit: this allows to remove much recently introduced code. Change-Id: Ib2c96e7ed172a4cc97520aa4b5d180cc6353c661 Reviewed-by: hjk --- src/libs/utils/stylehelper.cpp | 22 ++++++++++++++-------- src/libs/utils/stylehelper.h | 1 - 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/libs') diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp index 9431cbe18d..8de43c24bb 100644 --- a/src/libs/utils/stylehelper.cpp +++ b/src/libs/utils/stylehelper.cpp @@ -25,6 +25,7 @@ #include "stylehelper.h" +#include "theme/theme.h" #include "hostosinfo.h" #include @@ -108,11 +109,6 @@ QColor StyleHelper::baseColor(bool lightColored) return m_baseColor.lighter(230); } -bool StyleHelper::isBaseColorDefault() -{ - return m_requestedBaseColor == DEFAULT_BASE_COLOR; -} - QColor StyleHelper::highlightColor(bool lightColored) { QColor result = baseColor(lightColored); @@ -152,10 +148,20 @@ void StyleHelper::setBaseColor(const QColor &newcolor) { m_requestedBaseColor = newcolor; + const QColor themeBaseColor = creatorTheme()->color(Theme::PanelStatusBarBackgroundColor); + const QColor defaultBaseColor = QColor(DEFAULT_BASE_COLOR); QColor color; - color.setHsv(newcolor.hue(), - newcolor.saturation() * 0.7, - 64 + newcolor.value() / 3); + + if (defaultBaseColor == newcolor) { + color = themeBaseColor; + } else { + const int valueDelta = (newcolor.value() - defaultBaseColor.value()) / 3; + const int value = qBound(0, themeBaseColor.value() + valueDelta, 255); + + color.setHsv(newcolor.hue(), + newcolor.saturation() * 0.7, + value); + } if (color.isValid() && color != m_baseColor) { m_baseColor = color; diff --git a/src/libs/utils/stylehelper.h b/src/libs/utils/stylehelper.h index 5ac91df433..7e483c43f1 100644 --- a/src/libs/utils/stylehelper.h +++ b/src/libs/utils/stylehelper.h @@ -56,7 +56,6 @@ public: // This is our color table, all colors derive from baseColor static QColor requestedBaseColor() { return m_requestedBaseColor; } static QColor baseColor(bool lightColored = false); - static bool isBaseColorDefault(); static QColor panelTextColor(bool lightColored = false); static QColor highlightColor(bool lightColored = false); static QColor shadowColor(bool lightColored = false); -- cgit v1.2.1