forked from linuxdeepin/dde-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppItem.qml
More file actions
357 lines (321 loc) · 12.1 KB
/
AppItem.qml
File metadata and controls
357 lines (321 loc) · 12.1 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// SPDX-FileCopyrightText: 2023 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.dtk 1.0 as D
import Qt.labs.platform 1.1 as LP
Item {
id: root
required property int displayMode
required property int colorTheme
required property bool active
required property bool attention
required property string itemId
required property string name
required property string iconName
required property string menus
required property list<string> windows
required property int visualIndex
signal clickItem(itemId: string, menuId: string)
signal dragFinished()
Drag.active: mouseArea.drag.active
Drag.source: root
Drag.hotSpot.x: icon.width / 2
Drag.hotSpot.y: icon.height / 2
Drag.dragType: Drag.Automatic
Drag.mimeData: { "text/x-dde-dock-dnd-appid": itemId }
property bool useColumnLayout: Panel.position % 2
property int statusIndicatorSize: useColumnLayout ? root.width * 0.72 : root.height * 0.72
property real iconScale: Panel.rootObject.dockItemMaxSize * 9 / 14 / Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE
property var iconGlobalPoint: {
var a = icon
var x = 0, y = 0
while(a.parent) {
x += a.x
y += a.y
a = a.parent
}
return Qt.point(x, y)
}
Item {
anchors.fill: parent
id: appItem
visible: !root.Drag.active // When in dragging, hide app item
AppItemPalette {
id: itemPalette
displayMode: root.displayMode
colorTheme: root.colorTheme
active: root.active
backgroundColor: D.DTK.palette.highlight
}
StatusIndicator {
id: statusIndicator
palette: itemPalette
width: root.statusIndicatorSize
height: root.statusIndicatorSize
anchors.centerIn: icon
visible: root.displayMode === Dock.Efficient && root.windows.length > 0
}
WindowIndicator {
id: windowIndicator
dotWidth: root.useColumnLayout ? Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 16, 2) : Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 3, 2)
dotHeight: root.useColumnLayout ? Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 3, 2) : Math.max(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale / 16, 2)
windows: root.windows
displayMode: root.displayMode
useColumnLayout: root.useColumnLayout
palette: itemPalette
visible: (root.displayMode === Dock.Efficient && root.windows.length > 1) || (root.displayMode === Dock.Fashion && root.windows.length > 0)
function updateIndicatorAnchors() {
windowIndicator.anchors.top = undefined
windowIndicator.anchors.topMargin = 0
windowIndicator.anchors.bottom = undefined
windowIndicator.anchors.bottomMargin = 0
windowIndicator.anchors.left = undefined
windowIndicator.anchors.leftMargin = 0
windowIndicator.anchors.right = undefined
windowIndicator.anchors.rightMargin = 0
windowIndicator.anchors.horizontalCenter = undefined
windowIndicator.anchors.verticalCenter = undefined
let fixedDistance = 2
if (Panel.position === Dock.Top || Panel.position === Dock.Bottom) {
fixedDistance = (root.height - Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale) / 2 / 3
} else {
fixedDistance = (root.width - Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE * iconScale) / 2 / 3
}
switch(Panel.position) {
case Dock.Top: {
windowIndicator.anchors.horizontalCenter = parent.horizontalCenter
windowIndicator.anchors.top = parent.top
windowIndicator.anchors.topMargin = fixedDistance
return
}
case Dock.Bottom: {
windowIndicator.anchors.horizontalCenter = parent.horizontalCenter
windowIndicator.anchors.bottom = parent.bottom
windowIndicator.anchors.bottomMargin = fixedDistance
return
}
case Dock.Left: {
windowIndicator.anchors.verticalCenter = parent.verticalCenter
windowIndicator.anchors.left = parent.left
windowIndicator.anchors.leftMargin = fixedDistance
return
}
case Dock.Right:{
windowIndicator.anchors.verticalCenter = parent.verticalCenter
windowIndicator.anchors.right = parent.right
windowIndicator.anchors.rightMargin = fixedDistance
return
}
}
}
Component.onCompleted: {
windowIndicator.updateIndicatorAnchors()
}
}
Connections {
function onPositionChanged() {
windowIndicator.updateIndicatorAnchors()
updateWindowIconGeometryTimer.start()
}
target: Panel
}
Loader {
id: contextMenuLoader
active: false
sourceComponent: LP.Menu {
id: contextMenu
Instantiator {
id: menuItemInstantiator
model: JSON.parse(menus)
delegate: LP.MenuItem {
text: modelData.name
onTriggered: {
root.clickItem(root.itemId, modelData.id)
}
}
onObjectAdded: (index, object) => contextMenu.insertItem(index, object)
onObjectRemoved: (index, object) => contextMenu.removeItem(object)
}
}
}
D.DciIcon {
id: icon
name: root.iconName
sourceSize: Qt.size(Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE, Dock.MAX_DOCK_TASKMANAGER_ICON_SIZE)
anchors.centerIn: parent
scale: iconScale
BeatAnimation {
id: beatAnimation
target: icon
baseScale: iconScale
loops: Animation.Infinite
running: root.attention
}
LaunchAnimation {
id: launchAnimation
launchSpace: {
switch (Panel.position) {
case Dock.Top:
case Dock.Bottom:
// todo: use icon.height * iconScale is not good
return (root.height - icon.height * iconScale) / 2
case Dock.Left:
case Dock.Right:
return (root.width - icon.width * iconScale) / 2
}
}
direction: {
switch (Panel.position) {
case Dock.Top:
return LaunchAnimation.Direction.Down
case Dock.Bottom:
return LaunchAnimation.Direction.Up
case Dock.Left:
return LaunchAnimation.Direction.Right
case Dock.Right:
return LaunchAnimation.Direction.Left
}
}
target: icon
loops: 1
running: false
}
Connections {
target: Panel.rootObject
function onPressedAndDragging(isDragging) {
if (isDragging) {
beatAnimation.stop()
icon.scale = Qt.binding(function() {
return root.iconScale
})
} else {
beatAnimation.running = Qt.binding(function() {
return root.attention
})
}
}
}
}
}
Timer {
id: updateWindowIconGeometryTimer
interval: 500
running: false
repeat: false
onTriggered: {
var pos = icon.mapToItem(null, 0, 0)
taskmanager.Applet.setAppItemWindowIconGeometry(root.itemId, Panel.rootObject, pos.x, pos.y,
pos.x + icon.width * iconScale, pos.y + icon.height * iconScale)
}
}
Timer {
id: previewTimer
interval: 500
running: false
repeat: false
property int xOffset: 0
property int yOffset: 0
onTriggered: {
if (root.windows.length != 0 || Qt.platform.pluginName === "wayland") {
taskmanager.Applet.showItemPreview(root.itemId, Panel.rootObject, xOffset, yOffset, Panel.position)
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
drag.target: root
drag.onActiveChanged: {
if (!drag.active)
root.dragFinished()
}
onPressed: function (mouse) {
if (mouse.button === Qt.LeftButton) {
icon.grabToImage(function(result) {
root.Drag.imageSource = result.url;
})
}
toolTip.close()
closeItemPreview()
}
onClicked: function (mouse) {
if (mouse.button === Qt.RightButton) {
contextMenuLoader.active = true
MenuHelper.openMenu(contextMenuLoader.item)
} else {
if (root.windows.length === 0) {
launchAnimation.start()
}
root.clickItem(root.itemId, "")
}
}
onEntered: {
if (Qt.platform.pluginName === "xcb" && windows.length === 0) {
toolTipShowTimer.start()
return
}
var itemPos = root.mapToItem(null, 0, 0)
let xOffset, yOffset, interval = 10
if (Panel.position % 2 === 0) {
xOffset = itemPos.x + (root.width / 2)
yOffset = (Panel.position == 2 ? -interval : interval + Panel.dockSize)
} else {
xOffset = (Panel.position == 1 ? -interval : interval + Panel.dockSize)
yOffset = itemPos.y + (root.height / 2)
}
previewTimer.xOffset = xOffset
previewTimer.yOffset = yOffset
previewTimer.start()
}
onExited: {
if (toolTipShowTimer.running) {
toolTipShowTimer.stop()
}
if (previewTimer.running) {
previewTimer.stop()
}
if (Qt.platform.pluginName === "xcb" && windows.length === 0) {
toolTip.close()
return
}
closeItemPreview()
}
PanelToolTip {
id: toolTip
text: root.name
toolTipX: DockPanelPositioner.x
toolTipY: DockPanelPositioner.y
}
Timer {
id: toolTipShowTimer
interval: 50
onTriggered: {
var point = root.mapToItem(null, root.width / 2, root.height / 2)
toolTip.DockPanelPositioner.bounding = Qt.rect(point.x, point.y, toolTip.width, toolTip.height)
toolTip.open()
}
}
function closeItemPreview() {
if (previewTimer.running) {
previewTimer.stop()
} else {
taskmanager.Applet.hideItemPreview()
}
}
}
onWindowsChanged: {
updateWindowIconGeometryTimer.start()
}
onIconGlobalPointChanged: {
updateWindowIconGeometryTimer.start()
}
onIconScaleChanged: {
windowIndicator.updateIndicatorAnchors()
}
}