Commit a30b9b6c authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Alessandro Portale

Theming: Do not hardcode the mapping from theming colors to QPalette

There is no reason to hardcode the mapping from theming color roles
to QPalette roles, since such a mapping can be easily defined in the
theme itself.

I added optional color roles for each QPalette role.

Themes that do not change the palette do not have to take care at
all and themes that change the palette define only the QPalette roles
they require.

Change-Id: Id195052c96117b7a1a8d7d7d6acacd44e66e22f3
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@theqtcompany.com>
parent 116baad6
......@@ -12,13 +12,16 @@ selectedBackground=46ffffff
normalBackground=ff333333
alternateBackground=ff515151
error=ffff0000
textColorLink=ff007af4
textColorLinkVisited=ffa57aff
backgroundColorDisabled=ff444444
[Colors]
BackgroundColorAlternate=alternateBackground
BackgroundColorDark=shadowBackground
BackgroundColorHover=hoverBackground
BackgroundColorNormal=normalBackground
BackgroundColorDisabled=ff444444
BackgroundColorDisabled=backgroundColorDisabled
BackgroundColorSelected=selectedBackground
BadgeLabelBackgroundColorChecked=normalBackground
BadgeLabelBackgroundColorUnchecked=selectedBackground
......@@ -112,8 +115,8 @@ SplitterColor=ff313131
TextColorDisabled=textDisabled
TextColorError=ffff4040
TextColorHighlight=ffff0000
TextColorLink=ff007af4
TextColorLinkVisited=ffa57aff
TextColorLink=textColorLink
TextColorLinkVisited=textColorLinkVisited
TextColorNormal=text
TodoItemTextColor=ff000000
ToggleButtonBackgroundColor=shadowBackground
......@@ -177,6 +180,26 @@ ProjectExplorer_TaskWarn_TextMarkColor=ffffff40
ClangCodeModel_Error_TextMarkColor=ffff882f
ClangCodeModel_Warning_TextMarkColor=ffceff40
PaletteWindow=normalBackground
PaletteWindowText=text
PaletteBase=normalBackground
PaletteAlternateBase=alternateBackground
PaletteButton=shadowBackground
PaletteBrightText=ffff0000
PaletteText=text
PaletteButtonText=text
PaletteToolTipBase=selectedBackground
PaletteHighlight=selectedBackground
PaletteDark=shadowBackground
PaletteHighlightedText=ffffffff
PaletteToolTipText=text
PaletteLink=textColorLink
PaletteLinkVisited=textColorLinkVisited
PaletteWindowDisabled=backgroundColorDisabled
PaletteWindowTextDisabled=textDisabled
PaletteBaseDisabled=backgroundColorDisabled
PaletteTextDisabled=textDisabled
[Flags]
ComboBoxDrawTextShadow=false
DerivePaletteFromTheme=true
......
......@@ -17,13 +17,16 @@ normalBackground=ff2E2F30
alternateBackground=ff353637
error=ffe41e25
splitter=ff06080A
textColorLink=ff007af4
textColorLinkVisited=ffa57aff
backgroundColorDisabled=ff444444
[Colors]
BackgroundColorAlternate=alternateBackground
BackgroundColorDark=shadowBackground
BackgroundColorHover=hoverBackground
BackgroundColorNormal=normalBackground
BackgroundColorDisabled=ff444444
BackgroundColorDisabled=backgroundColorDisabled
BackgroundColorSelected=selectedBackground
BadgeLabelBackgroundColorChecked=ffe0e0e0
BadgeLabelBackgroundColorUnchecked=ff808080
......@@ -117,8 +120,8 @@ SplitterColor=splitter
TextColorDisabled=textDisabled
TextColorError=ffff4040
TextColorHighlight=ffff0000
TextColorLink=ff007af4
TextColorLinkVisited=ffa57aff
TextColorLink=textColorLink
TextColorLinkVisited=textColorLinkVisited
TextColorNormal=text
TodoItemTextColor=text
ToggleButtonBackgroundColor=shadowBackground
......@@ -182,6 +185,26 @@ ProjectExplorer_TaskWarn_TextMarkColor=ffffff40
ClangCodeModel_Error_TextMarkColor=ffff882f
ClangCodeModel_Warning_TextMarkColor=ffceff40
PaletteWindow=normalBackground
PaletteWindowText=text
PaletteBase=normalBackground
PaletteAlternateBase=alternateBackground
PaletteButton=shadowBackground
PaletteBrightText=ffff0000
PaletteText=text
PaletteButtonText=text
PaletteToolTipBase=selectedBackground
PaletteHighlight=selectedBackground
PaletteDark=shadowBackground
PaletteHighlightedText=ffffffff
PaletteToolTipText=text
PaletteLink=textColorLink
PaletteLinkVisited=textColorLinkVisited
PaletteWindowDisabled=backgroundColorDisabled
PaletteWindowTextDisabled=textDisabled
PaletteBaseDisabled=backgroundColorDisabled
PaletteTextDisabled=textDisabled
[Flags]
ComboBoxDrawTextShadow=false
DerivePaletteFromTheme=true
......
......@@ -192,8 +192,9 @@ void Theme::readSettings(QSettings &settings)
for (int i = 0, total = e.keyCount(); i < total; ++i) {
const QString key = QLatin1String(e.key(i));
if (!settings.contains(key)) {
qWarning("Theme \"%s\" misses color setting for key \"%s\".",
qPrintable(d->fileName), qPrintable(key));
if (i < PaletteWindow || i > PaletteShadowDisabled)
qWarning("Theme \"%s\" misses color setting for key \"%s\".",
qPrintable(d->fileName), qPrintable(key));
continue;
}
d->colors[i] = readNamedColor(settings.value(key).toString());
......@@ -253,27 +254,64 @@ QPalette Theme::palette() const
if (!flag(DerivePaletteFromTheme))
return pal;
// FIXME: introduce some more color roles for this
const static struct {
Color themeColor;
QPalette::ColorRole paletteColorRole;
QPalette::ColorGroup paletteColorGroup;
bool setColorRoleAsBrush;
} mapping[] = {
{ PaletteWindow, QPalette::Window, QPalette::All, false},
{ PaletteWindowDisabled, QPalette::Window, QPalette::Disabled, false},
{ PaletteWindowText, QPalette::WindowText, QPalette::All, true},
{ PaletteWindowTextDisabled, QPalette::WindowText, QPalette::Disabled, true},
{ PaletteBase, QPalette::Base, QPalette::All, false},
{ PaletteBaseDisabled, QPalette::Base, QPalette::Disabled, false},
{ PaletteAlternateBase, QPalette::AlternateBase, QPalette::All, false},
{ PaletteAlternateBaseDisabled, QPalette::AlternateBase, QPalette::Disabled, false},
{ PaletteToolTipBase, QPalette::ToolTipBase, QPalette::All, true},
{ PaletteToolTipBaseDisabled, QPalette::ToolTipBase, QPalette::Disabled, true},
{ PaletteToolTipText, QPalette::ToolTipText, QPalette::All, false},
{ PaletteToolTipTextDisabled, QPalette::ToolTipText, QPalette::Disabled, false},
{ PaletteText, QPalette::Text, QPalette::All, true},
{ PaletteTextDisabled, QPalette::Text, QPalette::Disabled, true},
{ PaletteButton, QPalette::Button, QPalette::All, false},
{ PaletteButtonDisabled, QPalette::Button, QPalette::Disabled, false},
{ PaletteButtonText, QPalette::ButtonText, QPalette::All, true},
{ PaletteButtonTextDisabled, QPalette::ButtonText, QPalette::Disabled, true},
{ PaletteBrightText, QPalette::BrightText, QPalette::All, false},
{ PaletteBrightTextDisabled, QPalette::BrightText, QPalette::Disabled, false},
{ PaletteHighlight, QPalette::Highlight, QPalette::All, true},
{ PaletteHighlightDisabled, QPalette::Highlight, QPalette::Disabled, true},
{ PaletteHighlightedText, QPalette::HighlightedText, QPalette::All, true},
{ PaletteHighlightedTextDisabled, QPalette::HighlightedText, QPalette::Disabled, true},
{ PaletteLink, QPalette::Link, QPalette::All, false},
{ PaletteLinkDisabled, QPalette::Link, QPalette::Disabled, false},
{ PaletteLinkVisited, QPalette::LinkVisited, QPalette::All, false},
{ PaletteLinkVisitedDisabled, QPalette::LinkVisited, QPalette::Disabled, false},
{ PaletteLight, QPalette::Light, QPalette::All, false},
{ PaletteLightDisabled, QPalette::Light, QPalette::Disabled, false},
{ PaletteMidlight, QPalette::Midlight, QPalette::All, false},
{ PaletteMidlightDisabled, QPalette::Midlight, QPalette::Disabled, false},
{ PaletteDark, QPalette::Dark, QPalette::All, false},
{ PaletteDarkDisabled, QPalette::Dark, QPalette::Disabled, false},
{ PaletteMid, QPalette::Mid, QPalette::All, false},
{ PaletteMidDisabled, QPalette::Mid, QPalette::Disabled, false},
{ PaletteShadow, QPalette::Shadow, QPalette::All, false},
{ PaletteShadowDisabled, QPalette::Shadow, QPalette::Disabled, false}
};
for (auto entry: mapping) {
const QColor themeColor = color(entry.themeColor);
// Use original color if color is not defined in theme.
if (themeColor.isValid()) {
if (entry.setColorRoleAsBrush)
// TODO: Find out why sometimes setBrush is used
pal.setBrush(entry.paletteColorGroup, entry.paletteColorRole, themeColor);
else
pal.setColor(entry.paletteColorGroup, entry.paletteColorRole, themeColor);
}
}
pal.setColor(QPalette::Window, color(Theme::BackgroundColorNormal));
pal.setBrush(QPalette::WindowText, color(Theme::TextColorNormal));
pal.setColor(QPalette::Base, color(Theme::BackgroundColorNormal));
pal.setColor(QPalette::AlternateBase, color(Theme::BackgroundColorAlternate));
pal.setColor(QPalette::Button, color(Theme::BackgroundColorDark));
pal.setColor(QPalette::BrightText, Qt::red);
pal.setBrush(QPalette::Text, color(Theme::TextColorNormal));
pal.setBrush(QPalette::ButtonText, color(Theme::TextColorNormal));
pal.setBrush(QPalette::ToolTipBase, color(Theme::BackgroundColorSelected));
pal.setColor(QPalette::Highlight, color(Theme::BackgroundColorSelected));
pal.setColor(QPalette::Dark, color(Theme::BackgroundColorDark));
pal.setColor(QPalette::HighlightedText, Qt::white);
pal.setColor(QPalette::ToolTipText, color(Theme::TextColorNormal));
pal.setColor(QPalette::Link, color(Theme::TextColorLink));
pal.setColor(QPalette::LinkVisited, color(Theme::TextColorLinkVisited));
pal.setColor(QPalette::Disabled, QPalette::Window, color(Theme::BackgroundColorDisabled));
pal.setBrush(QPalette::Disabled, QPalette::WindowText, color(Theme::TextColorDisabled));
pal.setColor(QPalette::Disabled, QPalette::Base, color(Theme::BackgroundColorDisabled));
pal.setBrush(QPalette::Disabled, QPalette::Text, color(Theme::TextColorDisabled));
return pal;
}
......
......@@ -125,6 +125,52 @@ public:
TreeViewArrowColorNormal,
TreeViewArrowColorSelected,
/* Palette for QPalette */
PaletteWindow,
PaletteWindowText,
PaletteBase,
PaletteAlternateBase,
PaletteToolTipBase,
PaletteToolTipText,
PaletteText,
PaletteButton,
PaletteButtonText,
PaletteBrightText,
PaletteHighlight,
PaletteHighlightedText,
PaletteLink,
PaletteLinkVisited,
PaletteLight,
PaletteMidlight,
PaletteDark,
PaletteMid,
PaletteShadow,
PaletteWindowDisabled,
PaletteBackgroundDisabled,
PaletteWindowTextDisabled,
PaletteForegroundDisabled,
PaletteBaseDisabled,
PaletteAlternateBaseDisabled,
PaletteToolTipBaseDisabled,
PaletteToolTipTextDisabled,
PaletteTextDisabled,
PaletteButtonDisabled,
PaletteButtonTextDisabled,
PaletteBrightTextDisabled,
PaletteHighlightDisabled,
PaletteHighlightedTextDisabled,
PaletteLinkDisabled,
PaletteLinkVisitedDisabled,
PaletteLightDisabled,
PaletteMidlightDisabled,
PaletteDarkDisabled,
PaletteMidDisabled,
PaletteShadowDisabled,
/* Icons */
IconsBaseColor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment