33ec53998c815529ee86c87ba31f11cbe7f3011a
[staging/HomeScreen.git] / HomeScreen / qml / ShortcutArea.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
21 Item {
22     id: root
23     width: 785
24     height: 218
25
26
27     ListModel {
28         id: applicationModel
29         ListElement {
30             name: 'Home'
31             application: 'home@0.1'
32             label: 'HOME'
33         }
34         ListElement {
35             name: 'Multimedia'
36             application: 'mediaplayer@0.1'
37             label: 'MULTIMEDIA'
38         }
39         ListElement {
40             name: 'HVAC'
41             application: 'hvac@0.1'
42             label: 'HVAC'
43         }
44         ListElement {
45             name: 'Navigation'
46             application: 'navigation@0.1'
47             label: 'NAVIGATION'
48         }
49     }
50     function languageChanged(lang) {
51         if(lang === "fr") {
52             applicationModel.setProperty(0, "label", 'ACCEUIL')
53
54             applicationModel.setProperty(2, "label", 'MULTIMÉDIA')
55             applicationModel.setProperty(2, "name", 'Multimedia')
56             applicationModel.setProperty(2, "application", 'mediaplayer@0.1')
57
58             applicationModel.setProperty(3, "label", 'CLIMATISATION')
59             applicationModel.setProperty(3, "name", 'HVAC')
60             applicationModel.setProperty(3, "application", 'hvac@0.1')
61
62             applicationModel.setProperty(1, "label", 'NAVIGATION')
63             applicationModel.setProperty(1, "name", 'Navigation')
64             applicationModel.setProperty(1, "application", 'navigation@0.1')
65         } else {
66             applicationModel.setProperty(0, "label", 'HOME')
67
68             applicationModel.setProperty(1, "label", 'MULTIMEDIA')
69             applicationModel.setProperty(1, "name", 'Multimedia')
70             applicationModel.setProperty(1, "application", 'mediaplayer@0.1')
71
72             applicationModel.setProperty(2, "label", 'HVAC')
73             applicationModel.setProperty(2, "name", 'HVAC')
74             applicationModel.setProperty(2, "application", 'hvac@0.1')
75
76             applicationModel.setProperty(3, "label", 'NAVIGATION')
77             applicationModel.setProperty(3, "name", 'Navigation')
78             applicationModel.setProperty(3, "application", 'navigation@0.1')
79         }
80     }
81
82     property int pid: -1
83
84     RowLayout {
85         anchors.fill: parent
86         spacing: 2
87         Repeater {
88             model: applicationModel
89             delegate: ShortcutIcon {
90                 Layout.fillWidth: true
91                 Layout.fillHeight: true
92                 name: model.name
93                 active: model.application === launcher.current
94                 onClicked: {
95                     if (0 === model.index) {
96                         appLauncherAreaLauncher.visible = true
97                         applicationArea.visible = false
98                         layoutHandler.hideAppLayer()
99                         launcher.current = ''
100                     }
101                     else {
102                         pid = launcher.launch(model.application)
103                         if (1 < pid) {
104                             applicationArea.visible = true
105                             appLauncherAreaLauncher.visible = false
106                             layoutHandler.makeMeVisible(pid)
107                             layoutHandler.showAppLayer(pid)
108                         }
109                         else {
110                             console.warn("app cannot be launched!")
111                         }
112                     }
113                 }
114             }
115         }
116     }
117     Component.onCompleted: {
118         root.currentIndex = 0
119         appLauncherAreaLauncher.visible = true
120         applicationArea.visible = false
121         layoutHandler.hideAppLayer()
122     }
123 }