on 08bf9db help sign in
unity8/qml/Components/Background.qml
77 lines 2.1 kB history raw
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 */
17import QtQuick 2.0
19Loader {
20 id: root
21 anchors.fill: parent
23 property url style
24 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)
27 sourceComponent: {
28 if (style == "") return null;
29 if (!parsedStyle) return image;
30 if (parsedStyle[1] === "color") return solid
31 if (parsedStyle[1] === "gradient") return gradient
32 }
34 onLoaded: if (item.hasOwnProperty("parsedStyle")) {
35 item.parsedStyle = Qt.binding(function() { return root.parsedStyle } );
36 }
38 Component {
39 id: solid
41 Rectangle {
42 objectName: "solid"
44 property var parsedStyle
46 color: parsedStyle ? parsedStyle[2] : "#ffffff"
47 }
48 }
50 Component {
51 id: gradient
53 Rectangle {
54 objectName: "gradient"
56 property var parsedStyle
58 gradient: Gradient {
59 GradientStop { position: 0; color: parsedStyle ? parsedStyle[2] : "#000000" }
60 GradientStop { position: 1; color: parsedStyle ? parsedStyle[3] : "#000000" }
61 }
62 }
63 }
65 Component {
66 id: image
68 Image {
69 objectName: "image"
71 source: width > 0 && height > 0 && root.style
73 sourceSize.width: width
74 sourceSize.height: height
75 }
76 }