main.qml 9.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *  Copyright 2015 Marco Martin <mart@kde.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  2.010-1301, USA.
 */

import QtQuick 2.4
import QtQuick.Layouts 1.1
Marco Martin's avatar
Marco Martin committed
21
import QtQuick.Window 2.2
Marco Martin's avatar
Marco Martin committed
22
import QtGraphicalEffects 1.12
23

Marco Martin's avatar
Marco Martin committed
24
import org.kde.taskmanager 0.1 as TaskManager
25
26
27
28
29
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0

30
31
import org.kde.plasma.private.nanoshell 2.0 as NanoShell

Marco Martin's avatar
Marco Martin committed
32
33
import org.kde.plasma.private.mobileshell 1.0 as MobileShell

Marco Martin's avatar
Marco Martin committed
34
35
PlasmaCore.ColorScope {
    id: root
36
    width: 600
Marco Martin's avatar
Marco Martin committed
37
    height: 480
Marco Martin's avatar
Marco Martin committed
38
    colorGroup: showingApp ? PlasmaCore.Theme.NormalColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
Marco Martin's avatar
Marco Martin committed
39

40
41
    Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground

42
43
    readonly property color backgroundColor: NanoShell.StartupFeedback.visible ? NanoShell.StartupFeedback.backgroundColor : PlasmaCore.ColorScope.backgroundColor
    readonly property bool showingApp: !plasmoid.nativeInterface.allMinimized
44
45

    readonly property bool hasTasks: tasksModel.count > 0
46

47
48
49
    property QtObject taskSwitcher: taskSwitcherLoader.item ? taskSwitcherLoader.item : null
    Loader {
        id: taskSwitcherLoader
Marco Martin's avatar
Marco Martin committed
50
    }
51
    //FIXME: why it crashes on startup if TaskSwitcher is loaded immediately?
Marco Martin's avatar
Marco Martin committed
52
53
    Connections {
        target: plasmoid.nativeInterface
54
55
        function onAllMinimizedChanged() {
            MobileShell.HomeScreenControls.homeScreenVisible = plasmoid.nativeInterface.allMinimized
Marco Martin's avatar
Marco Martin committed
56
57
        }
    }
58
59
60
    Timer {
        running: true
        interval: 200
Marco Martin's avatar
Marco Martin committed
61
62
63
        onTriggered: {
            taskSwitcherLoader.setSource(Qt.resolvedUrl("TaskSwitcher.qml"), {"model": tasksModel});
        }
64
65
    }

Marco Martin's avatar
Marco Martin committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    function minimizeAll() {
        for (var i = 0 ; i < tasksModel.count; i++) {
            var idx = tasksModel.makeModelIndex(i);
            if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) {
                tasksModel.requestToggleMinimized(idx);
            }
        }
    }

    function restoreAll() {
        for (var i = 0 ; i < tasksModel.count; i++) {
            var idx = tasksModel.makeModelIndex(i);
            if (tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) {
                tasksModel.requestToggleMinimized(idx);
            }
        }
    }

84
85
86
87
88
    TaskManager.TasksModel {
        id: tasksModel
        groupMode: TaskManager.TasksModel.GroupDisabled

        screenGeometry: plasmoid.screenGeometry
89
90
91
92
93
94
95
96
97
98
99
        sortMode: TaskManager.TasksModel.SortAlpha

        virtualDesktop: virtualDesktopInfo.currentDesktop
        activity: activityInfo.currentActivity
        //FIXME: workaround
        Component.onCompleted: tasksModel.countChanged();
    }

    TaskManager.VirtualDesktopInfo {
        id: virtualDesktopInfo
    }
100

101
102
    TaskManager.ActivityInfo {
        id: activityInfo
103
104
    }

