Detach launcher application from HomeScreen
[apps/launcher.git] / launcher / qml / Launcher.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 import QtQuick 2.6
19 import QtQuick.Layouts 1.1
20 import QtQuick.Controls 2.0
21 import AppModel 1.0
22
23 ApplicationWindow {
24     id: root
25     // Layout.fillWidth: true
26     // Layout.fillHeight: true
27     // width: 1080
28     // Layout.preferredHeight: 1487
29
30     property int pid: -1
31     Image {
32         y: 218
33         anchors.centerIn: parent
34         source: './images/AGL_HMI_Blue_Background_Car-01.png'
35     }
36
37
38     GridView {
39         id: grid
40         x: 60
41         y: 100
42         width: 960
43         height: 1280
44         anchors.horizontalCenter: parent.horizontalCenter
45         anchors.verticalCenter: parent.verticalCenter
46         contentHeight: 320
47         flickableDirection: Flickable.AutoFlickDirection
48         snapMode: GridView.SnapOneRow
49         visible: true
50         cellWidth: 320
51         cellHeight: 320
52         interactive: false
53
54         model: ApplicationModel { id: applicationModel }
55         delegate: IconItem {
56             width: grid.cellWidth
57             height: grid.cellHeight
58         }
59
60         MouseArea {
61             id: loc
62             anchors.fill: parent
63             property string currentId: ''
64             property int newIndex: -1
65             property int index: grid.indexAt(loc.mouseX, loc.mouseY)
66             x: 62
67             y: 264
68             anchors.rightMargin: 0
69             anchors.bottomMargin: 0
70             anchors.leftMargin: 0
71             anchors.topMargin: 0
72             onPressAndHold: currentId = applicationModel.id(newIndex = index)
73             onReleased: {
74                 if (currentId === '') {
75                     pid = launcher.launch(applicationModel.id(loc.index))
76                     if (1 < pid) {
77                     }
78                     else {
79                         console.warn("app cannot be launched!")
80                     }
81                 } else {
82                     currentId = ''
83                 }
84                 homescreenHandler.tapShortcut(applicationModel.name(loc.index))
85             }
86             onPositionChanged: {
87                 if (loc.currentId === '') return
88                 if (index < 0) return
89                 if (index === newIndex) return
90                     applicationModel.move(newIndex, newIndex = index)
91             }
92         }
93     }
94 }