on xenial help sign in
Implement dark and light color properties instead of inverse.
f0b0dbbMichał Sawicz
plugins/Dash/StyleTool.qml+28−4
@@ -36,8 +36,7 @@ QtObject {
36 }
36 }
37
37
38 /// Color used for text and symbolic icons
38 /// 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
41
40
42 /// Color used for the overall background
41 /// Color used for the overall background
43 readonly property color background: style && "background-color" in style ? style["background-color"] : "transparent"
42 readonly property color background: style && "background-color" in style ? style["background-color"] : "transparent"
@@ -48,11 +47,36 @@ QtObject {
48 */
47 */
49 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
48 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
50
49
51− /// Whether back- and foreground colors are inversed (light on dark instead of dark on light)
50+ /*! \brief The lighter of foreground and background colors
52− readonly property bool inverse: d.foregroundLuminance < (background.a !== 1.0 ? 0.5 : d.backgroundLuminance)
53
51
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
54 property var d: QtObject {
71 property var d: QtObject {
55 readonly property real foregroundLuminance: luminance(foreground)
72 readonly property real foregroundLuminance: luminance(foreground)
56 readonly property real backgroundLuminance: luminance(background)
73 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)
57 }
80 }
81+ //! @endcond
58}
82}
tests/plugins/Dash/tst_StyleTool.qml+24−7
@@ -106,18 +106,35 @@ Rectangle {
106 compare(tool.threshold.toFixed(4), data.threshold.toFixed(4), "Luminance threshold was incorrect.");
106 compare(tool.threshold.toFixed(4), data.threshold.toFixed(4), "Luminance threshold was incorrect.");
107 }
107 }
108
108
109− function test_inverse_data() {
109+ function test_light_data() {
110 return [
110 return [
111− { tag: "default", index: 0, inverse: false },
111+ { tag: "default", index: 0, light: "white" },
112− { tag: "red on black", index: 1, inverse: false },
112+ { tag: "red on black", index: 1, light: "red" },
113− { tag: "green on white", index: 2, inverse: true },
113+ { tag: "green on white", index: 2, light: "white" },
114− { tag: "blue on darkgrey", index: 3, inverse: true },
114+ { tag: "blue on darkgrey", index: 3, light: "darkgrey" },
115 ];
115 ];
116 }
116 }
117
117
118− function test_inverse(data) {
118+ function test_light(data) {
119 tool.style = testCase.styles[data.index];
119 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));
121 }
122 }
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+
122 }
139 }
123}
140}