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         interactive: false
139
140         model: ApplicationModel {}
141         delegate: MouseArea {
142             width: 320
143             height: 320
144             Image {
145                 id: appImage
146                 anchors.fill: parent
147                 source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
148                 Label {
149                     id: labelName
150                     anchors.horizontalCenter: parent.horizontalCenter
151                     horizontalAlignment: Text.AlignHCenter
152                     y: 257
153                     font.pixelSize: 32
154                     font.family: "Roboto"
155                     color: "white"
156                     text: '%1'.arg(model.name)
157                     function myChangeLanguage() {
158                         text = '%1'.arg(model.name)
159                         appImage.source = './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
160                     }
161                     Component.onCompleted: {
162                         root.languageChanged.connect(myChangeLanguage)
163                     }
164                 }
165             }
166             onClicked: {
167                 console.log("app is ", model.id)
168                 pid = launcher.launch(model.id)
169                 if (1 < pid) {
170                     layoutHandler.makeMeVisible(pid)
171
172                     applicationArea.visible = true
173                     appLauncherAreaLauncher.visible = false
174                     layoutHandler.showAppLayer(pid)
175                 }
176                 else {
177                     console.warn("app cannot be launched!")
178                 }
179             }
180         }
181     }
182     Image {
183         id: logout
184         width: sourceSize.width
185         height: sourceSize.height
186         anchors.bottom: parent.bottom
187         anchors.right: parent.right
188         anchors.bottomMargin: 10
189         anchors.rightMargin: 20
190         source: './images/Logout-01.png'
191         visible: true
192         MouseArea {
193             anchors.fill: parent
194             onClicked: {
195                 rotateLogout.start()
196                 disconnect()
197                 helloText.text= 'No Authenticated User'
198
199             }
200         }
201         RotationAnimator {
202             id: rotateLogout
203             target: logout;
204             from: 0;
205             to: 360;
206             loops: 1
207             duration: 500
208             running: false
209         }
210     }
211 }