Welcome to mirror list, hosted at ThFree Co, Russian Federation.

generate-ApplicationPalette-class.py « scripts - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c459c196d7208b8e7c384a4bfb0da071d8299e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2005-2019 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.

# 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"]

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;
		}
"""

role_multigettersetter_template = """
	QBrush get_%(role)s() {
		if (%(comparators)s) {
			return %(representative)s;
		}
		return QBrush();
	}

	void set_%(role)s(const QBrush& brush) {
%(setters)s
	}
"""

role_multisetter_template="""		m_%(prop)s = brush;
"""


paletteupdate_template ="""
			if (m_%(prop)s) {
				newPalette.setBrush(QPalette::%(group)s, QPalette::%(role)s, *m_%(prop)s);
			}
"""

variable_template = """		boost::optional<QBrush> m_%(prop)s;
"""

reset_template = """			m_%(prop)s = boost::none;
"""

def rolename(role):
    return role.lower()

def groupname(group):
    return group.lower()

def propname(role, group):
    return rolename(role) + "_" + groupname(group)


def add_role_property(variables, role):
    """
    Add a property that sets all color groups to the same QBrush using
    the setters of the single group properties.
    """
    variables["properties"] += property_template % {"prop": rolename(role)}
    # Build a comparator that checks whether all properties
    # are equal and can be represented as one QBrush.
    all_groups_equal = " && ".join(
        ['property("%s") == property("%s")' % (propname(role, color_group[0]), propname(role, color_group[i])) for i in
         range(1, len(color_group))])
    role_representative = 'qvariant_cast<QBrush>(property("%s"))' % propname(role, color_group[0])
    role_multisetters = "".join([role_multisetter_template % {"prop": propname(role, group)} for group in color_group])
    variables["getterssetters"] += role_multigettersetter_template % {"role": rolename(role),
                                                                      "comparators": all_groups_equal,
                                                                      "representative": role_representative,
                                                                      "setters": role_multisetters}

def add_role_group_property(variables, role, group):
    """
    Add separate group properties.
    """
    vars = {"prop" : propname(role, group),
            "group" : group,
            "role" : role}

    variables["properties"] += property_template % vars
    variables["getterssetters"] += gettersetter_template % vars
    variables["paletteupdates"] += paletteupdate_template % vars
    variables["variables"] += variable_template % vars
    variables["propertyresets"] += reset_template % vars


if __name__ == "__main__":
    template = open(template_source, "r").read()

    variables = {"warning": "// Auto-generated from %s . Do not edit manually." % template_source,
                 "properties": "",
                 "propertyresets": "",
                 "getterssetters": "",
                 "paletteupdates": "",
                 "variables": ""}

    for role in color_role:
        add_role_property(variables, role)

        for group in color_group:
            add_role_group_property(variables, role, group)


    open(target, "w").write(template % variables)