change bg image opacity, add check icon condition
[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                     container.opacity = 0.0
140                 } else {
141                     image.source = './images/normal.png'
142                     btnState = 'normal'
143                     container.state = 'normal'
144                     touchArea.switchArea(0)
145                     homescreenHandler.tapShortcut(appName, false)
146                     container.opacity = 1.0
147                 }
148             }
149         }
150     }
151
152     Timer {
153         id:informationTimer
154         interval: 3000
155         running: false
156         repeat: true
157         onTriggered: {
158             bottomInformation.visible = false
159         }
160     }
161
162     Item {
163         id: bottomInformation
164         width: parent.width
165         height: 215
166         anchors.bottom: parent.bottom
167         visible: false
168         Text {
169             id: bottomText
170             anchors.centerIn: parent
171             font.pixelSize: 25
172             font.letterSpacing: 5
173             horizontalAlignment: Text.AlignHCenter
174             color: "white"
175             text: ""
176             z:1
177         }
178     }
179
180     Connections {
181         target: homescreenHandler
182         onShowInformation: {
183             bottomText.text = info
184             bottomInformation.visible = true
185             informationTimer.restart()
186         }
187     }
188
189         Timer {
190         id:notificationTimer
191         interval: 3000
192         running: false
193         repeat: true
194         onTriggered: notificationItem.visible = false
195     }
196
197     Item {
198         id: notificationItem
199         x: 0
200         y: 0
201         z: 1
202         width: 1280
203         height: 100
204         opacity: 0.8
205         visible: false
206
207         Rectangle {
208             width: parent.width
209             height: parent.height
210             anchors.fill: parent
211             color: "gray"
212             Image {
213                 id: notificationIcon
214                 width: 70
215                 height: 70
216                 anchors.left: parent.left
217                 anchors.leftMargin: 20
218                 anchors.verticalCenter: parent.verticalCenter
219                 source: ""
220             }
221
222             Text {
223                 id: notificationtext
224                 font.pixelSize: 25
225                 anchors.left: notificationIcon.right
226                 anchors.leftMargin: 5
227                 anchors.verticalCenter: parent.verticalCenter
228                 color: "white"
229                 text: qsTr("")
230             }
231         }
232     }
233
234     Connections {
235         target: homescreenHandler
236         onShowNotification: {
237             notificationIcon.source = icon_path
238             notificationtext.text = text
239             notificationItem.visible = true
240             notificationTimer.restart()
241         }
242     }
243 }