PoC: Qt Compositor-ized homescreen
[apps/homescreen.git] / homescreen / qml / SystemUI.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016, 2017 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.Window 2.1
20 import QtQuick.Layouts 1.1
21 import QtQuick.Controls 2.1
22 import QtWayland.Compositor 1.0
23 import HomeScreen 1.0
24 import QtGraphicalEffects 1.0
25
26 Window {
27     id: root
28     visible: true
29     flags: Qt.FramelessWindowHint
30     width: container.width * container.scale
31     height: container.height * container.scale
32     title: 'HomeScreen'
33     property alias applicationStack: applicationStack
34
35     property var app2item: new Object
36     property string appLaunching
37
38     Component {
39         id: chrome
40         ShellSurfaceItem {
41             onSurfaceDestroyed: destroy()
42         }
43     }
44
45     function show(shellSurface) {
46         var a2i = root.app2item
47         var item = chrome.createObject(root, {"shellSurface": shellSurface})
48         a2i[appLaunching] = item
49         root.app2item = a2i
50         shellSurface.sendConfigure(Qt.size(applicationStack.width, applicationStack.height), WlShellSurface.NoneEdge)
51         if (applicationStack.depth == 1) {
52             applicationStack.push(item)
53         } else {
54             applicationStack.replace(item)
55         }
56         appLaunching = ''
57     }
58
59     ApplicationLauncher {
60         id: launcher
61
62         function show(app) {
63             if (current === app) return
64             if (app.length > 0) {
65                 if (root.appLaunching.length > 0)
66                     return
67                 if (app2item[app]) {
68                     if (applicationStack.depth == 1) {
69                         applicationStack.push(app2item[app])
70                     } else {
71                         applicationStack.replace(app2item[app])
72                     }
73                     current = app
74                 } else {
75                     root.appLaunching = app
76                     if (launch(app) < 0) {
77                         root.appLaunching = ''
78                     }
79                 }
80             } else if (applicationStack.depth > 1) {
81                 applicationStack.pop()
82                 current = ''
83             }
84         }
85     }
86
87     Component {
88         id: home
89         Home {
90             width: parent.width
91             height: parent.height
92         }
93     }
94
95     Transition {
96         id: inTransition
97         NumberAnimation {
98             properties: "opacity, scale"
99             from: 0
100             to:1
101             duration: 250
102         }
103     }
104     Transition {
105         id: outTransition
106         NumberAnimation {
107             properties: "opacity"
108             from: 1
109             to:0
110             duration: 250
111         }
112         NumberAnimation {
113             properties: "scale"
114             from: 1
115             to:5
116             duration: 250
117         }
118     }
119
120     Image {
121         id: container
122         anchors.centerIn: parent
123         width: 1080
124         height: 1920
125         rotation: 270
126         source: './images/AGL_HMI_Background_NoCar-01.png'
127
128         ColumnLayout {
129             anchors.fill: parent
130             spacing: 0
131             TopArea {
132                 id: topArea
133                 Layout.fillWidth: true
134                 Layout.preferredHeight: 218
135             }
136
137             Item {
138                 id: applicationArea
139                 Layout.fillWidth: true
140                 Layout.fillHeight: true
141                 Layout.preferredHeight: 1920 - 218 - 215
142                 clip: true
143                 StackView {
144                     id: applicationStack
145                     anchors.fill: parent
146                     initialItem: home
147
148                     pushEnter: inTransition
149                     pushExit: outTransition
150                     replaceEnter: inTransition
151                     replaceExit: outTransition
152                     popEnter: inTransition
153                     popExit: outTransition
154                 }
155             }
156
157             MediaArea {
158                 id: mediaArea
159                 Layout.fillWidth: true
160                 Layout.fillHeight: true
161                 Layout.preferredHeight: 215
162                 MouseArea {
163                     z: 100
164                     anchors.fill: parent
165                     onClicked: {
166                         notificationLayer.shown = true
167                     }
168                 }
169             }
170         }
171     }
172
173     MouseArea {
174         id: notificationLayer
175         property bool shown: false
176         anchors.fill: container
177         scale: container.scale
178         visible: opacity > 0
179         opacity: 0
180         rotation: 270
181         z: 100
182
183         onClicked: shown = false
184
185         Rectangle {
186             anchors.fill: parent
187             color: 'black'
188             opacity: 0.75
189         }
190
191         states: [
192             State {
193                 name: "notify"
194                 when: notificationLayer.shown
195                 PropertyChanges {
196                     target: notificationLayer
197                     opacity: 1.0
198                 }
199                 PropertyChanges {
200                     target: timer
201                     running: true
202                 }
203             }
204         ]
205
206         transitions: [
207             Transition {
208                 NumberAnimation {
209                     properties: 'opacity'
210                     duration: 250
211                     easing.type: Easing.OutExpo
212                 }
213             }
214         ]
215
216         Column {
217             anchors.centerIn: parent
218             spacing: 20
219             Rectangle {
220                 width: 600
221                 height: 250
222                 radius: 20
223                 color: 'white'
224
225                 Label {
226                     anchors.centerIn: parent
227                     text: "Message 1"
228                     font.pixelSize: 96
229                     color: 'blue'
230                     antialiasing: true
231                 }
232             }
233             Rectangle {
234                 width: 600
235                 height: 250
236                 radius: 20
237                 color: 'white'
238
239                 Label {
240                     anchors.centerIn: parent
241                     text: "Restart"
242                     font.pixelSize: 96
243                     color: 'red'
244                     antialiasing: true
245                     MouseArea {
246                         anchors.fill: parent
247                         onClicked: Qt.quit()
248                     }
249                 }
250             }
251             Timer {
252                 id: timer
253                 interval: 3000
254                 onTriggered: notificationLayer.shown = false
255             }
256         }
257     }
258 }