on xenial help sign in
Introduce StyleTool.
commit5d07940da781fd9041f555b720d79edd220425cf authorMichał Sawicz <michal.sawicz@canonical.com> dateSun 6 Jul 2014, 02:25 (12 years ago) parentd3039f6
4 files changed+92
plugins/Dash/StyleTool.qml+31 plugins/Dash/qmldir+1 tests/plugins/Dash/CMakeLists.txt+1 tests/plugins/Dash/tst_StyleTool.qml+59
plugins/Dash/StyleTool.qmlnew file+31
@@ -0,0 +1,31 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.2
18+
19+/*! \brief Helper for processing scope customization options.
20+
21+ It will take the customizations object passed by the scope and
22+ process it to provide the scope UI with data such as colors or
23+ image paths.
24+ */
25+
26+QtObject {
27+ /// Calculate luminance of the passed color
28+ function luminance(color) {
29+ return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
30+ }
31+}
plugins/Dash/qmldir+1
@@ -2,3 +2,4 @@ module Dash
22plugin Dash-qml
33typeinfo Dash.qmltypes
44singleton CardCreatorCache 0.1 CardCreatorCache.qml
5+StyleTool 0.1 StyleTool.qml
tests/plugins/Dash/CMakeLists.txt+1
@@ -77,3 +77,4 @@ add_binary_qml_test(CardCreator "" "Dash-qml")
7777set(qmltest_DEFAULT_TARGETS qmluitests)
7878set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
7979add_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.qmlnew file+59
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.2
18+import QtTest 1.0
19+import Dash 0.1
20+import Ubuntu.Components 1.1
21+
22+Rectangle {
23+ width: units.gu(40)
24+ height: units.gu(71)
25+
26+ StyleTool {
27+ id: tool
28+ }
29+
30+ TestCase {
31+ id: testCase
32+ name: "StyleTool"
33+ when: windowShown
34+
35+ property color color
36+
37+ function cleanup() {
38+ testCase.color = "transparent";
39+ }
40+
41+ function test_luminance_data() {
42+ return [
43+ { tag: "#F00", luminance: 0.2126 },
44+ { tag: "#0F0", luminance: 0.7152 },
45+ { tag: "#00F", luminance: 0.0722 },
46+ { tag: "white", luminance: 1.0 },
47+ { tag: "black", luminance: 0.0 },
48+ { tag: "lightgrey", luminance: 0.8275 },
49+ { tag: "grey", luminance: 0.5020 },
50+ { tag: "darkgrey", luminance: 0.6627 },
51+ ];
52+ }
53+
54+ function test_luminance(data) {
55+ testCase.color = data.tag;
56+ compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
57+ }
58+ }
59+}