on xenial help sign in
Add luminance property to Background.qml
commitf58b35fdb565d2443fa410c0fbfc63ce8eacf07f authorMichał Sawicz <michal.sawicz@canonical.com> dateThu 14 Aug 2014, 13:43 (12 years ago) parentf4a7f03
2 files changed+11−4
qml/Components/Background.qml+6 tests/qmltests/Components/tst_Background.qml+5−4
qml/Components/Background.qml+6
@@ -15,6 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18+import Utils 0.1 as Utils
1819
1920Loader {
2021 id: root
@@ -23,6 +24,11 @@ Loader {
2324 property url style
2425 readonly property var parsedStyle: String(style)
2526 .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+ }
2632
2733 sourceComponent: {
2834 if (style == "") return null;
tests/qmltests/Components/tst_Background.qml+5−4
@@ -46,10 +46,10 @@ Rectangle {
4646
4747 function test_style_data() {
4848 return [
49− { tag: "empty", style: "" },
50− { tag: "solid", style: "color:///black" },
51− { tag: "gradient", style: "gradient:///black/red" },
52− { tag: "image", style: "/some/path" },
49+ { tag: "empty", style: "", luminance: 0.5 },
50+ { tag: "solid", style: "color:///black", luminance: 0 },
51+ { tag: "gradient", style: "gradient:///black/red", luminance: 0.1063 },
52+ { tag: "image", style: "/some/path", luminance: 0.5 },
5353 ];
5454 }
5555
@@ -58,6 +58,7 @@ Rectangle {
5858 expectFail("empty", "Empty style should not create a background.");
5959 loadedSpy.wait();
6060 compare(background.item.objectName, data.tag, "Background should be %1".arg(data.style));
61+ compare(background.luminance, data.luminance);
6162 }
6263
6364 function test_solid() {