Skip to content

Commit

Permalink
refactor: use DropArea for each item on FullscreenFrame
Browse files Browse the repository at this point in the history
为全屏模式下的拖拽支持准备,为每个 Item 提供一个 DropArea 用于接受拖
拽。此方式即不再需要通过顶层查找的方式来通过鼠标位置定位 item 是哪个。

Log:
  • Loading branch information
BLumia committed Nov 22, 2023
1 parent f152e93 commit 7c363bb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
89 changes: 46 additions & 43 deletions qml/FullscreenFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ Control {
topPadding: (DesktopIntegration.dockPosition === Qt.UpArrow ? DesktopIntegration.dockGeometry.height : 0) + 20
bottomPadding: (DesktopIntegration.dockPosition === Qt.DownArrow ? DesktopIntegration.dockGeometry.height : 0) + 20

// ----------- Drag and Drop related functions START -----------
Label {
id: dndDebug
visible: DebugHelper.qtDebugEnabled
text: "DnD DEBUG"
}

function dropOnItem(dragId, dropId, op) {
dndDebug.text = "drag " + dragId + " onto " + dropId + " with " + op
MultipageProxyModel.commitDndOperation(dragId, dropId, op)
}
// ----------- Drag and Drop related functions END -----------

Timer {
id: flipPageDelay
interval: 400
Expand Down Expand Up @@ -149,10 +162,9 @@ Control {
delegate: IconItemDelegate {
dndEnabled: false
Drag.mimeData: {
"application/x-dde-launcher-dnd-fullscreen": ("0," + modelData + "," + index), // "folder,page,index"
"application/x-dde-launcher-dnd-desktopId": model.desktopId
}
visible: model.desktopId !== dropArea.currentDraggedDesktopId
visible: !Drag.active
iconSource: "image://app-icon/" + iconName
width: gridViewContainer.cellSize
height: gridViewContainer.cellSize
Expand All @@ -172,6 +184,20 @@ Control {
onMenuTriggered: {
showContextMenu(this, model, folderIcons, false, true)
}
DropArea {
anchors.fill: parent
onDropped: {
let dragId = drop.getDataAsString("application/x-dde-launcher-dnd-desktopId")
let op = 0
let sideOpPadding = width / 4
if (drop.x < sideOpPadding) {
op = -1
} else if (drop.x > (width - sideOpPadding)) {
op = 1
}
dropOnItem(dragId, model.desktopId, op)
}
}
}
}
}
Expand Down Expand Up @@ -240,47 +266,6 @@ Control {
}
}

DropArea {
id: dropArea
anchors.fill: parent

property string currentDraggedDesktopId: ""

onPositionChanged: {
currentDraggedDesktopId = drag.getDataAsString("application/x-dde-launcher-dnd-desktopId")
dndDebug.text = drag.x + "," + drag.y + "." + drag.getDataAsString("application/x-dde-launcher-dnd-desktopId")
}

onDropped: {
let curGridView = pages.currentItem.item.grids
let curPoint = curGridView.mapFromItem(dropArea, drag.x, drag.y)
let curItem = curGridView.itemAt(curPoint.x, curPoint.y)
if (curItem) {
// drop on the left, center or right?
let itemX = curGridView.mapFromItem(curItem.parent, curItem.x, curItem.y).x
let itemWidth = curItem.width
let sideOpPadding = itemWidth / 4
let op = 0
if (curPoint.x < (itemX + sideOpPadding)) {
op = -1
} else if (curPoint.x > (itemX + curItem.width - sideOpPadding)) {
op = 1
}

let targetItemInfo = curItem.Drag.mimeData["application/x-dde-launcher-dnd-desktopId"]
dndDebug.text = "drag " + currentDraggedDesktopId + " onto " + targetItemInfo + " with " + op
MultipageProxyModel.commitDndOperation(currentDraggedDesktopId, targetItemInfo, op)
}
currentDraggedDesktopId = ""
}

Label {
id: dndDebug
visible: DebugHelper.qtDebugEnabled
text: "DnD DEBUG"
}
}

Popup {
id: folderGridViewPopup

Expand Down Expand Up @@ -365,6 +350,10 @@ Control {
activeGridViewFocusOnTab: folderGridViewLoader.SwipeView.isCurrentItem
delegate: IconItemDelegate {
dndEnabled: false
Drag.mimeData: {
"application/x-dde-launcher-dnd-desktopId": model.desktopId
}
visible: !Drag.active
iconSource: "image://app-icon/" + iconName
width: folderGridViewContainer.cellSize
height: folderGridViewContainer.cellSize
Expand All @@ -375,6 +364,20 @@ Control {
onMenuTriggered: {
showContextMenu(this, model, false, false, true)
}
DropArea {
anchors.fill: parent
onDropped: {
let dragId = drop.getDataAsString("application/x-dde-launcher-dnd-desktopId")
let op = 0
let sideOpPadding = width / 4
if (drop.x < sideOpPadding) {
op = -1
} else if (drop.x > (width - sideOpPadding)) {
op = 1
}
dropOnItem(dragId, model.desktopId, op)
}
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions qml/IconItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ Control {
}
}

HoverHandler {
id: stylus
}

DragHandler {
id: dragHandler
enabled: root.dndEnabled
Expand Down

0 comments on commit 7c363bb

Please sign in to comment.