Add sample qml application
[staging/HomeScreen.git] / sample-qml / imports / components / HexSwitch.qml
1 /* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved.
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 import QtQuick 2.0
8 import QtGraphicalEffects 1.0
9
10 Item {
11     width: 170 * height / 80
12     height: 80
13
14     property bool value
15     property bool showLabels: false
16
17     Image {
18         anchors.fill: parent
19         source: "../../images/switchplate_" + (value ? "on" : "off") + ".png"
20     }
21
22     Item {
23         id: shadowTarget
24         x: value ? parent.width * 0.375 : -11
25         width: parent.width * 0.7
26         height: parent.height
27
28         Image {
29             id: control
30             anchors.centerIn: parent
31             width: parent.height * 0.9
32             fillMode: Image.PreserveAspectFit
33             source: "../../images/switchcontrol.png"
34         }
35     }
36
37     DropShadow {
38         anchors.fill: shadowTarget
39         cached: true
40         horizontalOffset: parent.height * 0.05
41         verticalOffset: parent.height * 0.05
42         radius: 16
43         samples: 32
44         color: Qt.rgba(0, 0, 0, 0.35)
45         smooth: true
46         source: shadowTarget
47     }
48
49     Text {
50         text: qsTr("OFF")
51         font.family: "Source Sans Pro"
52         anchors.right: parent.left
53         anchors.rightMargin: 30
54         anchors.verticalCenter: parent.verticalCenter
55         font.pointSize: 25
56         font.letterSpacing: -0.5
57         font.weight: value ? Font.Normal : Font.Bold
58         color: value ? "#C4C4C4" : "#FE9C00"
59         visible: showLabels
60     }
61
62     Text {
63         id: onText
64         text: qsTr("ON")
65         font.family: "Source Sans Pro"
66         anchors.left: parent.right
67         anchors.leftMargin: 30
68         font.pointSize: 25
69         anchors.verticalCenter: parent.verticalCenter
70         font.letterSpacing: -0.5
71         font.weight: value ? Font.Bold : Font.Normal
72         color: value ? "#59FF00" : "#C4C4C4"
73         visible: showLabels
74     }
75
76     MouseArea {
77         anchors.fill: parent
78         onClicked: value = !value
79     }
80 }