Theming: fix disabled menu items in dark theme

In the dark theme (fusion style under linux), disabled
menu items looked bad due to (1) SH_EtchDisabledText being enabled
and (2) a bright color for the etch effect.

This patch adds color values for normal and disabled text colors
for menu items. It also adds a color value "style" which indicates
that the color should just stay at the default of the style.
The default theme uses this value for the new menu item colors,
while the dark theme fixes the ugly colors.
The patch also disables etching for disabled text.

Task-number: QTCREATORBUG-13447
Change-Id: Ib54504693d28cf2c71f3fc5a88d3de014230b12b
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Thorben Kroeger <thorbenkroeger@gmail.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Thorben Kroeger
2015-03-21 13:13:59 +01:00
committed by Eike Ziller
parent 5dcd9fe694
commit e91e1a742c
5 changed files with 29 additions and 2 deletions

View File

@@ -53,6 +53,8 @@ MenuBarEmptyAreaBackgroundColor=shadowBackground
MenuBarItemBackgroundColor=shadowBackground
MenuBarItemTextColorDisabled=textDisabled
MenuBarItemTextColorNormal=text
MenuItemTextColorDisabled=textDisabled
MenuItemTextColorNormal=text
MiniProjectTargetSelectorBackgroundColor=shadowBackground
MiniProjectTargetSelectorBorderColor=shadowBackground
MiniProjectTargetSelectorSummaryBackgroundColor=shadowBackground

View File

@@ -47,6 +47,8 @@ MenuBarEmptyAreaBackgroundColor=ffff0000
MenuBarItemBackgroundColor=ffff0000
MenuBarItemTextColorDisabled=ffa0a0a4
MenuBarItemTextColorNormal=ff000000
MenuItemTextColorDisabled=style
MenuItemTextColorNormal=style
MiniProjectTargetSelectorBackgroundColor=ffa0a0a0
MiniProjectTargetSelectorBorderColor=ff000000
MiniProjectTargetSelectorSummaryBackgroundColor=ff464646

View File

@@ -113,6 +113,8 @@ QPair<QColor, QString> Theme::readNamedColor(const QString &color) const
{
if (d->palette.contains(color))
return qMakePair(d->palette[color], color);
if (color == QLatin1String("style"))
return qMakePair(QColor(), QString());
bool ok = true;
const QRgb rgba = color.toLongLong(&ok, 16);

View File

@@ -98,6 +98,8 @@ public:
MenuBarItemBackgroundColor,
MenuBarItemTextColorDisabled,
MenuBarItemTextColorNormal,
MenuItemTextColorDisabled,
MenuItemTextColorNormal,
MiniProjectTargetSelectorBackgroundColor,
MiniProjectTargetSelectorBorderColor,
MiniProjectTargetSelectorSummaryBackgroundColor,

View File

@@ -359,7 +359,7 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
ret = true;
break;
case QStyle::SH_EtchDisabledText:
if (panelWidget(widget))
if (panelWidget(widget) || qobject_cast<const QMenu *> (widget) )
ret = false;
break;
case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren:
@@ -614,7 +614,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
if (!panelWidget(widget))
if (!panelWidget(widget) && !qobject_cast<const QMenu *>(widget))
return QProxyStyle::drawControl(element, option, painter, widget);
switch (element) {
@@ -645,6 +645,25 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
}
break;
case CE_MenuItem:
painter->save();
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
const bool enabled = mbi->state & State_Enabled;
QStyleOptionMenuItem item = *mbi;
item.rect = mbi->rect;
const QColor color = creatorTheme()->color(enabled
? Theme::MenuItemTextColorNormal
: Theme::MenuItemTextColorDisabled);
if (color.isValid()) {
QPalette pal = mbi->palette;
pal.setBrush(QPalette::Text, color);
item.palette = pal;
}
QProxyStyle::drawControl(element, &item, painter, widget);
}
painter->restore();
break;
case CE_MenuBarItem:
painter->save();
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {