forked from qt-creator/qt-creator
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 <hjk@theqtcompany.com>
This commit is contained in:
@@ -77,7 +77,7 @@ MiniProjectTargetSelectorBackgroundColor=ffa0a0a0
|
|||||||
MiniProjectTargetSelectorBorderColor=ff000000
|
MiniProjectTargetSelectorBorderColor=ff000000
|
||||||
MiniProjectTargetSelectorSummaryBackgroundColor=ff464646
|
MiniProjectTargetSelectorSummaryBackgroundColor=ff464646
|
||||||
MiniProjectTargetSelectorTextColor=a0ffffff
|
MiniProjectTargetSelectorTextColor=a0ffffff
|
||||||
PanelStatusBarBackgroundColor=ffff0000
|
PanelStatusBarBackgroundColor=ff626262
|
||||||
PanelsWidgetSeparatorLineColor=ffbfbcb8
|
PanelsWidgetSeparatorLineColor=ffbfbcb8
|
||||||
PanelTextColorDark=darkText
|
PanelTextColorDark=darkText
|
||||||
PanelTextColorMid=ff909090
|
PanelTextColorMid=ff909090
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "stylehelper.h"
|
#include "stylehelper.h"
|
||||||
|
|
||||||
|
#include "theme/theme.h"
|
||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
|
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
@@ -108,11 +109,6 @@ QColor StyleHelper::baseColor(bool lightColored)
|
|||||||
return m_baseColor.lighter(230);
|
return m_baseColor.lighter(230);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyleHelper::isBaseColorDefault()
|
|
||||||
{
|
|
||||||
return m_requestedBaseColor == DEFAULT_BASE_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor StyleHelper::highlightColor(bool lightColored)
|
QColor StyleHelper::highlightColor(bool lightColored)
|
||||||
{
|
{
|
||||||
QColor result = baseColor(lightColored);
|
QColor result = baseColor(lightColored);
|
||||||
@@ -152,10 +148,20 @@ void StyleHelper::setBaseColor(const QColor &newcolor)
|
|||||||
{
|
{
|
||||||
m_requestedBaseColor = newcolor;
|
m_requestedBaseColor = newcolor;
|
||||||
|
|
||||||
|
const QColor themeBaseColor = creatorTheme()->color(Theme::PanelStatusBarBackgroundColor);
|
||||||
|
const QColor defaultBaseColor = QColor(DEFAULT_BASE_COLOR);
|
||||||
QColor color;
|
QColor color;
|
||||||
color.setHsv(newcolor.hue(),
|
|
||||||
newcolor.saturation() * 0.7,
|
if (defaultBaseColor == newcolor) {
|
||||||
64 + newcolor.value() / 3);
|
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) {
|
if (color.isValid() && color != m_baseColor) {
|
||||||
m_baseColor = color;
|
m_baseColor = color;
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ public:
|
|||||||
// This is our color table, all colors derive from baseColor
|
// This is our color table, all colors derive from baseColor
|
||||||
static QColor requestedBaseColor() { return m_requestedBaseColor; }
|
static QColor requestedBaseColor() { return m_requestedBaseColor; }
|
||||||
static QColor baseColor(bool lightColored = false);
|
static QColor baseColor(bool lightColored = false);
|
||||||
static bool isBaseColorDefault();
|
|
||||||
static QColor panelTextColor(bool lightColored = false);
|
static QColor panelTextColor(bool lightColored = false);
|
||||||
static QColor highlightColor(bool lightColored = false);
|
static QColor highlightColor(bool lightColored = false);
|
||||||
static QColor shadowColor(bool lightColored = false);
|
static QColor shadowColor(bool lightColored = false);
|
||||||
|
|||||||
@@ -272,9 +272,7 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
|
|||||||
if (creatorTheme()->widgetStyle () == Theme::StyleFlat) {
|
if (creatorTheme()->widgetStyle () == Theme::StyleFlat) {
|
||||||
// this paints the background of the bottom portion of the
|
// this paints the background of the bottom portion of the
|
||||||
// left tab bar
|
// left tab bar
|
||||||
painter.fillRect(event->rect(), StyleHelper::isBaseColorDefault()
|
painter.fillRect(event->rect(), StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::FancyTabBarBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
painter.setPen(creatorTheme()->color(Theme::FancyToolBarSeparatorColor));
|
painter.setPen(creatorTheme()->color(Theme::FancyToolBarSeparatorColor));
|
||||||
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
|
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -118,9 +118,7 @@ void FancyTabBar::paintEvent(QPaintEvent *event)
|
|||||||
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
|
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
|
||||||
// draw background of upper part of left tab widget
|
// draw background of upper part of left tab widget
|
||||||
// (Welcome, ... Help)
|
// (Welcome, ... Help)
|
||||||
p.fillRect(event->rect(), StyleHelper::isBaseColorDefault()
|
p.fillRect(event->rect(), StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::FancyTabBarBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count(); ++i)
|
for (int i = 0; i < count(); ++i)
|
||||||
|
|||||||
@@ -528,9 +528,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
|
|||||||
painter->drawLine(borderRect.topLeft(), borderRect.topRight());
|
painter->drawLine(borderRect.topLeft(), borderRect.topRight());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
} else {
|
} else {
|
||||||
painter->fillRect(rect, StyleHelper::isBaseColorDefault()
|
painter->fillRect(rect, StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::PanelStatusBarBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -653,9 +651,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
|||||||
const bool dis = !(mbi->state & State_Enabled);
|
const bool dis = !(mbi->state & State_Enabled);
|
||||||
|
|
||||||
if (creatorTheme()->flag(Theme::FlatMenuBar))
|
if (creatorTheme()->flag(Theme::FlatMenuBar))
|
||||||
painter->fillRect(option->rect, StyleHelper::isBaseColorDefault()
|
painter->fillRect(option->rect, StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::MenuBarItemBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
else
|
else
|
||||||
StyleHelper::menuGradient(painter, option->rect, option->rect);
|
StyleHelper::menuGradient(painter, option->rect, option->rect);
|
||||||
|
|
||||||
@@ -793,9 +789,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
|||||||
option->rect.bottomRight() + QPointF(0.5, 0.5));
|
option->rect.bottomRight() + QPointF(0.5, 0.5));
|
||||||
painter->restore();
|
painter->restore();
|
||||||
} else {
|
} else {
|
||||||
painter->fillRect(option->rect, StyleHelper::isBaseColorDefault()
|
painter->fillRect(option->rect, StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::MenuBarEmptyAreaBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -817,9 +811,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
|||||||
bool drawLightColored = lightColored(widget);
|
bool drawLightColored = lightColored(widget);
|
||||||
// draws the background of the 'Type hierarchy', 'Projects' headers
|
// draws the background of the 'Type hierarchy', 'Projects' headers
|
||||||
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
|
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
|
||||||
painter->fillRect(rect, StyleHelper::isBaseColorDefault()
|
painter->fillRect(rect, StyleHelper::baseColor(drawLightColored));
|
||||||
? creatorTheme()->color(Theme::ToolBarBackgroundColor)
|
|
||||||
: StyleHelper::baseColor(drawLightColored));
|
|
||||||
else if (horizontal)
|
else if (horizontal)
|
||||||
StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
|
StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -296,9 +296,7 @@ void FutureProgress::paintEvent(QPaintEvent *)
|
|||||||
{
|
{
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
|
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
|
||||||
p.fillRect(rect(), StyleHelper::isBaseColorDefault()
|
p.fillRect(rect(), StyleHelper::baseColor());
|
||||||
? creatorTheme()->color(Theme::FutureProgressBackgroundColor)
|
|
||||||
: StyleHelper::baseColor());
|
|
||||||
} else {
|
} else {
|
||||||
QLinearGradient grad = StyleHelper::statusBarGradient(rect());
|
QLinearGradient grad = StyleHelper::statusBarGradient(rect());
|
||||||
p.fillRect(rect(), grad);
|
p.fillRect(rect(), grad);
|
||||||
|
|||||||
Reference in New Issue
Block a user