Add sample qml application
[staging/HomeScreen.git] / sample-qml / apps / HVAC_org / TempSlider.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 utils 1.0
9 import "models"
10
11 Item {
12     id: root
13     width: 64
14     height: 716
15
16     property real value: HVACModel[propertyName]
17     property string propertyName: side + "Temperature"
18     property string side: "left"
19
20     function setProperty(v) {
21         HVACModel[propertyName] = Math.min(Math.max(v, 0), 1)
22     }
23
24     Rectangle {
25         anchors.fill: parent
26         color: "#4a53b5ce"
27     }
28
29     Rectangle {
30         width: parent.width
31         height: value * parent.height
32         color: Style.orangeViv
33         anchors.bottom: parent.bottom
34     }
35
36     Rectangle {
37         x: side === "left" ? parent.width + 30 : -30
38         width: 2
39         height: value * parent.height
40         anchors.bottom: parent.bottom
41         color: Style.orangeLt
42
43         Image {
44             width: 30
45             height: width
46             anchors.verticalCenter: parent.top
47             anchors.horizontalCenter: parent.horizontalCenter
48             source: "images/drag_knob.svg"
49         }
50     }
51
52     MouseArea {
53         x: side === "left" ? 0 : -45
54         width: parent.width + 45
55         height: parent.height
56
57         onPressed: setProperty(1 - mouse.y / height)
58         onPositionChanged: setProperty(1 - mouse.y / height)
59     }
60 }
61