Home: Use icon from AFM, display a black area with text if icon unloadable
[apps/homescreen.git] / homescreen / qml / Home.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 Home 1.0
20
21 Item {
22     id: root
23
24     Image {
25         anchors.fill: parent
26         anchors.topMargin: -218
27         anchors.bottomMargin: -215
28         source: './images/AGL_HMI_Background_Car-01.png'
29     }
30
31     property int pid: -1
32
33     GridView {
34         anchors.centerIn: parent
35         width: cellWidth * 3
36         height: parent.height
37         cellWidth: 320
38         cellHeight: 320
39         interactive: true
40         clip: true
41
42         model: ApplicationModel {}
43
44         delegate: MouseArea {
45             width: 320
46             height: 320
47
48             Item {
49                 width: parent.width
50                 height: parent.height
51                 anchors.fill: parent
52
53                 // These images contain the item text at the bottom,
54                 // is it possible to crop the image in QML?
55                 Image {
56                     id: img
57                     clip: true
58                     width: parent.width
59                     height: parent.height
60                     fillMode: Image.PreserveAspectCrop
61                     source: model.icon.substr(0, 5) === "file:"
62                         ? model.icon
63                         : './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
64                 }
65
66                 // Show this rect and the text below if the image could not be loaded
67                 Rectangle {
68                     anchors {
69                         fill: parent
70                         margins: 50
71                     }
72                     border {
73                         color: "#64fdcb"
74                         width: 3
75                     }
76                     color: pressed ? "#11bcb9" : "#202020"
77                     radius: parent.width / 2 // circle'd rectangle...
78                     visible: img.status == Image.Error
79                 }
80
81                 Text {
82                     property int font_size: 26
83
84                     font.family: roboto
85                     font.capitalization: Font.AllUppercase
86                     font.bold: false
87                     font.pixelSize: font_size
88                     text: model.name
89                     color: "#ffffff"
90                     anchors {
91                         horizontalCenter: parent.horizontalCenter
92                         top: img.top
93                         topMargin: parent.height / 2 - font_size / 2
94                     }
95                     visible: img.status == Image.Error
96                 }
97             }
98
99             onClicked: {
100                 console.log("app is ", model.id)
101                 pid = launcher.launch(model.id)
102                 if (1 < pid) {
103                     layoutHandler.makeMeVisible(pid)
104
105                     applicationArea.visible = true
106                     appLauncherAreaLauncher.visible = false
107                     layoutHandler.showAppLayer(pid)
108                 }
109                 else {
110                     console.warn("app cannot be launched!")
111                 }
112             }
113         }
114     }
115 }