Add logout button in home screen
[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 Home 1.0
22
23 Item {
24     id: root
25     property int pid: -1
26     signal languageChanged
27     signal disconnect
28
29     Image {
30         anchors.fill: parent
31         anchors.topMargin: -218
32         anchors.bottomMargin: -215
33         source: './images/AGL_HMI_Background_Car-01.png'
34     }
35     Image {
36         id: sign90
37         width: 200
38         height: 200
39         anchors.horizontalCenter: parent.horizontalCenter
40         anchors.top: parent.top
41         anchors.topMargin: 20
42         source: './images/B14-90.png'
43         visible: false
44     }
45     Image {
46         id: flagLanguage
47         scale: 0.7
48         anchors.left: parent.left
49         anchors.leftMargin: 20
50         anchors.top: parent.top
51         anchors.topMargin: 10
52         source: './images/us_flag.png'
53         visible: true
54     }
55     Image {
56         id: visa
57         width: 200
58         height: 124
59         anchors.right: parent.right
60         anchors.rightMargin: 20
61         anchors.top: parent.top
62         anchors.topMargin: 20
63         source: './images/visa.png'
64         visible: false
65         Label {
66             id: cardNumber
67             anchors.top: parent.bottom
68             anchors.topMargin: 10
69             anchors.horizontalCenter: parent.horizontalCenter
70             horizontalAlignment:  Text.AlignHCenter
71             color: "white"
72             text: "111"
73             font.pixelSize: 20
74             font.family: "Roboto"
75         }
76     }
77     Item {
78         id: hello
79         anchors.horizontalCenter: parent.horizontalCenter
80         anchors.bottom: parent.bottom
81         anchors.bottomMargin: 40
82         visible: true
83         Text {
84             id: helloText
85             anchors.centerIn: parent
86             color: 'white'
87             text: 'No Authenticated User'
88             font.pixelSize: 40
89             font.family: 'Roboto'
90             SequentialAnimation on font.letterSpacing {
91                 id: animation1
92                 loops: 1;
93                 NumberAnimation { from: 0; to: 50; easing.type: Easing.InQuad; duration: 3000 }
94                 running: false
95                 onRunningChanged: {
96                     if(running) {
97                         hello.visible = true
98                     } else {
99                         helloText.opacity = 1
100                         helloText.font.letterSpacing = 0
101                     }
102                 }
103             }
104
105             SequentialAnimation on opacity {
106                 id: animation2
107                 loops: 1;
108                 running: false
109                 NumberAnimation { from: 1; to: 0; duration: 2600 }
110                 PauseAnimation { duration: 400 }
111             }
112         }
113     }
114     function showHello(helloString) {
115         helloText.text = helloString
116         animation1.running = true;
117         animation2.running = true;
118     }
119
120     function showSign90(show) {
121         sign90.visible = show
122     }
123
124     function showVisa(show, num) {
125         visa.visible = show
126         cardNumber.text = num;
127     }
128     function changeFlag(flagImage) {
129         flagLanguage.source = flagImage
130     }
131
132     GridView {
133         anchors.centerIn: parent
134         width: cellHeight * 3
135         height: cellHeight * 3
136         cellWidth: 320
137         cellHeight: 320
138
139         model: ApplicationModel {}
140         delegate: MouseArea {
141             width: 320
142             height: 320
143             Image {
144                 id: appImage
145                 anchors.fill: parent
146                 source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
147                 Label {
148                     id: labelName
149                     anchors.horizontalCenter: parent.horizontalCenter
150                     horizontalAlignment: Text.AlignHCenter
151                     y: 257
152                     font.pixelSize: 32
153                     font.family: "Roboto"
154                     color: "white"
155                     text: '%1'.arg(model.name)
156                     function myChangeLanguage() {
157                         text = '%1'.arg(model.name)
158                         appImage.source = './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
159                     }
160                     Component.onCompleted: {
161                         root.languageChanged.connect(myChangeLanguage)
162                     }
163                 }
164             }
165             onClicked: {
166                 console.log("app is ", model.id)
167                 pid = launcher.launch(model.id)
168                 if (1 < pid) {
169                     layoutHandler.makeMeVisible(pid)
170
171                     applicationArea.visible = true
172                     appLauncherAreaLauncher.visible = false
173                     layoutHandler.showAppLayer(pid)
174                 }
175                 else {
176                     console.warn("app cannot be launched!")
177                 }
178             }
179         }
180     }
181     Image {
182         id: logout
183         width: sourceSize.width
184         height: sourceSize.height
185         anchors.bottom: parent.bottom
186         anchors.right: parent.right
187         anchors.bottomMargin: 10
188         anchors.rightMargin: 20
189         source: './images/Logout-01.png'
190         visible: true
191         MouseArea {
192             anchors.fill: parent
193             onClicked: {
194                 rotateLogout.start()
195                 disconnect()
196                 helloText.text= 'No Authenticated User'
197
198             }
199         }
200         RotationAnimator {
201             id: rotateLogout
202             target: logout;
203             from: 0;
204             to: 360;
205             loops: 1
206             duration: 500
207             running: false
208         }
209     }
210 }