164cbf7e50080b80c881ee2a002bb4ebfba01279
[apps/homescreen.git] / homescreen / qml / main.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 HomeScreen 1.0
22
23 Window {
24     visible: true
25     flags: Qt.FramelessWindowHint
26     width: container.width * container.scale
27     height: container.height * container.scale
28     title: 'HomeScreen'
29     color: "#00000000"
30
31     Image {
32         id: container
33         anchors.centerIn: parent
34         width: 1080
35         height: 1920
36         scale: screenInfo.scale_factor()
37         source: './images/AGL_HMI_Blue_Background_NoCar-01.png'
38
39         ColumnLayout {
40             anchors.fill: parent
41             spacing: 0
42             TopArea {
43                 id: topArea
44                 Layout.fillWidth: true
45                 Layout.preferredHeight: 218
46             }
47
48             Item {
49                 id: applicationArea
50                 Layout.fillWidth: true
51                 Layout.fillHeight: true
52                 Layout.preferredHeight: 1920 - 218 - 215
53
54                 visible: true
55             }
56
57             MediaArea {
58                 id: mediaArea
59                 Layout.fillWidth: true
60                 Layout.fillHeight: true
61                 Layout.preferredHeight: 215
62             }
63         }
64
65         states: [
66             State {
67                 name: "normal"
68                 PropertyChanges {
69                     target: topArea
70                     y: 0
71                 }
72                 PropertyChanges {
73                     target: applicationArea
74                     y: 218
75                 }
76                 PropertyChanges {
77                     target: mediaArea
78                     y: 1705
79                 }
80             },
81             State {
82                 name: "fullscreen"
83                 PropertyChanges {
84                     target: topArea
85                     y: -220
86                 }
87                 PropertyChanges {
88                     target: applicationArea
89                     y: -1490
90                 }
91                 PropertyChanges {
92                     target: mediaArea
93                     y: 2135
94                 }
95             }
96         ]
97         transitions: Transition {
98             NumberAnimation {
99                 target: topArea
100                 property: "y"
101                 easing.type: "OutQuad"
102                 duration: 250
103             }
104             NumberAnimation {
105                 target: mediaArea
106                 property: "y"
107                 easing.type: "OutQuad"
108                 duration: 250
109             }
110         }
111     }
112
113     Item {
114         id: switchBtn
115         anchors.right: parent.right
116         anchors.rightMargin: 20
117         anchors.top: parent.top
118         anchors.topMargin: 25
119         width: 35
120         height: 35
121         z: 1
122
123         MouseArea {
124             anchors.fill: parent
125             property string btnState: 'normal'
126             Image {
127                 id: image
128                 anchors.fill: parent
129                 source: './images/normal.png'
130             }
131             onClicked: {
132                 var appName = homescreenHandler.getCurrentApplication()
133                 if (btnState === 'normal') {
134                     image.source = './images/fullscreen.png'
135                     btnState = 'fullscreen'
136                     container.state = 'fullscreen'
137                     touchArea.switchArea(1)
138                     homescreenHandler.tapShortcut(appName, true)
139                     if (appName === 'navigation' || appName === 'browser') {
140                         container.opacity = 0.0
141                     }
142                 } else {
143                     image.source = './images/normal.png'
144                     btnState = 'normal'
145                     container.state = 'normal'
146                     touchArea.switchArea(0)
147                     homescreenHandler.tapShortcut(appName, false)
148                     if (appName === 'navigation' || appName === 'browser') {
149                         container.opacity = 1.0
150                     }
151                 }
152             }
153         }
154     }
155
156     Timer {
157         id:informationTimer
158         interval: 3000
159         running: false
160         repeat: true
161         onTriggered: {
162             bottomInformation.visible = false
163         }
164     }
165
166     Item {
167         id: bottomInformation
168         width: parent.width
169         height: 215
170         anchors.bottom: parent.bottom
171         visible: false
172         Text {
173             id: bottomText
174             anchors.centerIn: parent
175             font.pixelSize: 25
176             font.letterSpacing: 5
177             horizontalAlignment: Text.AlignHCenter
178             color: "white"
179             text: ""
180             z:1
181         }
182     }
183
184     Connections {
185         target: homescreenHandler
186         onShowInformation: {
187             bottomText.text = info
188             bottomInformation.visible = true
189             informationTimer.restart()
190         }
191     }
192
193         Timer {
194         id:notificationTimer
195         interval: 3000
196         running: false
197         repeat: true
198         onTriggered: notificationItem.visible = false
199     }
200
201     Item {
202         id: notificationItem
203         x: 0
204         y: 0
205         z: 1
206         width: 1280
207         height: 100
208         opacity: 0.8
209         visible: false
210
211         Rectangle {
212             width: parent.width
213             height: parent.height
214             anchors.fill: parent
215             color: "gray"
216             Image {
217                 id: notificationIcon
218                 width: 70
219                 height: 70
220                 anchors.left: parent.left
221                 anchors.leftMargin: 20
222                 anchors.verticalCenter: parent.verticalCenter
223                 source: ""
224             }
225
226             Text {
227                 id: notificationtext
228                 font.pixelSize: 25
229                 anchors.left: notificationIcon.right
230                 anchors.leftMargin: 5
231                 anchors.verticalCenter: parent.verticalCenter
232                 color: "white"
233                 text: qsTr("")
234             }
235         }
236     }
237
238     Connections {
239         target: homescreenHandler
240         onShowNotification: {
241             notificationIcon.source = icon_path
242             notificationtext.text = text
243             notificationItem.visible = true
244             notificationTimer.restart()
245         }
246     }
247 }