on xenial help sign in
Add support for inversion in StyleTool.
commit9e0acf7429f7db4b33adcf2a33159a7527c1d572 authorMichał Sawicz <michal.sawicz@canonical.com> dateSun 6 Jul 2014, 03:28 (12 years ago) parent3428442
3 files changed+22−2
plugins/Dash/StyleTool.qml+3 tests/plugins/Dash/CMakeLists.txt+4−1 tests/plugins/Dash/tst_StyleTool.qml+15−1
plugins/Dash/StyleTool.qml+3
@@ -48,6 +48,9 @@ QtObject {
4848 */
4949 readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
5050
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+
5154 property var d: QtObject {
5255 readonly property real foregroundLuminance: luminance(foreground)
5356 readonly property real backgroundLuminance: luminance(background)
tests/plugins/Dash/CMakeLists.txt+4−1
@@ -73,8 +73,11 @@ qt5_use_modules(CardCreatorTestExec Test Core Qml)
7373target_link_libraries(CardCreatorTestExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
7474add_binary_qml_test(CardCreator "" "Dash-qml")
7575
76+# qml unit test
77+set(qmltest_DEFAULT_TARGETS qmltests)
78+add_qml_test(. StyleTool IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
79+
7680# plain qml test
7781set(qmltest_DEFAULT_TARGETS qmluitests)
7882set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
7983add_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 {
103103
104104 function test_threshold(data) {
105105 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.");
107121 }
108122 }
109123}