Changeset View
Changeset View
Standalone View
Standalone View
applets/minimizeall/package/contents/ui/main.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2015 Sebastian Kügler <sebas@kde.org> | ||||
3 | * Copyright 2016 Anthony Fieroni <bvbfan@abv.bg> | ||||
4 | * Copyright 2018 David Edmundson <davidedmundson@kde.org> | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or modify | ||||
7 | * it under the terms of the GNU General Public License as published by | ||||
8 | * the Free Software Foundation; either version 2 of the License, or | ||||
9 | * (at your option) any later version. | ||||
10 | * | ||||
11 | * This program is distributed in the hope that it will be useful, | ||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | * GNU General Public License for more details. | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU General Public License along | ||||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
19 | */ | ||||
20 | | ||||
21 | import QtQuick 2.7 | ||||
22 | import QtQuick.Layouts 1.1 | ||||
23 | | ||||
24 | import org.kde.plasma.plasmoid 2.0 | ||||
25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
26 | | ||||
27 | import org.kde.taskmanager 0.1 as TaskManager | ||||
28 | | ||||
29 | Item { | ||||
30 | id: root | ||||
31 | | ||||
32 | readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge | ||||
33 | || plasmoid.location === PlasmaCore.Types.RightEdge | ||||
34 | || plasmoid.location === PlasmaCore.Types.BottomEdge | ||||
35 | || plasmoid.location === PlasmaCore.Types.LeftEdge) | ||||
36 | | ||||
37 | Layout.minimumWidth: units.gridUnit | ||||
38 | Layout.minimumHeight: units.gridUnit | ||||
39 | | ||||
40 | Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1 | ||||
41 | Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1 | ||||
42 | | ||||
43 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | ||||
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 | | ||||
50 | function activate() { | ||||
51 | var clients = [] | ||||
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)); | ||||
57 | } | ||||
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(); | ||||
83 | } else { | ||||
84 | activate(); | ||||
85 | } | ||||
86 | } | ||||
87 | | ||||
88 | TaskManager.TasksModel { | ||||
89 | id: tasksModel | ||||
90 | sortMode: TaskManager.TasksModel.SortDisabled | ||||
91 | groupMode: TaskManager.TasksModel.GroupDisabled | ||||
92 | } | ||||
93 | | ||||
94 | Connections { | ||||
95 | target: tasksModel | ||||
96 | enabled: root.active | ||||
97 | | ||||
98 | onActiveTaskChanged: { | ||||
99 | if (tasksModel.activeTask.valid) { //to suppress changing focus to non windows, such as the desktop | ||||
100 | root.active = false; | ||||
101 | root.minimizedClients = []; | ||||
102 | } | ||||
103 | } | ||||
104 | onVirtualDesktopChanged: deactivate() | ||||
105 | onActivityChanged: deactivate() | ||||
106 | } | ||||
107 | | ||||
108 | PlasmaCore.FrameSvgItem { | ||||
109 | id: expandedItem | ||||
110 | anchors.fill: parent | ||||
111 | imagePath: "widgets/tabbar" | ||||
112 | prefix: { | ||||
113 | var prefix; | ||||
114 | switch (plasmoid.location) { | ||||
115 | case PlasmaCore.Types.LeftEdge: | ||||
116 | prefix = "west-active-tab"; | ||||
117 | break; | ||||
118 | case PlasmaCore.Types.TopEdge: | ||||
119 | prefix = "north-active-tab"; | ||||
120 | break; | ||||
121 | case PlasmaCore.Types.RightEdge: | ||||
122 | prefix = "east-active-tab"; | ||||
123 | break; | ||||
124 | default: | ||||
125 | prefix = "south-active-tab"; | ||||
126 | } | ||||
127 | if (!hasElementPrefix(prefix)) { | ||||
128 | prefix = "active-tab"; | ||||
129 | } | ||||
130 | return prefix; | ||||
131 | } | ||||
132 | opacity: root.active ? 1 : 0 | ||||
133 | Behavior on opacity { | ||||
134 | NumberAnimation { | ||||
135 | duration: units.shortDuration | ||||
136 | easing.type: Easing.InOutQuad | ||||
137 | } | ||||
138 | } | ||||
139 | } | ||||
140 | | ||||
141 | PlasmaCore.IconItem { | ||||
142 | id:icon | ||||
143 | source: plasmoid.configuration.icon | ||||
144 | active: tooltip.containsMouse | ||||
145 | anchors.fill: parent | ||||
146 | } | ||||
147 | | ||||
148 | PlasmaCore.ToolTipArea { | ||||
149 | id: tooltip | ||||
150 | anchors.fill: parent | ||||
151 | mainText : i18n("Minimize Windows") | ||||
152 | subText : i18n("Show the desktop by minimizing all windows") | ||||
153 | icon : plasmoid.configuration.icon | ||||
154 | | ||||
155 | MouseArea { | ||||
156 | id: mouseArea | ||||
157 | anchors.fill: parent | ||||
158 | onClicked: root.toggleActive() | ||||
159 | } | ||||
160 | //also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop | ||||
161 | DropArea { | ||||
162 | anchors.fill: parent | ||||
163 | onEntered: activateTimer.start() | ||||
164 | onExited: activateTimer.stop() | ||||
165 | Timer { | ||||
166 | id: activateTimer | ||||
167 | interval: 250 //to match TaskManager | ||||
168 | onTriggered: toggleActive() | ||||
169 | } | ||||
170 | } | ||||
171 | } | ||||
172 | } |