diff options
author | Stefan Hacker <dd0t@users.sourceforge.net> | 2014-10-26 16:50:08 +0300 |
---|---|---|
committer | Stefan Hacker <dd0t@users.sourceforge.net> | 2014-10-26 17:21:30 +0300 |
commit | 291ed489d93a0501de20df0505c40723d5e1b70d (patch) | |
tree | 90c084d6ca8d3d0c513265f483a2dc95e027e132 /scripts | |
parent | fa5188c8279b185fcaf3dd7d3d48c49347de378a (diff) |
Add ApplicationPalette class which allows theming the QApplication::palette.
Qt allows setting custom QPROPERTY values from QSS themes. As we cannot
style QPalettes this class has a property for each color group and
color role in a palette and acts as a stand-in for QApplication::palette
in the theme. When setting a qproperty-<group>-<role> on it in QSS
the brush will be set on the application palette.
The ApplicationPalette is derived from QWidget but never visible.
It listens to style changes on itself as those indicate the
application palette should be updated again. Variables not set
in the QSS will not be touched in the palette.
There might be some interactions with system style or theme changes
that have not yet been explored. Those are edge cases though and
can be fixed later.
ApplicationPalette.h is generated from ApplicationPaletteTemplate.h using
the generate-ApplicationPalette-class.py script. While it isn't expected
that this file has to change a lot in the future auto-generation is much
easier than writing all that boilerplate from hand.
Fixes #1438
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/generate-ApplicationPalette-class.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/generate-ApplicationPalette-class.py b/scripts/generate-ApplicationPalette-class.py new file mode 100644 index 000000000..c48321458 --- /dev/null +++ b/scripts/generate-ApplicationPalette-class.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Generates the Mumble palette generation class from +# template_source and writes it into target after +# template expansion. + +template_source = "ApplicationPaletteTemplate.h" +target = "ApplicationPalette.h" + +color_group = ["Active", "Disabled", "Inactive"] +color_role = [ "WindowText", "Button", "Light", "Midlight", "Dark", "Mid", + "Text", "BrightText", "ButtonText", "Base", "Window", "Shadow", + "Highlight", "HighlightedText", + "Link", "LinkVisited", + "AlternateBase", + "ToolTipBase", "ToolTipText"] + + + +template = open(template_source, "r").read() + +variables = {"warning": "// Auto-generated from %s . Do not edit manually." % template_source, + "properties": "", + "getterssetters": "", + "paletteupdates": "", + "variables": ""} + +property_template = """ Q_PROPERTY(QBrush %(prop)s READ get_%(prop)s WRITE set_%(prop)s) +""" + +gettersetter_template = """ + QBrush get_%(prop)s() { + if (!m_%(prop)s) + return QBrush(); + + return *m_%(prop)s; + } + + void set_%(prop)s(const QBrush& brush) { + m_%(prop)s = brush; + } +""" + +paletteupdate_template =""" + if (m_%(prop)s) { + palette.setBrush(QPalette::%(group)s, QPalette::%(role)s, *m_%(prop)s); + } +""" + +variable_template = """ boost::optional<QBrush> m_%(prop)s; +""" + + +for group in color_group: + for role in color_role: + + vars = {"prop" : group.lower() + "_" + role.lower(), + "group" : group, + "role" : role} + + variables["properties"] += property_template % vars + variables["getterssetters"] += gettersetter_template % vars + variables["paletteupdates"] += paletteupdate_template % vars + variables["variables"] += variable_template % vars + + +open(target, "w").write(template % variables)
\ No newline at end of file |