Skip to content

Commit b2f5046

Browse files
wjyrichBLumia
authored andcommitted
fix: when drag app to another app from folder,add animation and auto-move with folders.
as title. PMS-BUG-288847
1 parent 4520c31 commit b2f5046

3 files changed

Lines changed: 83 additions & 8 deletions

File tree

qml/FolderGridViewPopup.qml

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,35 @@ Popup {
274274

275275
MultipageSortFilterProxyModel {
276276
id: folderProxyModel
277+
filterOnlyMode: true
277278
sourceModel: ItemArrangementProxyModel
278279
pageId: modelData
279280
folderId: folderLoader.currentFolderId
280281
}
282+
283+
SortProxyModel {
284+
id: sortProxyModel
285+
sourceModel: folderProxyModel
286+
sortRole: ItemArrangementProxyModel.IndexInPageRole
287+
Component.onCompleted: {
288+
sortProxyModel.sort(0)
289+
}
290+
}
281291

282292
//gridViewContainer
283293
Loader {
284294
id: gridViewContainerLoader
285295
anchors.fill: parent
286-
287296
sourceComponent: isWindowedMode ? listViewGridViewContainer : fullScreenGridViewContainer
297+
298+
// Define common itemMove transition to avoid duplication
299+
property Transition itemMove: Transition {
300+
NumberAnimation {
301+
properties: "x,y"
302+
duration: 200
303+
easing.type: Easing.OutQuad
304+
}
305+
}
288306
}
289307

290308
Component {
@@ -295,13 +313,13 @@ Popup {
295313
anchors.fill: parent
296314
rows: 3
297315
columns: 4
298-
model: folderProxyModel
316+
model: sortProxyModel
299317
padding: 10
300318
interactive: false
301319
focus: true
302320
gridViewClip: false // TODO it maybe a bug for dtk, https://github.com/linuxdeepin/developer-center/issues/8468
303321
activeGridViewFocusOnTab: folderGridViewLoader.SwipeView.isCurrentItem
304-
itemMove: Transition { NumberAnimation { properties: "x,y"; duration: 250 } }
322+
itemMove: parent.itemMove
305323
delegate: DelegateDropArea {
306324
width: folderGridViewContainer.cellWidth
307325
height: folderGridViewContainer.cellHeight
@@ -316,14 +334,15 @@ Popup {
316334
anchors.fill: parent
317335
rows: 3
318336
columns: 4
319-
model: folderProxyModel
337+
model: sortProxyModel
320338
paddingRows: 6
321339
cellHeight: 86
322340
paddingColumns: 2
323341
interactive: false
324342
focus: true
325343
gridViewClip: false
326344
activeGridViewFocusOnTab: folderGridViewLoader.SwipeView.isCurrentItem
345+
itemMove: parent.itemMove
327346
delegate: DelegateDropArea {
328347
width: folderGridViewContainer.cellWidth
329348
height: folderGridViewContainer.cellHeight
@@ -332,7 +351,28 @@ Popup {
332351
}
333352

334353
component DelegateDropArea: DropArea {
354+
onEntered: function(drag) {
355+
folderDragApplyTimer.dragId = drag.getDataAsString("text/x-dde-launcher-dnd-desktopId")
356+
folderDragApplyTimer.restart()
357+
}
358+
onPositionChanged: function(drag) {
359+
let dragId = drag.getDataAsString("text/x-dde-launcher-dnd-desktopId")
360+
if (dragId === model.desktopId) {
361+
return
362+
}
363+
folderDragApplyTimer.dragId = dragId
364+
folderDragApplyTimer.currentDropX = drag.x
365+
if (!folderDragApplyTimer.running) {
366+
folderDragApplyTimer.restart()
367+
}
368+
}
369+
onExited: {
370+
folderDragApplyTimer.stop()
371+
folderDragApplyTimer.dragId = ""
372+
}
335373
onDropped: function(drop) {
374+
folderDragApplyTimer.stop()
375+
folderDragApplyTimer.dragId = ""
336376
let dragId = drop.getDataAsString("text/x-dde-launcher-dnd-desktopId")
337377
if (dragId === model.desktopId) {
338378
return
@@ -345,6 +385,29 @@ Popup {
345385
}
346386

347387
dropOnItem(dragId, model.desktopId, op)
388+
sortProxyModel.sort(0)
389+
}
390+
391+
Timer {
392+
id: folderDragApplyTimer
393+
interval: 500
394+
property string dragId: ""
395+
property real currentDropX: 0
396+
onTriggered: function() {
397+
if (dragId === "") return
398+
let op = 0
399+
let sideOpPadding = parent.width / 4
400+
if (currentDropX < sideOpPadding) {
401+
op = -1
402+
} else if (currentDropX > (parent.width - sideOpPadding)) {
403+
op = 1
404+
}
405+
// 只有在需要插入操作时才执行预览移动
406+
if (op !== 0) {
407+
dropOnItem(dragId, model.desktopId, op)
408+
sortProxyModel.sort(0)
409+
}
410+
}
348411
}
349412
Keys.forwardTo: [innerItem]
350413

qml/GridViewContainer.qml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,19 @@ FocusScope {
6868
Rectangle {
6969
anchors.centerIn: parent
7070
width: {
71-
if (root.objectName === "folderGridViewContainer")
72-
return model.rowCount() > root.columns - 1 ? item.cellWidth * root.columns : model.rowCount() * item.cellWidth
73-
else
71+
if (root.objectName === "folderGridViewContainer") {
72+
return item.cellWidth * root.columns + root.paddingColumns * Math.max(0, root.columns - 1) + root.paddingColumns
73+
} else {
7474
return item.cellWidth * root.columns
75+
}
76+
}
77+
height: {
78+
if (root.objectName === "folderGridViewContainer") {
79+
return item.cellHeight * root.rows + root.paddingColumns * Math.max(0, root.rows - 1)
80+
} else {
81+
return root.rows == 0 ? parent.height : (item.cellHeight * root.rows)
82+
}
7583
}
76-
height: rows == 0 ? parent.height : (item.cellHeight * root.rows)
7784
color: "transparent"
7885

7986
GridView {

qml/windowed/GridViewContainer.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ FocusScope {
3030
property int paddingRows: Helper.frequentlyUsed.cellPaddingRows
3131
property real cellHeight: 82
3232
property real cellWidth: 80
33+
property Transition itemMove
3334

3435
readonly property alias currentItem: gridView.currentItem
3536
readonly property alias gridViewWidth: gridView.width
@@ -84,6 +85,10 @@ FocusScope {
8485
cellHeight: root.cellHeight + paddingRows
8586
cellWidth: root.cellWidth + paddingColumns
8687

88+
displaced: root.itemMove
89+
move: root.itemMove
90+
moveDisplaced: root.itemMove
91+
8792
highlight: Item {
8893
FocusBoxBorder {
8994
anchors {

0 commit comments

Comments
 (0)