Add sample qml application
[staging/HomeScreen.git] / sample-qml / apps / HVAC / TemperatureWheel.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 "models"
9
10 Rectangle {
11     width: 237
12     height: 350
13     color: "#aa000000"
14
15     property string side: "left"
16     property string propertyName: side + "Temperature"
17     property real value: HVACModel[propertyName]
18
19     ListView {
20         anchors.fill: parent
21         clip: true
22         snapMode: ListView.SnapToItem
23         model: TemperatureModel
24         header: Item { height: 120 }
25         footer: Item { height: 120 }
26         currentIndex: Math.min(value * count, count - 1)
27         flickDeceleration: 5000
28         onContentYChanged: {
29             if (dragging || flicking) {
30                 var item = Math.round((contentY + 120) / 110)
31                 item = Math.max(Math.min(item, count - 1), 0)
32                 if (item != currentIndex) {
33                     var temperature = item / (count - 1)
34                     HVACModel[propertyName] = temperature
35                 }
36             }
37         }
38         highlightMoveDuration: 100
39         interactive: true
40
41         delegate: Text {
42             x: side === "right" ? 40 : 10
43             height: 110
44             verticalAlignment: Text.AlignVCenter
45             color: "white"
46             font.pixelSize: 70
47             text: model.text
48         }
49     }
50
51     Image {
52         mirror: side === "left"
53         source: "./images/right_number_cover.svg"
54         anchors.fill: parent
55     }
56 }