Modification for dynamic speed sign (not activated)
[staging/HomeScreen.git] / HomeScreen / qml / Home.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 import QtQuick 2.2
19 import QtQuick.Layouts 1.1
20 import QtQuick.Controls 1.0
21 import QtQuick.Controls 1.4
22 import QtQuick.Controls.Styles 1.4
23 import Home 1.0
24
25 Item {
26     id: root
27     property int pid: -1
28     signal languageChanged
29     signal disconnect
30
31     Image {
32         anchors.fill: parent
33         anchors.topMargin: -218
34         anchors.bottomMargin: -215
35         source: './images/AGL_HMI_Background_Car-01.png'
36     }
37     Image {
38         id: sign90
39         width: 200
40         height: 200
41         anchors.horizontalCenter: parent.horizontalCenter
42         anchors.top: parent.top
43         anchors.topMargin: 20
44         source: './images/sign.png'
45         visible: false
46         Label {
47             id: speedLimit
48             anchors.horizontalCenter: parent.horizontalCenter
49             anchors.verticalCenter: parent.verticalCenter
50             horizontalAlignment:  Text.AlignHCenter
51             color: "black"
52             text: "50"
53             font.pixelSize: 90
54             font.family: "Roboto"
55             font.bold: true
56             visible: false
57         }
58     }
59     Image {
60         id: flagLanguage
61         scale: 0.7
62         anchors.left: parent.left
63         anchors.leftMargin: 20
64         anchors.top: parent.top
65         anchors.topMargin: 10
66         source: './images/us_flag.png'
67         visible: true
68     }
69     Image {
70         id: visa
71         width: 200
72         height: 124
73         anchors.right: parent.right
74         anchors.rightMargin: 20
75         anchors.top: parent.top
76         anchors.topMargin: 20
77         source: './images/visa.png'
78         visible: false
79         Label {
80             id: cardNumber
81             anchors.top: parent.bottom
82             anchors.topMargin: 10
83             anchors.horizontalCenter: parent.horizontalCenter
84             horizontalAlignment:  Text.AlignHCenter
85             color: "white"
86             text: "111"
87             font.pixelSize: 20
88             font.family: "Roboto"
89         }
90     }
91     Item {
92         id: hello
93         anchors.horizontalCenter: parent.horizontalCenter
94         anchors.bottom: parent.bottom
95         anchors.bottomMargin: 40
96         visible: true
97         Text {
98             id: helloText
99             anchors.centerIn: parent
100             color: 'white'
101             text: 'No Authenticated User'
102             font.pixelSize: 40
103             font.family: 'Roboto'
104             SequentialAnimation on font.letterSpacing {
105                 id: animation1
106                 loops: 1;
107                 NumberAnimation { from: 0; to: 50; easing.type: Easing.InQuad; duration: 3000 }
108                 running: false
109                 onRunningChanged: {
110                     if(running) {
111                         hello.visible = true
112                     } else {
113                         helloText.opacity = 1
114                         helloText.font.letterSpacing = 0
115                     }
116                 }
117             }
118
119             SequentialAnimation on opacity {
120                 id: animation2
121                 loops: 1;
122                 running: false
123                 NumberAnimation { from: 1; to: 0; duration: 2600 }
124                 PauseAnimation { duration: 400 }
125             }
126         }
127     }
128     function showHello(helloString) {
129         helloText.text = helloString
130         animation1.running = true;
131         animation2.running = true;
132     }
133
134     function showSign90(show, speed, unit) {
135         sign90.visible = show
136         if(show) {
137             if(speed.length > 2)
138                 speedLimit.font.pixelSize = 60
139             else
140                 speedLimit.font.pixelSize = 90
141             speedLimit.text = speed
142         }
143         sign90.source = './images/B14-90.png'
144         speedLimit.visible = false
145     }
146
147     function showVisa(show, num) {
148         visa.visible = show
149         cardNumber.text = num;
150     }
151     function changeFlag(flagImage) {
152         flagLanguage.source = flagImage
153     }
154     function setUser(type, auts) {
155         if(type === '') {
156             authorisations.visible = false
157         } else {
158             authorisations.visible = true
159             labelUserType.text = type
160             myModel.clear()
161             for (var i=0; i<auts.length; i++) {
162                 if(auts[i] !== '')
163                     myModel.append({"name": auts[i]})
164             }
165         }
166     }
167
168     GridView {
169         anchors.centerIn: parent
170         width: cellHeight * 3
171         height: cellHeight * 3
172         cellWidth: 320
173         cellHeight: 320
174
175         model: ApplicationModel {}
176         delegate: MouseArea {
177             width: 320
178             height: 320
179             Image {
180                 id: appImage
181                 anchors.fill: parent
182                 source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
183                 Label {
184                     id: labelName
185                     anchors.horizontalCenter: parent.horizontalCenter
186                     horizontalAlignment: Text.AlignHCenter
187                     y: 257
188                     font.pixelSize: 32
189                     font.family: "Roboto"
190                     color: "white"
191                     text: '%1'.arg(model.name)
192                     function myChangeLanguage() {
193                         text = '%1'.arg(model.name)
194                         appImage.source = './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
195                     }
196                     Component.onCompleted: {
197                         root.languageChanged.connect(myChangeLanguage)
198                     }
199                 }
200             }
201             onClicked: {
202                 console.log("app is ", model.id)
203                 pid = launcher.launch(model.id)
204                 if (1 < pid) {
205                     layoutHandler.makeMeVisible(pid)
206
207                     applicationArea.visible = true
208                     appLauncherAreaLauncher.visible = false
209                     layoutHandler.showAppLayer(pid)
210                 }
211                 else {
212                     console.warn("app cannot be launched!")
213                 }
214             }
215         }
216     }
217     ListModel {
218         id: myModel
219         ListElement {
220             name: 'Install App'
221         }
222         ListElement {
223             name: 'Open Trunk'
224         }
225         ListElement {
226             name: 'Update Software'
227         }
228         ListElement {
229             name: 'View Online'
230         }
231     }
232     Item {
233         id: authorisations
234         anchors.fill: parent
235         visible: false
236         GridLayout {
237             id: gridAut
238             columns: 2
239             anchors.bottom: parent.bottom
240             anchors.left: parent.left
241             anchors.bottomMargin: 50
242             anchors.leftMargin: 20
243             Repeater {
244                 model: myModel
245                 Image {
246                     source: './images/' + model.name + '.png'
247                     width: sourceSize.width
248                     height: sourceSize.height
249                     visible: true
250                 }
251             }
252         }
253         Label {
254             id: labelUserType
255             anchors.bottom: gridAut.top
256             anchors.bottomMargin: 10
257             anchors.left: gridAut.left
258             color: "white"
259             text: "Owner"
260             font.pixelSize: 30
261             font.family: "Roboto"
262         }
263     }
264
265     Image {
266         id: logout
267         width: sourceSize.width
268         height: sourceSize.height
269         anchors.bottom: parent.bottom
270         anchors.right: parent.right
271         anchors.bottomMargin: 10
272         anchors.rightMargin: 20
273         source: './images/Logout-01.png'
274         visible: true
275         MouseArea {
276             anchors.fill: parent
277             onClicked: {
278                 rotateLogout.start()
279                 disconnect()
280                 helloText.text= 'No Authenticated User'
281
282             }
283         }
284         RotationAnimator {
285             id: rotateLogout
286             target: logout;
287             from: 0;
288             to: 360;
289             loops: 1
290             duration: 500
291             running: false
292         }
293     }
294 }