From e91e1a742c8a2eda0a1e3f8827c12fb0c1ef4591 Mon Sep 17 00:00:00 2001 From: Thorben Kroeger Date: Sat, 21 Mar 2015 13:13:59 +0100 Subject: 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 Reviewed-by: Thorben Kroeger Reviewed-by: Orgad Shaneh --- share/qtcreator/themes/dark.creatortheme | 2 ++ share/qtcreator/themes/default.creatortheme | 2 ++ src/libs/utils/theme/theme.cpp | 2 ++ src/libs/utils/theme/theme.h | 2 ++ src/plugins/coreplugin/manhattanstyle.cpp | 23 +++++++++++++++++++++-- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/share/qtcreator/themes/dark.creatortheme b/share/qtcreator/themes/dark.creatortheme index 0f49468454..54721a7627 100644 --- a/share/qtcreator/themes/dark.creatortheme +++ b/share/qtcreator/themes/dark.creatortheme @@ -53,6 +53,8 @@ MenuBarEmptyAreaBackgroundColor=shadowBackground MenuBarItemBackgroundColor=shadowBackground MenuBarItemTextColorDisabled=textDisabled MenuBarItemTextColorNormal=text +MenuItemTextColorDisabled=textDisabled +MenuItemTextColorNormal=text MiniProjectTargetSelectorBackgroundColor=shadowBackground MiniProjectTargetSelectorBorderColor=shadowBackground MiniProjectTargetSelectorSummaryBackgroundColor=shadowBackground diff --git a/share/qtcreator/themes/default.creatortheme b/share/qtcreator/themes/default.creatortheme index 5c02e74c11..27867b3d5f 100644 --- a/share/qtcreator/themes/default.creatortheme +++ b/share/qtcreator/themes/default.creatortheme @@ -47,6 +47,8 @@ MenuBarEmptyAreaBackgroundColor=ffff0000 MenuBarItemBackgroundColor=ffff0000 MenuBarItemTextColorDisabled=ffa0a0a4 MenuBarItemTextColorNormal=ff000000 +MenuItemTextColorDisabled=style +MenuItemTextColorNormal=style MiniProjectTargetSelectorBackgroundColor=ffa0a0a0 MiniProjectTargetSelectorBorderColor=ff000000 MiniProjectTargetSelectorSummaryBackgroundColor=ff464646 diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index c6a37e3c1e..13843d3dd5 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -113,6 +113,8 @@ QPair 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); diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h index 847b1e4bbf..1567532cee 100644 --- a/src/libs/utils/theme/theme.h +++ b/src/libs/utils/theme/theme.h @@ -98,6 +98,8 @@ public: MenuBarItemBackgroundColor, MenuBarItemTextColorDisabled, MenuBarItemTextColorNormal, + MenuItemTextColorDisabled, + MenuItemTextColorNormal, MiniProjectTargetSelectorBackgroundColor, MiniProjectTargetSelectorBorderColor, MiniProjectTargetSelectorSummaryBackgroundColor, diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 52074ffc57..9326552159 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -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 (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(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(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(option)) { -- cgit v1.2.3