Marco Martin's avatar
Marco Martin committed
105
106
    MouseArea {
        id: mainMouseArea
Marco Martin's avatar
Marco Martin committed
107
        anchors.fill: parent
Marco Martin's avatar
Marco Martin committed
108
        property int oldMouseY: 0
Marco Martin's avatar
Marco Martin committed
109
110
        property int startMouseY: 0
        property bool isDragging: false
Marco Martin's avatar
Marco Martin committed
111
        property bool opening: false
Marco Martin's avatar
Marco Martin committed
112
        drag.filterChildren: true
Marco Martin's avatar
Marco Martin committed
113
114
        function managePressed(mouse) {
            startMouseY = oldMouseY = mouse.y;
Marco Martin's avatar
Marco Martin committed
115
116
            taskSwitcher.offset = -taskSwitcher.height
        }
Marco Martin's avatar
Marco Martin committed
117
        onPressed: managePressed(mouse);
Marco Martin's avatar
Marco Martin committed
118
        onPositionChanged: {
Marco Martin's avatar
Marco Martin committed
119
120
121
122
123
124
125
            if (!isDragging && Math.abs(startMouseY - oldMouseY) < root.height) {
                oldMouseY = mouse.y;
                return;
            } else {
                isDragging = true;
            }

Marco Martin's avatar
Marco Martin committed
126
            taskSwitcher.offset = taskSwitcher.offset - (mouse.y - oldMouseY);
Marco Martin's avatar
Marco Martin committed
127
            opening = oldMouseY > mouse.y;
128

Marco Martin's avatar
Marco Martin committed
129
            if (taskSwitcher.visibility == Window.Hidden && taskSwitcher.offset > -taskSwitcher.height + units.gridUnit && taskSwitcher.tasksCount) {
130
                taskSwitcher.showFullScreen();
131
132
133
            //no tasks, let's scroll up the homescreen instead
            } else if (taskSwitcher.tasksCount === 0) {
                MobileShell.HomeScreenControls.requestHomeScreenPosition(MobileShell.HomeScreenControls.homeScreenPosition - (mouse.y - oldMouseY));
Marco Martin's avatar
Marco Martin committed
134
            }
135
            oldMouseY = mouse.y;
Marco Martin's avatar
Marco Martin committed
136
137
        }
        onReleased: {
Marco Martin's avatar
Marco Martin committed
138
139
140
141
            if (!isDragging) {
                return;
            }

Marco Martin's avatar
Marco Martin committed
142
            if (taskSwitcher.visibility == Window.Hidden) {
143
144
145
                if (taskSwitcher.tasksCount === 0) {
                    MobileShell.HomeScreenControls.snapHomeScreenPosition();
                }
Marco Martin's avatar
Marco Martin committed
146
147
                return;
            }
Marco Martin's avatar
Marco Martin committed
148
            if (opening) {
Marco Martin's avatar
Marco Martin committed
149
150
151
152
153
                taskSwitcher.show();
            } else {
                taskSwitcher.hide();
            }
        }
Marco Martin's avatar
Marco Martin committed
154

Marco Martin's avatar
Marco Martin committed
155
156
        DropShadow {
            anchors.fill: icons
Jonah Brüchert's avatar
Jonah Brüchert committed
157
            visible: !showingApp
Marco Martin's avatar
Marco Martin committed
158
            cached: true
Marco Martin's avatar
Marco Martin committed
159
160
161
162
163
164
165
            horizontalOffset: 0
            verticalOffset: 1
            radius: 4.0
            samples: 17
            color: Qt.rgba(0,0,0,0.8)
            source: icons
        }
166
        Item {
Marco Martin's avatar
Marco Martin committed
167
            id: icons
Marco Martin's avatar
Marco Martin committed
168
            anchors.fill: parent
Marco Martin's avatar
Marco Martin committed
169

170
            visible: plasmoid.configuration.PanelButtonsVisible
171

Marco Martin's avatar
Marco Martin committed
172
173
174
175
176
            Rectangle {
                anchors.fill: parent
                gradient: Gradient {
                    GradientStop {
                        position: 0
177
                        color: showingApp ? root.backgroundColor : "transparent"
Marco Martin's avatar
Marco Martin committed
178
179
180
                    }
                    GradientStop {
                        position: 1
181
                        color: showingApp ? root.backgroundColor : Qt.rgba(0, 0, 0, 0.1)
Marco Martin's avatar
Marco Martin committed
182
183
                    }
                }
184
            }
Marco Martin's avatar
Marco Martin committed
185

Marco Martin's avatar
Marco Martin committed
186
187
188
189
            Button {
                anchors.left: parent.left
                height: parent.height
                width: parent.width/3
190
                enabled: root.hasTasks
191
                clickable: root.hasTasks && !taskSwitcher.visible
Ilya Bizyaev's avatar
Ilya Bizyaev committed
192
                iconSource: "box"
Marco Martin's avatar
Marco Martin committed
193
                onClicked: {
194
                    if (!clickable) {
195
196
                        return;
                    }
Marco Martin's avatar
Marco Martin committed
197
                    plasmoid.nativeInterface.showDesktop = false;
Marco Martin's avatar
Marco Martin committed
198
199
200
                    taskSwitcher.visible ? taskSwitcher.hide() : taskSwitcher.show();
                }
                onPressed: mainMouseArea.managePressed(mouse);
201
202
                onPositionChanged: mainMouseArea.positionChanged(mouse);
                onReleased: mainMouseArea.released(mouse);
Marco Martin's avatar
Marco Martin committed
203
            }
Marco Martin's avatar
Marco Martin committed
204
205
206
207
208
209

            Button {
                id: showDesktopButton
                height: parent.height
                width: parent.width/3
                anchors.horizontalCenter: parent.horizontalCenter
Ilya Bizyaev's avatar
Ilya Bizyaev committed
210
                iconSource: "start-here-kde"
211
                clickable: !taskSwitcher.visible && (root.showingApp || MobileShell.HomeScreenControls.homeScreenPosition != 0)
Marco Martin's avatar
Marco Martin committed
212
213
                //checkable: true
                onClicked: {
214
                    if (!clickable) {
215
216
                        return;
                    }
Marco Martin's avatar
Marco Martin committed
217
                    root.minimizeAll();
218
219
                    MobileShell.HomeScreenControls.resetHomeScreenPosition();
                    plasmoid.nativeInterface.allMinimizedChanged();
Marco Martin's avatar
Marco Martin committed
220
                    //plasmoid.nativeInterface.showDesktop = checked;
Marco Martin's avatar
Marco Martin committed
221
                }
Marco Martin's avatar
Marco Martin committed
222
                onPressed: mainMouseArea.managePressed(mouse);
223
224
                onPositionChanged: mainMouseArea.positionChanged(mouse);
                onReleased: mainMouseArea.released(mouse);
Marco Martin's avatar
Marco Martin committed
225
226
227
228
229
230
231
232
                Connections {
                    target: root.taskSwitcher
                    onCurrentTaskIndexChanged: {
                        if (root.taskSwitcher.currentTaskIndex < 0) {
                            showDesktopButton.checked = false;
                        }
                    }
                }
233
            }
Marco Martin's avatar
Marco Martin committed
234

Marco Martin's avatar
Marco Martin committed
235
236
237
238
            Button {
                height: parent.height
                width: parent.width/3
                anchors.right: parent.right
Ilya Bizyaev's avatar
Ilya Bizyaev committed
239
                iconSource: "paint-none"
Marco Martin's avatar
Marco Martin committed
240
                //FIXME:Qt.UserRole+9 is IsWindow Qt.UserRole+15 is IsClosable. We can't reach that enum from QML
241
                clickable: plasmoid.nativeInterface.hasCloseableActiveWindow && !taskSwitcher.visible
Marco Martin's avatar
Marco Martin committed
242
                onClicked: {
243
                    if (!clickable) {
244
245
246
247
248
                        return;
                    }
                    if (!plasmoid.nativeInterface.hasCloseableActiveWindow) {
                        return;
                    }
Marco Martin's avatar
Marco Martin committed
249
250
251
252
253
                    var index = taskSwitcher.model.activeTask;
                    if (index) {
                        taskSwitcher.model.requestClose(index);
                    }
                }
Marco Martin's avatar
Marco Martin committed
254
                onPressed: mainMouseArea.managePressed(mouse);
255
256
                onPositionChanged: mainMouseArea.positionChanged(mouse);
                onReleased: mainMouseArea.released(mouse);
Marco Martin's avatar
Marco Martin committed
257
            }
Marco Martin's avatar
Marco Martin committed
258
        }
259
    }
Marco Martin's avatar
Marco Martin committed
260
261
262
263
264
265
    //This is to give an animation when the plasma button is pressed
    Item {
        id: dummyWindowTask
        width: Screen.width
        height: Screen.height
    }
266
}