Skip to content

Commit 2aea012

Browse files
committed
refactor: replace DragHandler with MouseArea for app dragging
1. Replaced DragHandler with MouseArea for better drag control and simpler implementation 2. Changed drag state detection from dragHandler.active to drag.active 3. Simplified drag initialization by directly setting Drag.active from mouseArea 4. Removed complex state management and replaced with direct property binding 5. Combined left/right click handling in single MouseArea for cleaner code 6. Improved drag image handling by showing/hiding background during drag operation 7. Fixed potential crash issues by eliminating the need for external dndItem refactor: 使用 MouseArea 替换 DragHandler 处理应用拖拽 1. 使用 MouseArea 替换 DragHandler 以获得更好的拖拽控制和更简单的实现 2. 将拖拽状态检测从 dragHandler.active 改为 drag.active 3. 通过直接从 mouseArea 设置 Drag.active 简化了拖拽初始化 4. 移除了复杂的状态管理,改用直接属性绑定 5. 在单个 MouseArea 中合并左右键点击处理,代码更清晰 6. 改进了拖拽图像处理,在拖拽操作期间显示/隐藏背景 7. 通过消除对外部 dndItem 的需求修复了潜在的崩溃问题
1 parent d3f17a6 commit 2aea012

1 file changed

Lines changed: 29 additions & 53 deletions

File tree

qml/windowed/AppListView.qml

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ FocusScope {
165165
leftMargin: 10
166166
rightMargin: 10
167167
}
168-
visible: !dragHandler.active
168+
visible: !Drag.active
169169
text: model.display
170170
checkable: false
171171
icon.name: (iconName && iconName !== "") ? iconName : "application-x-desktop"
@@ -206,69 +206,45 @@ FocusScope {
206206
ToolTip.visible: hovered && contentItem.implicitWidth > contentItem.width
207207

208208
Drag.dragType: Drag.Automatic
209+
Drag.active: mouseArea.drag.active
209210
Drag.mimeData: Helper.generateDragMimeData(model.desktopId, true)
210211
Drag.hotSpot.y: height / 2
211212
Drag.hotSpot.x: width / 2
212213

213-
states: State {
214-
name: "dragged";
215-
when: dragHandler.active
216-
// FIXME: When dragging finished, the position of the item is changed for unknown reason,
217-
// so we use the state to reset the x and y here.
218-
PropertyChanges {
219-
target: dragHandler.target
220-
x: x
221-
y: y
222-
}
223-
}
224-
225-
TapHandler {
226-
acceptedButtons: Qt.RightButton
227-
onTapped: {
228-
showContextMenu(itemDelegate, model)
229-
baseLayer.focus = true
230-
}
231-
}
232-
233-
DragHandler {
234-
id: dragHandler
235-
target: parent
236-
acceptedButtons: Qt.LeftButton
237-
dragThreshold: 1
214+
MouseArea {
215+
id: mouseArea
216+
anchors.fill: parent
217+
218+
acceptedButtons: Qt.LeftButton | Qt.RightButton
219+
drag.target: itemDelegate
238220
// 当分类菜单打开时,禁用拖拽功能
239221
enabled: !(ddeCategoryMenu.visible || alphabetCategoryPopup.visible)
240-
onActiveChanged: {
241-
if (active) {
242-
// We switch to use the `dndItem` to handle Drag event since that one will always exists.
243-
// If we use the current item, then if the item that provides the drag attached property
244-
// get destoryed (e.g. switch page or folder close caused destory), dropping at that moment
245-
// will cause a crash.
246-
dndItem.Drag.hotSpot = target.Drag.hotSpot
247-
dndItem.Drag.mimeData = target.Drag.mimeData
248-
249-
parent.grabToImage(function(result) {
250-
dndItem.Drag.imageSource = result.url;
251-
dndItem.Drag.active = true
252-
dndItem.Drag.startDrag()
222+
223+
onPressed: function (mouse) {
224+
if (mouse.button === Qt.LeftButton) {
225+
bg.visible = false
226+
itemDelegate.grabToImage(function(result) {
227+
itemDelegate.Drag.imageSource = result.url
228+
bg.visible = Qt.binding(function() {
229+
return bg.ColorSelector.controlState === DTK.HoveredState
230+
})
253231
})
254232
}
255233
}
256-
}
257-
258-
background: Loader {
259-
active: !dragHandler.active
260-
sourceComponent: ItemBackground {
261-
focusPolicy: Qt.NoFocus
262-
implicitWidth: DStyle.Style.itemDelegate.width
263-
implicitHeight: Helper.windowed.listItemHeight
264-
button: itemDelegate
234+
onClicked: function (mouse) {
235+
if (mouse.button === Qt.RightButton) {
236+
showContextMenu(itemDelegate, model)
237+
baseLayer.focus = true
238+
} else {
239+
launchApp(desktopId)
240+
}
265241
}
266242
}
267-
268-
TapHandler {
269-
onTapped: {
270-
launchApp(desktopId)
271-
}
243+
background: ItemBackground {
244+
id: bg
245+
implicitWidth: DStyle.Style.itemDelegate.width
246+
implicitHeight: Helper.windowed.listItemHeight
247+
button: itemDelegate
272248
}
273249

274250
Keys.onReturnPressed: {

0 commit comments

Comments
 (0)