on xenial help sign in
Add support for foreground color in StyleTool.
2998644Michał Sawicz
plugins/Dash/StyleTool.qml+7
@@ -24,8 +24,15 @@ import QtQuick 2.2
24 */
24 */
25
25
26QtObject {
26QtObject {
27+ /// Style object passed from the scope
28+ property var style: {}
29+
27 /// Calculate luminance of the passed color
30 /// Calculate luminance of the passed color
28 function luminance(color) {
31 function luminance(color) {
29 return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
32 return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
30 }
33 }
34+
35+ /// Color used for text and symbolic icons
36+ // FIXME: should be taken from the theme
37+ readonly property color foreground: style && "foreground-color" in style ? style["foreground-color"] : "grey"
31}
38}
tests/plugins/Dash/tst_StyleTool.qml+21
@@ -33,6 +33,12 @@ Rectangle {
33 when: windowShown
33 when: windowShown
34
34
35 property color color
35 property color color
36+ property var styles: [
37+ {},
38+ { "foreground-color": "red" },
39+ { "foreground-color": "green" },
40+ { "foreground-color": "blue" },
41+ ]
36
42
37 function cleanup() {
43 function cleanup() {
38 testCase.color = "transparent";
44 testCase.color = "transparent";
@@ -55,5 +61,20 @@ Rectangle {
55 testCase.color = data.tag;
61 testCase.color = data.tag;
56 compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
62 compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
57 }
63 }
64+
65+ function test_foreground_data() {
66+ return [
67+ { tag: "default", index: 0, foreground: "grey" },
68+ { tag: "red", index: 1, foreground: "red" },
69+ { tag: "green", index: 2, foreground: "green" },
70+ { tag: "blue", index: 3, foreground: "blue" },
71+ ];
72+ }
73+
74+ function test_foreground(data) {
75+ tool.style = testCase.styles[data.index];
76+ verify(Qt.colorEqual(tool.foreground, data.foreground),
77+ "Foreground color not equal: %1 != %2".arg(tool.foreground).arg(data.foreground));
78+ }
58 }
79 }
59}
80}