on xenial help sign in
Implement dark and light color properties instead of inverse.
commitf0b0dbb965f44828a4f00862c5aa614657ffd926 authorMichał Sawicz <michal.sawicz@canonical.com> dateSun 6 Jul 2014, 11:15 (12 years ago) parente31839d
2 files changed+52−11
plugins/Dash/StyleTool.qml+28−4 tests/plugins/Dash/tst_StyleTool.qml+24−7
plugins/Dash/StyleTool.qml+28−4
@@ -36,8 +36,7 @@ QtObject {
3636 }
3737
3838 /// Color used for text and symbolic icons
39− // FIXME: should be taken from the theme
40− readonly property color foreground: style && "foreground-color" in style ? style["foreground-color"] : "grey"
39+ readonly property color foreground: style && "foreground-color" in style ? style["foreground-color"] : d.defaultDark
4140
4241 /// Color used for the overall background
4342 readonly property color background: style && "background-color" in style ? style["background-color"] : "transparent"
@@ -48,11 +47,36 @@ QtObject {
4847 */
4948 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
5049
51− /// Whether back- and foreground colors are inversed (light on dark instead of dark on light)
52− readonly property bool inverse: d.foregroundLuminance < (background.a !== 1.0 ? 0.5 : d.backgroundLuminance)
50+ /*! \brief The lighter of foreground and background colors
5351
52+ \note If background color is not fully opaque, it's not taken into account
53+ and defaults to the theme-provided light color.
54+ */
55+ readonly property color light: {
56+ if (background.a !== 1.0) return d.foregroundLuminance > d.defaultLightLuminance ? foreground : d.defaultLight;
57+ return d.foregroundLuminance > d.backgroundLuminance ? foreground : background;
58+ }
59+
60+ /*! \brief The darker of foreground and background colors
61+
62+ \note If background color is not fully opaque, it's not taken into account
63+ and defaults to the theme-provided dark color.
64+ */
65+ readonly property color dark: {
66+ if (background.a !== 1.0) return d.foregroundLuminance < d.defaultDarkLuminance ? foreground : d.defaultDark;
67+ return d.foregroundLuminance < d.backgroundLuminance ? foreground : background;
68+ }
69+
70+ //! @cond
5471 property var d: QtObject {
5572 readonly property real foregroundLuminance: luminance(foreground)
5673 readonly property real backgroundLuminance: luminance(background)
74+
75+ // FIXME: should be taken from the theme
76+ readonly property color defaultLight: "white"
77+ readonly property color defaultDark: "grey"
78+ readonly property real defaultLightLuminance: luminance(defaultLight)
79+ readonly property real defaultDarkLuminance: luminance(defaultDark)
5780 }
81+ //! @endcond
5882}
tests/plugins/Dash/tst_StyleTool.qml+24−7
@@ -106,18 +106,35 @@ Rectangle {
106106 compare(tool.threshold.toFixed(4), data.threshold.toFixed(4), "Luminance threshold was incorrect.");
107107 }
108108
109− function test_inverse_data() {
109+ function test_light_data() {
110110 return [
111− { tag: "default", index: 0, inverse: false },
112− { tag: "red on black", index: 1, inverse: false },
113− { tag: "green on white", index: 2, inverse: true },
114− { tag: "blue on darkgrey", index: 3, inverse: true },
111+ { tag: "default", index: 0, light: "white" },
112+ { tag: "red on black", index: 1, light: "red" },
113+ { tag: "green on white", index: 2, light: "white" },
114+ { tag: "blue on darkgrey", index: 3, light: "darkgrey" },
115115 ];
116116 }
117117
118− function test_inverse(data) {
118+ function test_light(data) {
119119 tool.style = testCase.styles[data.index];
120− compare(tool.inverse, data.inverse, "Inversion was incorrect.");
120+ verify(Qt.colorEqual(tool.light, data.light),
121+ "Light color not equal: %1 != %2".arg(tool.light).arg(data.light));
121122 }
123+
124+ function test_dark_data() {
125+ return [
126+ { tag: "default", index: 0, dark: "grey" },
127+ { tag: "red on black", index: 1, dark: "black" },
128+ { tag: "green on white", index: 2, dark: "green" },
129+ { tag: "blue on darkgrey", index: 3, dark: "blue" },
130+ ];
131+ }
132+
133+ function test_dark(data) {
134+ tool.style = testCase.styles[data.index];
135+ verify(Qt.colorEqual(tool.dark, data.dark),
136+ "Dark color not equal: %1 != %2".arg(tool.dark).arg(data.dark));
137+ }
138+
122139 }
123140}