on xenial help sign in
Add luminance property to Background.qml
f58b35fMichał Sawicz
qml/Components/Background.qml+6
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import Utils 0.1 as Utils
18
19
19Loader {
20Loader {
20 id: root
21 id: root
@@ -23,6 +24,11 @@ Loader {
23 property url style
24 property url style
24 readonly property var parsedStyle: String(style)
25 readonly property var parsedStyle: String(style)
25 .match(/^(color|gradient):\/\/\/(?:(#(?:[0-9a-f]{3,4}){1,2}|[a-z]{3,}))(?:\/(#(?:[0-9a-f]{3,4}){1,2}|[a-z]{3,}))?\/?$/i)
26 .match(/^(color|gradient):\/\/\/(?:(#(?:[0-9a-f]{3,4}){1,2}|[a-z]{3,}))(?:\/(#(?:[0-9a-f]{3,4}){1,2}|[a-z]{3,}))?\/?$/i)
27+ readonly property var luminance: {
28+ if (!parsedStyle) return 0.5;
29+ if (parsedStyle[1] === "color") return Utils.Style.luminance(parsedStyle[2]);
30+ else if (parsedStyle[1] === "gradient") return Utils.Style.luminance(parsedStyle[2], parsedStyle[3]);
31+ }
26
32
27 sourceComponent: {
33 sourceComponent: {
28 if (style == "") return null;
34 if (style == "") return null;
tests/qmltests/Components/tst_Background.qml+5−4
@@ -46,10 +46,10 @@ Rectangle {
46
46
47 function test_style_data() {
47 function test_style_data() {
48 return [
48 return [
49− { tag: "empty", style: "" },
49+ { tag: "empty", style: "", luminance: 0.5 },
50− { tag: "solid", style: "color:///black" },
50+ { tag: "solid", style: "color:///black", luminance: 0 },
51− { tag: "gradient", style: "gradient:///black/red" },
51+ { tag: "gradient", style: "gradient:///black/red", luminance: 0.1063 },
52− { tag: "image", style: "/some/path" },
52+ { tag: "image", style: "/some/path", luminance: 0.5 },
53 ];
53 ];
54 }
54 }
55
55
@@ -58,6 +58,7 @@ Rectangle {
58 expectFail("empty", "Empty style should not create a background.");
58 expectFail("empty", "Empty style should not create a background.");
59 loadedSpy.wait();
59 loadedSpy.wait();
60 compare(background.item.objectName, data.tag, "Background should be %1".arg(data.style));
60 compare(background.item.objectName, data.tag, "Background should be %1".arg(data.style));
61+ compare(background.luminance, data.luminance);
61 }
62 }
62
63
63 function test_solid() {
64 function test_solid() {