on xenial help sign in
Add support for inversion in StyleTool.
9e0acf7Michał Sawicz
plugins/Dash/StyleTool.qml+3
@@ -48,6 +48,9 @@ QtObject {
48 */
48 */
49 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
49 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
50
50
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)
53+
51 property var d: QtObject {
54 property var d: QtObject {
52 readonly property real foregroundLuminance: luminance(foreground)
55 readonly property real foregroundLuminance: luminance(foreground)
53 readonly property real backgroundLuminance: luminance(background)
56 readonly property real backgroundLuminance: luminance(background)
tests/plugins/Dash/CMakeLists.txt+4−1
@@ -73,8 +73,11 @@ qt5_use_modules(CardCreatorTestExec Test Core Qml)
73target_link_libraries(CardCreatorTestExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
73target_link_libraries(CardCreatorTestExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
74add_binary_qml_test(CardCreator "" "Dash-qml")
74add_binary_qml_test(CardCreator "" "Dash-qml")
75
75
76+# qml unit test
77+set(qmltest_DEFAULT_TARGETS qmltests)
78+add_qml_test(. StyleTool IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
79+
76# plain qml test
80# plain qml test
77set(qmltest_DEFAULT_TARGETS qmluitests)
81set(qmltest_DEFAULT_TARGETS qmluitests)
78set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
82set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
79add_qml_test(. ListViewWithPageHeaderQML IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
83add_qml_test(. ListViewWithPageHeaderQML IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
80−add_qml_test(. StyleTool IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
tests/plugins/Dash/tst_StyleTool.qml+15−1
@@ -103,7 +103,21 @@ Rectangle {
103
103
104 function test_threshold(data) {
104 function test_threshold(data) {
105 tool.style = testCase.styles[data.index];
105 tool.style = testCase.styles[data.index];
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+ }
108+
109+ function test_inverse_data() {
110+ 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 },
115+ ];
116+ }
117+
118+ function test_inverse(data) {
119+ tool.style = testCase.styles[data.index];
120+ compare(tool.inverse, data.inverse, "Inversion was incorrect.");
107 }
121 }
108 }
122 }
109}
123}