aboutsummaryrefslogtreecommitdiffstats
path: root/qml/TemperatureWheel.qml
blob: 7a59dde15ecc5ad921e36bff99bf5932b40c6ec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import QtQuick 2.0
import "models"

Rectangle {
    width: 237
    height: 350
    color: "#aa000000"

    property string side: "left"
    property string propertyName: side + "Temperature"
    property real value: HVACModel[propertyName]

    ListView {
        anchors.fill: parent
        clip: true
        snapMode: ListView.SnapToItem
        model: TemperatureModel
        header: Item { height: 120 }
        footer: Item { height: 120 }
        currentIndex: Math.min(value * count, count - 1)
        flickDeceleration: 5000
        onContentYChanged: {
            if (dragging || flicking) {
                var item = Math.round((contentY + 120) / 110)
                item = Math.max(Math.min(item, count - 1), 0)
                if (item != currentIndex) {
                    var temperature = item / (count - 1)
                    HVACModel[propertyName] = temperature
                }
            }
        }
        highlightMoveDuration: 100
        interactive: true

        delegate: Text {
            x: side === "right" ? 40 : 10
            height: 110
            verticalAlignment: Text.AlignVCenter
            color: "white"
            font.pixelSize: 70
            text: model.text
        }
    }

    Image {
        mirror: side === "left"
        source: "./images/right_number_cover.svg"
        anchors.fill: parent
    }
}