forked from linuxdeepin/dde-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.qml
More file actions
271 lines (246 loc) · 11.8 KB
/
TaskManager.qml
File metadata and controls
271 lines (246 loc) · 11.8 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15
import org.deepin.ds 1.0
import org.deepin.ds.dock 1.0
import org.deepin.ds.dock.taskmanager 1.0
import org.deepin.dtk 1.0 as D
ContainmentItem {
id: taskmanager
property bool useColumnLayout: Panel.rootObject.useColumnLayout
property int dockOrder: 16
property real remainingSpacesForTaskManager: Panel.itemAlignment === Dock.LeftAlignment ? Panel.rootObject.dockLeftSpaceForCenter : Panel.rootObject.dockRemainingSpaceForCenter
readonly property int appTitleSpacing: Math.max(10, Math.round(Panel.rootObject.dockItemMaxSize * 9 / 14) / 3)
property real remainingSpacesForSplitWindow: Panel.rootObject.dockLeftSpaceForCenter - (
(Panel.rootObject.dockCenterPartCount - 1) * (visualModel.cellWidth + appTitleSpacing) + (Panel.rootObject.dockCenterPartCount) * Panel.rootObject.dockPartSpacing)
// 用于居中计算的实际应用区域尺寸
property int appContainerWidth: useColumnLayout ? Panel.rootObject.dockSize : appContainer.implicitWidth
property int appContainerHeight: useColumnLayout ? appContainer.implicitHeight : Panel.rootObject.dockSize
implicitWidth: useColumnLayout ? Panel.rootObject.dockSize : Math.max(remainingSpacesForTaskManager, appContainer.implicitWidth)
implicitHeight: useColumnLayout ? Math.max(remainingSpacesForTaskManager, appContainer.implicitHeight) : Panel.rootObject.dockSize
// Helper function to find the current index of an app by its appId in the visualModel
function findAppIndex(appId) {
for (let i = 0; i < visualModel.items.count; i++) {
const item = visualModel.items.get(i);
if (item.model.itemId === appId) {
return item.itemsIndex
}
}
return -1
}
// Helper function to find the current index by window ID (for windowSplit mode)
function findAppIndexByWindow(appId, winId) {
if (!winId) return findAppIndex(appId)
for (let i = 0; i < visualModel.items.count; i++) {
const item = visualModel.items.get(i);
if (item.model.itemId === appId && item.model.windows.length > 0 && item.model.windows[0] === winId) {
return item.itemsIndex
}
}
return -1
}
function blendColorAlpha(fallback) {
var appearance = DS.applet("org.deepin.ds.dde-appearance")
if (!appearance || appearance.opacity < 0)
return fallback
return appearance.opacity
}
property real blendOpacity: blendColorAlpha(D.DTK.themeType === D.ApplicationHelper.DarkType ? 0.25 : 1.0)
TextCalculator {
id: textCalculator
enabled: taskmanager.Applet.windowSplit && (Panel.position == Dock.Bottom || Panel.position == Dock.Top)
dataModel: taskmanager.Applet.dataModel
iconSize: Panel.rootObject.dockItemMaxSize * 9 / 14
spacing: appContainer.spacing
cellSize: visualModel.cellWidth
itemPadding: 4
remainingSpace: taskmanager.remainingSpacesForSplitWindow
font.family: D.DTK.fontManager.t6.family
font.pixelSize: Math.max(10, Math.min(20, Math.round(textCalculator.iconSize * 0.35)))
}
OverflowContainer {
id: appContainer
anchors.fill: parent
useColumnLayout: taskmanager.useColumnLayout
spacing: 0
remove: Transition {
NumberAnimation {
properties: "scale,opacity"
from: 1
to: 0
duration: 200
}
}
model: DelegateModel {
id: visualModel
model: taskmanager.Applet.dataModel
// 1:4 the distance between app : dock height; get width/height≈0.8
property real cellWidth: Panel.rootObject.dockItemMaxSize * 0.8
delegate: Item {
id: delegateRoot
required property int index
required property bool active
required property bool attention
required property string itemId
required property string name
required property string title // winTitle
required property string iconName
required property string icon // winIconName
required property string menus
required property list<string> windows
z: attention ? -1 : 0
property bool visibility: {
let draggedAppId = taskmanager.Applet.desktopIdToAppId(launcherDndDropArea.launcherDndDesktopId)
if (itemId !== draggedAppId) {
return true
}
return windows.length > 0 && launcherDndDropArea.launcherDndWinId !== windows[0]
}
ListView.onAdd: NumberAnimation {
target: delegateRoot
properties: "scale,opacity"
from: 0
to: 1
duration: 200
}
states: [
State {
name: "item-visible"
when: delegateRoot.visibility
PropertyChanges { target: delegateRoot; opacity: 1.0; scale: 1.0; }
},
State {
name: "item-invisible"
when: !delegateRoot.visibility
PropertyChanges { target: delegateRoot; opacity: 0.0; scale: 0.0; }
}
]
Behavior on opacity { NumberAnimation { duration: 200 } }
Behavior on scale { NumberAnimation { duration: 200 } }
implicitWidth: useColumnLayout ? taskmanager.implicitWidth : appItem.implicitWidth
implicitHeight: useColumnLayout ? visualModel.cellWidth : taskmanager.implicitHeight
property int visualIndex: DelegateModel.itemsIndex
property var modelIndex: visualModel.modelIndex(index)
Rectangle {
// kept for debug purpose
// border.color: "red"
// border.width: 1
color: "transparent"
parent: appContainer
x: delegateRoot.x
y: delegateRoot.y
width: delegateRoot.width
height: delegateRoot.height
scale: delegateRoot.scale
Behavior on x {
NumberAnimation {
duration: 200
easing.type: Easing.OutCubic
}
}
Behavior on y {
NumberAnimation {
duration: 200
easing.type: Easing.OutCubic
}
}
AppItem {
id: appItem
anchors.fill: parent // This is mandatory for draggable item center in drop area
displayMode: Panel.indicatorStyle
colorTheme: Panel.colorTheme
active: delegateRoot.active
attention: delegateRoot.attention
itemId: delegateRoot.itemId
name: delegateRoot.name
iconName: delegateRoot.iconName
menus: delegateRoot.menus
windows: delegateRoot.windows
visualIndex: delegateRoot.visualIndex
modelIndex: delegateRoot.modelIndex
blendOpacity: taskmanager.blendOpacity
title: delegateRoot.title
enableTitle: textCalculator.enabled
appTitleSpacing: taskmanager.appTitleSpacing
ListView.delayRemove: Drag.active
Component.onCompleted: {
dropFilesOnItem.connect(taskmanager.Applet.dropFilesOnItem)
}
onDragFinished: function() {
launcherDndDropArea.resetDndState()
}
}
}
}
}
DropArea {
id: launcherDndDropArea
anchors.fill: parent
z: 3
keys: ["text/x-dde-dock-dnd-appid"]
property string launcherDndDesktopId: ""
property string launcherDndDragSource: ""
property string launcherDndWinId: ""
function resetDndState() {
launcherDndDesktopId = ""
launcherDndDragSource = ""
launcherDndWinId = ""
}
onEntered: function(drag) {
let desktopId = drag.getDataAsString("text/x-dde-dock-dnd-appid")
launcherDndDragSource = drag.getDataAsString("text/x-dde-dock-dnd-source")
launcherDndWinId = drag.getDataAsString("text/x-dde-dock-dnd-winid")
launcherDndDesktopId = desktopId
if (launcherDndDragSource !== "taskbar" && taskmanager.Applet.requestDockByDesktopId(desktopId) === false) {
resetDndState()
}
}
onPositionChanged: function(drag) {
if (launcherDndDesktopId === "") return
let targetIndex = appContainer.indexAt(drag.x, drag.y)
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
let currentIndex = taskmanager.Applet.windowSplit ? taskmanager.findAppIndexByWindow(appId, launcherDndWinId) : taskmanager.findAppIndex(appId)
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
if (taskmanager.Applet.windowSplit) {
taskmanager.Applet.moveItem(currentIndex, targetIndex)
} else {
visualModel.items.move(currentIndex, targetIndex)
}
}
}
onDropped: function(drop) {
Panel.contextDragging = false
if (launcherDndDesktopId === "") return
let targetIndex = appContainer.indexAt(drop.x, drop.y)
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
let currentIndex = taskmanager.Applet.windowSplit ? taskmanager.findAppIndexByWindow(appId, launcherDndWinId) : taskmanager.findAppIndex(appId)
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
if (taskmanager.Applet.windowSplit) {
taskmanager.Applet.moveItem(currentIndex, targetIndex)
} else {
visualModel.items.move(currentIndex, targetIndex)
}
}
let appIds = []
for (let i = 0; i < visualModel.items.count; i++) {
appIds.push(visualModel.items.get(i).model.itemId)
}
taskmanager.Applet.saveDockElementsOrder(appIds)
resetDndState()
}
onExited: function() {
if (launcherDndDesktopId !== "" && launcherDndDragSource !== "taskbar") {
taskmanager.Applet.requestUndockByDesktopId(launcherDndDesktopId)
}
resetDndState()
}
}
}
Component.onCompleted: {
Panel.rootObject.dockItemMaxSize = Qt.binding(function(){
return Math.min(Panel.rootObject.dockSize, Panel.rootObject.dockLeftSpaceForCenter * 1.2 / (Panel.rootObject.dockCenterPartCount - 1 + visualModel.count) - 2)
})
}
}