Changing LED colour gradient according to temperature sliders
[apps/hvac.git] / app / HVAC.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import QtQuick 2.6
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20 import AGL.Demo.Controls 1.0
21 import Translator 1.0
22 import 'api' as API
23
24 ApplicationWindow {
25     id: root
26
27         Translator {
28                 id: translator
29                 language: binding.language
30         }
31
32         API.Binding {
33                 id: binding
34                 url: bindingAddress
35                 onFanSpeedChanged: fanSpeedSlider.value = fanSpeed
36                 onLanguageChanged: translator.language = language
37         }
38
39         ColumnLayout {
40                 anchors.fill: parent
41                 anchors.topMargin: width / 10
42                 anchors.bottomMargin: width / 10
43                 RowLayout {
44                         Layout.fillHeight: true
45                         Layout.alignment: Qt.AlignHCenter
46                         Image {
47                                 source: './images/HMI_HVAC_Fan_Icon.svg'
48                         }
49                         Item {
50                                 width: root.width * 0.8
51                                 Slider {
52                                         id: fanSpeedSlider
53                                         anchors.left: parent.left
54                                         anchors.right: parent.right
55                                         anchors.verticalCenter: parent.verticalCenter
56                                         from: 0.0
57                                         to: 255.0
58                                         stepSize: 1.0
59                                         onValueChanged: {
60                                                 binding.fanSpeed = value
61                                         }
62                                 }
63                                 Label {
64                                         anchors.left: fanSpeedSlider.left
65                                         anchors.top: fanSpeedSlider.bottom
66                                         font.pixelSize: 32
67                                         text: translator.translate(qsTr('FAN SPEED'), translator.language)
68                                 }
69                         }
70                 }
71                 RowLayout {
72                         Layout.fillHeight: true
73                         Layout.fillWidth: true
74                         Layout.alignment: Layout.Center
75                         spacing: 20
76                         ColumnLayout {
77                                 Layout.fillWidth: true
78                                 spacing: 20
79                                 SeatHeatButton {
80                                         id: leftSeat
81                                         side: 'Left'
82                                 }
83                                 HeatDegree {
84                                         onCurrentItemChanged: {
85                                                 console.log("Left Temp changed",degree)
86                                                 binding.leftTemperature = degree
87                                         }
88                                 }
89                         }
90                         ColumnLayout {
91                                 Layout.fillWidth: true
92                                 spacing: 20
93                                 ToggleButton {
94                                         onImage: './images/HMI_HVAC_Active.svg'
95                                         offImage: './images/HMI_HVAC_Inactive.svg'
96                                         Label {
97                                                 anchors.centerIn: parent
98                                                 color: parent.checked ? '#00ADDC' : '#848286'
99                                                 text: translator.translate(qsTr('A/C'), translator.language)
100                                                 font.pixelSize: parent.height / 3
101                                         }
102                                         onCheckedChanged: {
103                                                 console.debug('A/C', checked)
104                                         }
105                                 }
106                                 ToggleButton {
107                                         onImage: './images/HMI_HVAC_Active.svg'
108                                         offImage: './images/HMI_HVAC_Inactive.svg'
109                                         Label {
110                                                 anchors.centerIn: parent
111                                                 color: parent.checked ? '#00ADDC' : '#848286'
112                                                 text: translator.translate(qsTr('AUTO'), translator.language)
113                                                 font.pixelSize: parent.height / 3
114                                         }
115                                         onCheckedChanged: {
116                                                 console.debug('AUTO', checked)
117                                         }
118                                 }
119                                 ToggleButton {
120                                         onImage: './images/HMI_HVAC_Circulation_Active.svg'
121                                         offImage: './images/HMI_HVAC_Circulation_Inactive.svg'
122                                         onCheckedChanged: {
123                                                 console.debug('Circulation', checked)
124                                         }
125                                 }
126                         }
127
128                         ColumnLayout {
129                                 Layout.fillWidth: true
130                                 spacing: 20
131                                 SeatHeatButton {
132                                         id: rightSeat
133                                         side: 'Right'
134                                 }
135                                 HeatDegree {
136                                         onCurrentItemChanged: {
137                                                 console.log("Right Temp changed",degree)
138                                                 binding.rightTemperature = degree
139                                         }
140                                 }
141                         }
142                 }
143
144                 RowLayout {
145                         Layout.fillHeight: true
146                         Layout.alignment: Qt.AlignHCenter
147                         spacing: root.width / 20
148                         Repeater {
149                                 model: ['AirDown', 'AirUp', 'AirRight', 'Rear', 'Front']
150                                 ToggleButton {
151                                         onImage: './images/HMI_HVAC_%1_Active.svg'.arg(model.modelData)
152                                         offImage: './images/HMI_HVAC_%1_Inactive.svg'.arg(model.modelData)
153                                         onCheckedChanged: {
154                                                 console.debug(model.modelData, checked)
155                                         }
156                                 }
157                         }
158                 }
159         }
160 }