QML/Hvac: Do not hard-code window size
[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 QtQuick.Window 2.11
21 import AGL.Demo.Controls 1.0
22 import Translator 1.0
23 import 'api' as API
24
25 ApplicationWindow {
26     id: root
27
28     width: container.width * container.scale
29     height: container.height * container.scale
30
31         Translator {
32                 id: translator
33                 language: binding.language
34         }
35
36         API.Binding {
37                 id: binding
38                 url: bindingAddress
39                 onFanSpeedChanged: fanSpeedSlider.value = fanSpeed
40                 onLanguageChanged: translator.language = language
41         }
42
43     Item {
44         id: container
45         anchors.centerIn: parent
46         width: Screen.width
47         height: Screen.height
48         scale: 1
49
50         ColumnLayout {
51                 anchors.fill: parent
52                 anchors.topMargin: width / 10
53                 anchors.bottomMargin: width / 10
54                 RowLayout {
55                         Layout.fillHeight: true
56                         Layout.alignment: Qt.AlignHCenter
57                         Image {
58                                 source: './images/HMI_HVAC_Fan_Icon.svg'
59                         }
60                         Item {
61                                 width: container.width * 0.8
62                                 Slider {
63                                         id: fanSpeedSlider
64                                         anchors.left: parent.left
65                                         anchors.right: parent.right
66                                         anchors.verticalCenter: parent.verticalCenter
67                                         from: 0.0
68                                         to: 255.0
69                                         stepSize: 1.0
70                                         onValueChanged: {
71                                                 binding.fanSpeed = value
72                                         }
73                                 }
74                                 Label {
75                                         anchors.left: fanSpeedSlider.left
76                                         anchors.top: fanSpeedSlider.bottom
77                                         font.pixelSize: 32
78                                         text: translator.translate(qsTr('FAN SPEED'), translator.language)
79                                 }
80                         }
81                 }
82                 RowLayout {
83                         Layout.fillHeight: true
84                         Layout.fillWidth: true
85                         Layout.alignment: Layout.Center
86                         spacing: 20
87                         ColumnLayout {
88                                 Layout.fillWidth: true
89                                 spacing: 20
90                                 SeatHeatButton {
91                                         id: leftSeat
92                                         side: 'Left'
93                                 }
94                                 HeatDegree {
95                                         onCurrentItemChanged: {
96                                                 console.log("Left Temp changed",degree)
97                                                 binding.leftTemperature = degree
98                                         }
99                                 }
100                         }
101                         ColumnLayout {
102                                 Layout.fillWidth: true
103                                 spacing: 20
104                                 ToggleButton {
105                                         onImage: './images/HMI_HVAC_Active.svg'
106                                         offImage: './images/HMI_HVAC_Inactive.svg'
107                                         Label {
108                                                 anchors.centerIn: parent
109                                                 color: parent.checked ? '#00ADDC' : '#848286'
110                                                 text: translator.translate(qsTr('A/C'), translator.language)
111                                                 font.pixelSize: parent.height / 3
112                                         }
113                                         onCheckedChanged: {
114                                                 console.debug('A/C', checked)
115                                         }
116                                 }
117                                 ToggleButton {
118                                         onImage: './images/HMI_HVAC_Active.svg'
119                                         offImage: './images/HMI_HVAC_Inactive.svg'
120                                         Label {
121                                                 anchors.centerIn: parent
122                                                 color: parent.checked ? '#00ADDC' : '#848286'
123                                                 text: translator.translate(qsTr('AUTO'), translator.language)
124                                                 font.pixelSize: parent.height / 3
125                                         }
126                                         onCheckedChanged: {
127                                                 console.debug('AUTO', checked)
128                                         }
129                                 }
130                                 ToggleButton {
131                                         onImage: './images/HMI_HVAC_Circulation_Active.svg'
132                                         offImage: './images/HMI_HVAC_Circulation_Inactive.svg'
133                                         onCheckedChanged: {
134                                                 console.debug('Circulation', checked)
135                                         }
136                                 }
137                         }
138
139                         ColumnLayout {
140                                 Layout.fillWidth: true
141                                 spacing: 20
142                                 SeatHeatButton {
143                                         id: rightSeat
144                                         side: 'Right'
145                                 }
146                                 HeatDegree {
147                                         onCurrentItemChanged: {
148                                                 console.log("Right Temp changed",degree)
149                                                 binding.rightTemperature = degree
150                                         }
151                                 }
152                         }
153                 }
154
155                 RowLayout {
156                         Layout.fillHeight: true
157                         Layout.alignment: Qt.AlignHCenter
158                         spacing: root.width / 20
159                         Repeater {
160                                 model: ['AirDown', 'AirUp', 'AirRight', 'Rear', 'Front']
161                                 ToggleButton {
162                                         onImage: './images/HMI_HVAC_%1_Active.svg'.arg(model.modelData)
163                                         offImage: './images/HMI_HVAC_%1_Inactive.svg'.arg(model.modelData)
164                                         onCheckedChanged: {
165                                                 console.debug(model.modelData, checked)
166                                         }
167                                 }
168                         }
169                 }
170         }
171 }
172 }