423c24c70b1a75115573832b5b85e00f63b56635
[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) {
123         sign90.visible = show
124     }
125
126     function showVisa(show, num) {
127         visa.visible = show
128         cardNumber.text = num;
129     }
130     function changeFlag(flagImage) {
131         flagLanguage.source = flagImage
132     }
133     function setUser(type, auts) {
134         if(type === '') {
135             authorisations.visible = false
136         } else {
137             authorisations.visible = true
138             labelUserType.text = type
139             myModel.clear()
140             for (var i=0; i<auts.length; i++) {
141                 if(auts[i] !== '')
142                     myModel.append({"name": auts[i]})
143             }
144         }
145     }
146
147     GridView {
148         anchors.centerIn: parent
149         width: cellHeight * 3
150         height: cellHeight * 3
151         cellWidth: 320
152         cellHeight: 320
153
154         model: ApplicationModel {}
155         delegate: MouseArea {
156             width: 320
157             height: 320
158             Image {
159                 id: appImage
160                 anchors.fill: parent
161                 source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
162                 Label {
163                     id: labelName
164                     anchors.horizontalCenter: parent.horizontalCenter
165                     horizontalAlignment: Text.AlignHCenter
166                     y: 257
167                     font.pixelSize: 32
168                     font.family: "Roboto"
169                     color: "white"
170                     text: '%1'.arg(model.name)
171                     function myChangeLanguage() {
172                         text = '%1'.arg(model.name)
173                         appImage.source = './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
174                     }
175                     Component.onCompleted: {
176                         root.languageChanged.connect(myChangeLanguage)
177                     }
178                 }
179             }
180             onClicked: {
181                 console.log("app is ", model.id)
182                 pid = launcher.launch(model.id)
183                 if (1 < pid) {
184                     layoutHandler.makeMeVisible(pid)
185
186                     applicationArea.visible = true
187                     appLauncherAreaLauncher.visible = false
188                     layoutHandler.showAppLayer(pid)
189                 }
190                 else {
191                     console.warn("app cannot be launched!")
192                 }
193             }
194         }
195     }
196     ListModel {
197         id: myModel
198         ListElement {
199             name: 'Install App'
200         }
201         ListElement {
202             name: 'Open Trunk'
203         }
204         ListElement {
205             name: 'Update Software'
206         }
207         ListElement {
208             name: 'View Online'
209         }
210     }
211     Item {
212         id: authorisations
213         anchors.fill: parent
214         visible: false
215         GridLayout {
216             id: gridAut
217             columns: 2
218             anchors.bottom: parent.bottom
219             anchors.left: parent.left
220             anchors.bottomMargin: 50
221             anchors.leftMargin: 20
222             Repeater {
223                 model: myModel
224                 Image {
225                     source: './images/' + model.name + '.png'
226                     width: sourceSize.width
227                     height: sourceSize.height
228                     visible: true
229                 }
230             }
231         }
232         Label {
233             id: labelUserType
234             anchors.bottom: gridAut.top
235             anchors.bottomMargin: 10
236             anchors.left: gridAut.left
237             color: "white"
238             text: "Owner"
239             font.pixelSize: 30
240             font.family: "Roboto"
241         }
242     }
243
244     Image {
245         id: logout
246         width: sourceSize.width
247         height: sourceSize.height
248         anchors.bottom: parent.bottom
249         anchors.right: parent.right
250         anchors.bottomMargin: 10
251         anchors.rightMargin: 20
252         source: './images/Logout-01.png'
253         visible: true
254         MouseArea {
255             anchors.fill: parent
256             onClicked: {
257                 rotateLogout.start()
258                 disconnect()
259                 helloText.text= 'No Authenticated User'
260
261             }
262         }
263         RotationAnimator {
264             id: rotateLogout
265             target: logout;
266             from: 0;
267             to: 360;
268             loops: 1
269             duration: 500
270             running: false
271         }
272     }
273 }