Changeset View
Changeset View
Standalone View
Standalone View
applets/minimizeall/package/contents/ui/main.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2015 Sebastian Kügler <sebas@kde.org> | 2 | * Copyright 2015 Sebastian Kügler <sebas@kde.org> | ||
3 | * Copyright 2016 Anthony Fieroni <bvbfan@abv.bg> | 3 | * Copyright 2016 Anthony Fieroni <bvbfan@abv.bg> | ||
4 | * Copyright 2018 David Edmundson <davidedmundson@kde.org> | ||||
4 | * | 5 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | 9 | * (at your option) any later version. | ||
9 | * | 10 | * | ||
10 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. | ||
14 | * | 15 | * | ||
15 | * You should have received a copy of the GNU General Public License along | 16 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, write to the Free Software Foundation, Inc., | 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | import QtQuick 2.1 | 21 | import QtQuick 2.1 | ||
21 | import QtQuick.Layouts 1.1 | 22 | import QtQuick.Layouts 1.1 | ||
22 | 23 | | |||
23 | import org.kde.plasma.plasmoid 2.0 | 24 | import org.kde.plasma.plasmoid 2.0 | ||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | 25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
25 | 26 | | |||
26 | import org.kde.plasma.private.minimizeall 1.0 | 27 | import org.kde.taskmanager 0.1 as TaskManager | ||
27 | | ||||
28 | 28 | | |||
29 | Item { | 29 | Item { | ||
30 | id: root | 30 | id: root | ||
31 | 31 | | |||
32 | readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge | 32 | readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge | ||
33 | || plasmoid.location === PlasmaCore.Types.RightEdge | 33 | || plasmoid.location === PlasmaCore.Types.RightEdge | ||
34 | || plasmoid.location === PlasmaCore.Types.BottomEdge | 34 | || plasmoid.location === PlasmaCore.Types.BottomEdge | ||
35 | || plasmoid.location === PlasmaCore.Types.LeftEdge) | 35 | || plasmoid.location === PlasmaCore.Types.LeftEdge) | ||
36 | 36 | | |||
37 | Layout.minimumWidth: units.gridUnit | 37 | Layout.minimumWidth: units.gridUnit | ||
38 | Layout.minimumHeight: units.gridUnit | 38 | Layout.minimumHeight: units.gridUnit | ||
39 | 39 | | |||
40 | Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1 | 40 | Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1 | ||
41 | Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1 | 41 | Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1 | ||
42 | 42 | | |||
43 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | 43 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | ||
44 | 44 | | |||
45 | Plasmoid.onActivated: toggleActive() | ||||
46 | | ||||
47 | property bool active: false | ||||
48 | property var minimizedClients: [] //list of persistentmodelindexes from task manager model of clients minimised by us | ||||
49 | | ||||
45 | function activate() { | 50 | function activate() { | ||
46 | if (!minimizeall.active) { | 51 | var clients = [] | ||
47 | minimizeall.minimizeAllWindows(); | 52 | for (var i = 0 ; i < tasksModel.count; i++) { | ||
53 | var idx = tasksModel.makeModelIndex(i); | ||||
54 | if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { | ||||
55 | tasksModel.requestToggleMinimized(idx); | ||||
56 | clients.push(tasksModel.makePersistentModelIndex(i)); | ||||
broulik: This method does not exist, did you forget to commit the plasma-workspace part? | |||||
57 | } | ||||
broulik: typo | |||||
58 | } | ||||
59 | root.minimizedClients = clients; | ||||
60 | root.active = true; | ||||
61 | } | ||||
62 | | ||||
63 | function deactivate() { | ||||
64 | root.active = false; | ||||
65 | for (var i = 0 ; i < root.minimizedClients.length; i++) { | ||||
66 | var idx = root.minimizedClients[i] | ||||
67 | //client deleted, do nothing | ||||
68 | if (!idx.valid) { | ||||
69 | continue; | ||||
70 | } | ||||
71 | //if the user has restored it already, do nothing | ||||
72 | if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { | ||||
73 | continue; | ||||
74 | } | ||||
75 | tasksModel.requestToggleMinimized(idx); | ||||
76 | } | ||||
77 | root.minimizedClients = []; | ||||
78 | } | ||||
79 | | ||||
80 | function toggleActive() { | ||||
81 | if (root.active) { | ||||
82 | deactivate(); | ||||
48 | } else { | 83 | } else { | ||
49 | minimizeall.unminimizeAllWindows(); | 84 | activate(); | ||
50 | } | 85 | } | ||
51 | } | 86 | } | ||
52 | 87 | | |||
53 | Plasmoid.onActivated: activate() | 88 | TaskManager.TasksModel { | ||
89 | id: tasksModel | ||||
90 | sortMode: TaskManager.TasksModel.SortDisabled | ||||
91 | groupMode: TaskManager.TasksModel.GroupDisabled | ||||
92 | } | ||||
54 | 93 | | |||
55 | MinimizeAll { | 94 | Connections { | ||
56 | id: minimizeall | 95 | target: tasksModel | ||
96 | enabled: root.active | ||||
97 | onDataChanged: { | ||||
98 | for (var i = topLeft.row; i <= bottomRight.row ; i++) { | ||||
99 | var idx = tasksModel.makeModelIndex(i); | ||||
100 | if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { | ||||
101 | deactivate(); | ||||
102 | } | ||||
103 | } | ||||
104 | } | ||||
105 | onVirtualDesktopChanged: deactivate() | ||||
106 | onActivityChanged: deactivate() | ||||
57 | } | 107 | } | ||
58 | 108 | | |||
59 | PlasmaCore.FrameSvgItem { | 109 | PlasmaCore.FrameSvgItem { | ||
60 | id: expandedItem | 110 | id: expandedItem | ||
61 | anchors.fill: parent | 111 | anchors.fill: parent | ||
62 | imagePath: "widgets/tabbar" | 112 | imagePath: "widgets/tabbar" | ||
63 | prefix: { | 113 | prefix: { | ||
64 | var prefix; | 114 | var prefix; | ||
Show All 10 Lines | 115 | switch (plasmoid.location) { | |||
75 | default: | 125 | default: | ||
76 | prefix = "south-active-tab"; | 126 | prefix = "south-active-tab"; | ||
77 | } | 127 | } | ||
78 | if (!hasElementPrefix(prefix)) { | 128 | if (!hasElementPrefix(prefix)) { | ||
79 | prefix = "active-tab"; | 129 | prefix = "active-tab"; | ||
80 | } | 130 | } | ||
81 | return prefix; | 131 | return prefix; | ||
82 | } | 132 | } | ||
83 | opacity: minimizeall.active ? 1 : 0 | 133 | opacity: root.active ? 1 : 0 | ||
84 | Behavior on opacity { | 134 | Behavior on opacity { | ||
85 | NumberAnimation { | 135 | NumberAnimation { | ||
86 | duration: units.shortDuration | 136 | duration: units.shortDuration | ||
87 | easing.type: Easing.InOutQuad | 137 | easing.type: Easing.InOutQuad | ||
88 | } | 138 | } | ||
89 | } | 139 | } | ||
90 | } | 140 | } | ||
91 | 141 | | |||
Show All 9 Lines | 149 | PlasmaCore.ToolTipArea { | |||
101 | anchors.fill: parent | 151 | anchors.fill: parent | ||
102 | mainText : i18n("Minimize Windows") | 152 | mainText : i18n("Minimize Windows") | ||
103 | subText : i18n("Show the desktop by minimizing all windows") | 153 | subText : i18n("Show the desktop by minimizing all windows") | ||
104 | icon : plasmoid.configuration.icon | 154 | icon : plasmoid.configuration.icon | ||
105 | 155 | | |||
106 | MouseArea { | 156 | MouseArea { | ||
107 | id: mouseArea | 157 | id: mouseArea | ||
108 | anchors.fill: parent | 158 | anchors.fill: parent | ||
109 | onClicked: activate() | 159 | onClicked: root.toggleActive() | ||
110 | } | 160 | } | ||
111 | //also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop | 161 | //also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop | ||
112 | DropArea { | 162 | DropArea { | ||
113 | anchors.fill: parent | 163 | anchors.fill: parent | ||
114 | onEntered: activateTimer.start() | 164 | onEntered: activateTimer.start() | ||
115 | onExited: activateTimer.stop() | 165 | onExited: activateTimer.stop() | ||
116 | Timer { | 166 | Timer { | ||
117 | id: activateTimer | 167 | id: activateTimer | ||
118 | interval: 250 //to match TaskManager | 168 | interval: 250 //to match TaskManager | ||
119 | onTriggered: activate() | 169 | onTriggered: toggleActive() | ||
120 | } | 170 | } | ||
121 | } | 171 | } | ||
122 | } | 172 | } | ||
123 | } | 173 | } |
This method does not exist, did you forget to commit the plasma-workspace part?