summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/application-features/SystemUi/main.qml
blob: 0f87b9874b6e6dc15e002f581fad563c6f0df0ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

pragma ComponentBehavior: Bound

import QtQuick
import QtApplicationManager.SystemUI

Window {
    title: "Application Features - QtApplicationManager Example"
    width: 1280
    height: 800
    color: "whitesmoke"

    Text {
        anchors.bottom: parent.bottom
        text: (ApplicationManager.singleProcess ? "Single" : "Multi") + "-Process Mode"
    }

    Column {
        z: 9998
        Repeater {
            model: ApplicationManager

            Image {
                id: delegate
                required property string icon
                required property bool isRunning
                required property ApplicationObject application

                source: icon
                opacity: isRunning ? 0.3 : 1.0

                Rectangle {
                    x: 96; y: 38
                    width: appid.width; height: appid.height
                    color: "whitesmoke"
                    visible: imouse.containsMouse

                    Text {
                        id: appid
                        text: delegate.application.names["en"]
                    }
                }

                MouseArea {
                    id: imouse
                    anchors.fill: parent
                    hoverEnabled: true
                    onClicked: delegate.isRunning ? delegate.application.stop() : delegate.application.start();
                }
            }
        }
    }

    Repeater {
        model: ListModel { id: topLevelWindowsModel }

        delegate: Rectangle {
            id: chrome
            required property WindowObject window
            required property int index

            width: draggrab.x + 10; height: draggrab.y + 10
            color: "transparent"
            border.width: 3
            border.color: "grey"
            z: index

            Image {
                id: draggrab
                x: 710; y: 530
                source: "grab.png"
                visible: dragarea.containsMouse
            }

            MouseArea {
                id: dragarea
                anchors.fill: draggrab
                hoverEnabled: true
                drag.target: draggrab
                drag.minimumX: 230
                drag.minimumY: 170
            }

            Rectangle {
                height: 25
                width: parent.width
                color: "grey"

                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: chrome.window.application ? chrome.window.application.names["en"] : 'External Application'
                }

                MouseArea {
                    anchors.fill: parent
                    drag.target: chrome
                    onPressed: topLevelWindowsModel.move(chrome.index, topLevelWindowsModel.count - 1, 1);
                }

                Image {
                    source: "close.png"
                    MouseArea {
                        anchors.fill: parent
                        onClicked: chrome.window.close();
                    }
                }
            }

            WindowItem {
                anchors.fill: parent
                anchors.margins: 3
                anchors.topMargin: 25
                window: chrome.window

                Connections {
                    target: chrome.window
                    function onContentStateChanged() {
                        if (chrome.window.contentState === WindowObject.NoSurface)
                            topLevelWindowsModel.remove(chrome.index, 1);
                    }
                }
            }

            Component.onCompleted: {
                x = 200 + chrome.index * 50;
                y =  20 + chrome.index * 30;
            }
        }
    }

    Repeater {
        model: ListModel { id: popupsModel }
        delegate: WindowItem {
            id: win
            required property var model

            z: 9999 + model.index
            anchors.centerIn: parent
            window: model.window

            Connections {
                target: win.model.window
                function onContentStateChanged() {
                    if (win.model.window.contentState === WindowObject.NoSurface)
                        popupsModel.remove(win.model.index, 1);
                }
            }
        }
    }

    Text {
        z: 9999
        font.pixelSize: 46
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        text: NotificationManager.count > 0 ? NotificationManager.get(0).summary : ""
    }

    Connections {
        target: WindowManager
        function onWindowAdded(window) {
            let model = window.windowProperty("type") === "pop-up" ? popupsModel : topLevelWindowsModel;
            model.append({ "window": window });
        }
    }

    Connections {
        target: ApplicationManager
        function onApplicationRunStateChanged(id, runState) {
            if (runState === Am.NotRunning && id === "Crash"
                && ApplicationManager.application(id).lastExitStatus === Am.CrashExit) {
                ApplicationManager.startApplication(id);
            }
        }
    }
}