New speed sign according to language
[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/B14-90.png'
45         visible: false
46     }
47     Image {
48         id: flagLanguage
49         scale: 0.7
50         anchors.left: parent.left
51         anchors.leftMargin: 20
52         anchors.top: parent.top
53         anchors.topMargin: 10
54         source: './images/us_flag.png'
55         visible: true
56     }
57     Image {
58         id: visa
59         width: 200
60         height: 124
61         anchors.right: parent.right
62         anchors.rightMargin: 20
63         anchors.top: parent.top
64         anchors.topMargin: 20
65         source: './images/visa.png'
66         visible: false
67         Label {
68             id: cardNumber
69             anchors.top: parent.bottom
70             anchors.topMargin: 10
71             anchors.horizontalCenter: parent.horizontalCenter
72             horizontalAlignment:  Text.AlignHCenter
73             color: "white"
74             text: "111"
75             font.pixelSize: 20
76             font.family: "Roboto"
77         }
78     }
79     Item {
80         id: hello
81         anchors.horizontalCenter: parent.horizontalCenter
82         anchors.bottom: parent.bottom
83         anchors.bottomMargin: 40
84         visible: true
85         Text {
86             id: helloText
87             anchors.centerIn: parent
88             color: 'white'
89             text: 'No Authenticated User'
90             font.pixelSize: 40
91             font.family: 'Roboto'
92             SequentialAnimation on font.letterSpacing {
93                 id: animation1
94                 loops: 1;
95                 NumberAnimation { from: 0; to: 50; easing.type: Easing.InQuad; duration: 3000 }
96                 running: false
97                 onRunningChanged: {
98                     if(running) {
99                         hello.visible = true
100                     } else {
101                         helloText.opacity = 1
102                         helloText.font.letterSpacing = 0
103                     }
104                 }
105             }
106
107             SequentialAnimation on opacity {
108                 id: animation2
109                 loops: 1;
110                 running: false
111                 NumberAnimation { from: 1; to: 0; duration: 2600 }
112                 PauseAnimation { duration: 400 }
113             }
114         }
115     }
116     function showHello(helloString) {
117         helloText.text = helloString
118         animation1.running = true;
119         animation2.running = true;
120     }
121
122     function showSign90(show, lang) {
123         sign90.visible = show
124         if(show) {
125             if(lang === 'fr')
126                 sign90.source = './images/B14-90.png'
127             else
128                 sign90.source = './images/B14-60.png'
129         }
130     }
131
132     function showVisa(show, num) {
133         visa.visible = show
134         cardNumber.text = num;
135     }
136     function changeFlag(flagImage) {
137         flagLanguage.source = flagImage
138     }
139     function setUser(type, auts) {
140         if(type === '') {
141             authorisations.visible = false
142         } else {
143             authorisations.visible = true
144             labelUserType.text = type
145             myModel.clear()
146             for (var i=0; i<auts.length; i++) {
147                 if(auts[i] !== '')
148                     myModel.append({"name": auts[i]})
149             }
150         }
151     }
152
153     GridView {
154         anchors.centerIn: parent
155         width: cellHeight * 3
156         height: cellHeight * 3
157         cellWidth: 320
158         cellHeight: 320
159         interactive: false
160
161         model: ApplicationModel {}
162         delegate: MouseArea {
163             width: 320
164             height: 320
165             Image {
166                 id: appImage
167                 anchors.fill: parent
168                 source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
169                 Label {
170                     id: labelName
171                     anchors.horizontalCenter: parent.horizontalCenter
172                     horizontalAlignment: Text.AlignHCenter
173                     y: 257
174                     font.pixelSize: 32
175                     font.family: "Roboto"
176                     color: "white"
177                     text: '%1'.arg(model.name)
178                     function myChangeLanguage() {
179                         text = '%1'.arg(model.name)
180                         appImage.source = './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
181                     }
182                     Component.onCompleted: {
183                         root.languageChanged.connect(myChangeLanguage)
184                     }
185                 }
186             }
187             onClicked: {
188                 console.log("app is ", model.id)
189                 pid = launcher.launch(model.id)
190                 if (1 < pid) {
191                     layoutHandler.makeMeVisible(pid)
192
193                     applicationArea.visible = true
194                     appLauncherAreaLauncher.visible = false
195                     layoutHandler.showAppLayer(pid)
196                 }
197                 else {
198                     console.warn("app cannot be launched!")
199                 }
200             }
201         }
202     }
203     ListModel {
204         id: myModel
205         ListElement {
206             name: 'Install App'
207         }
208         ListElement {
209             name: 'Open Trunk'
210         }
211         ListElement {
212             name: 'Update Software'
213         }
214         ListElement {
215             name: 'View Online'
216         }
217     }
218     Item {
219         id: authorisations
220         anchors.fill: parent
221         visible: false
222         GridLayout {
223             id: gridAut
224             columns: 2
225             anchors.bottom: parent.bottom
226             anchors.left: parent.left
227             anchors.bottomMargin: 50
228             anchors.leftMargin: 20
229             Repeater {
230                 model: myModel
231                 Image {
232                     source: './images/' + model.name + '.png'
233                     width: sourceSize.width
234                     height: sourceSize.height
235                     visible: true
236                 }
237             }
238         }
239         Label {
240             id: labelUserType
241             anchors.bottom: gridAut.top
242             anchors.bottomMargin: 10
243             anchors.left: gridAut.left
244             color: "white"
245             text: "Owner"
246             font.pixelSize: 30
247             font.family: "Roboto"
248         }
249     }
250
251     Image {
252         id: logout
253         width: sourceSize.width
254         height: sourceSize.height
255         anchors.bottom: parent.bottom
256         anchors.right: parent.right
257         anchors.bottomMargin: 10
258         anchors.rightMargin: 20
259         source: './images/Logout-01.png'
260         visible: true
261         MouseArea {
262             anchors.fill: parent
263             onClicked: {
264                 rotateLogout.start()
265                 disconnect()
266                 helloText.text= 'No Authenticated User'
267
268             }
269         }
270         RotationAnimator {
271             id: rotateLogout
272             target: logout;
273             from: 0;
274             to: 360;
275             loops: 1
276             duration: 500
277             running: false
278         }
279     }
280 }