on xenial help sign in
Add support for foreground color in StyleTool.
commit29986444be67a58ad24f591e0385cb49d59150a5 authorMichał Sawicz <michal.sawicz@canonical.com> dateSun 6 Jul 2014, 02:35 (12 years ago) parent5d07940
2 files changed+28
plugins/Dash/StyleTool.qml+7 tests/plugins/Dash/tst_StyleTool.qml+21
plugins/Dash/StyleTool.qml+7
@@ -24,8 +24,15 @@ import QtQuick 2.2
2424 */
2525
2626QtObject {
27+ /// Style object passed from the scope
28+ property var style: {}
29+
2730 /// Calculate luminance of the passed color
2831 function luminance(color) {
2932 return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
3033 }
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"
3138}
tests/plugins/Dash/tst_StyleTool.qml+21
@@ -33,6 +33,12 @@ Rectangle {
3333 when: windowShown
3434
3535 property color color
36+ property var styles: [
37+ {},
38+ { "foreground-color": "red" },
39+ { "foreground-color": "green" },
40+ { "foreground-color": "blue" },
41+ ]
3642
3743 function cleanup() {
3844 testCase.color = "transparent";
@@ -55,5 +61,20 @@ Rectangle {
5561 testCase.color = data.tag;
5662 compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
5763 }
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+ }
5879 }
5980}