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