refactor: replace DragHandler with MouseArea for app dragging#655
Conversation
Reviewer's GuideThis refactor replaces the custom DragHandler and multiple TapHandlers with a unified MouseArea to handle drag activation, click events, and state binding, simplifying drag logic and eliminating complex state management. Sequence diagram for unified drag and click handling with MouseAreasequenceDiagram
participant User as actor
participant MouseArea
participant ItemDelegate
participant Drag
participant ItemBackground
User->>MouseArea: Press (LeftButton)
MouseArea->>ItemDelegate: grabToImage()
ItemDelegate->>Drag: Set imageSource
MouseArea->>ItemBackground: Hide background
User->>MouseArea: Click (RightButton)
MouseArea->>ItemDelegate: showContextMenu()
MouseArea->>ItemBackground: Show background
User->>MouseArea: Click (LeftButton)
MouseArea->>ItemDelegate: launchApp(desktopId)
Class diagram for refactored drag and click handling in AppListView.qmlclassDiagram
class ItemDelegate {
Drag : DragAttached
MouseArea : MouseArea
ItemBackground : ItemBackground
}
class DragAttached {
+active : bool
+dragType : enum
+mimeData : object
+hotSpot : point
+imageSource : url
}
class MouseArea {
+acceptedButtons : enum
+drag : object
+onPressed(mouse)
+onClicked(mouse)
+enabled : bool
}
class ItemBackground {
+focusPolicy : enum
+implicitWidth : int
+implicitHeight : int
+button : ItemDelegate
}
ItemDelegate --> DragAttached : Drag
ItemDelegate --> MouseArea : MouseArea
ItemDelegate --> ItemBackground : background
MouseArea --> ItemDelegate : drag.target
ItemBackground --> ItemDelegate : button
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `qml/windowed/AppListView.qml:238-239` </location>
<code_context>
+ if (mouse.button === Qt.RightButton) {
+ showContextMenu(itemDelegate, model)
+ baseLayer.focus = true
+ } else {
+ launchApp(desktopId)
+ }
}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Launching app on non-right click may trigger unintended launches.
Restrict the launchApp call to left mouse button clicks to prevent unintended launches from other buttons.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } else { | ||
| launchApp(desktopId) |
There was a problem hiding this comment.
suggestion (bug_risk): Launching app on non-right click may trigger unintended launches.
Restrict the launchApp call to left mouse button clicks to prevent unintended launches from other buttons.
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 的需求修复了潜在的崩溃问题
2aea012 to
373f4c1
Compare
deepin pr auto review代码审查报告Helper.qml
AppListView.qml
FreeSortListView.qml
ItemBackground.qml
总体建议
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: behind) |
refactor: 使用 MouseArea 替换 DragHandler 处理应用拖拽
PMS: BUG-303989
Summary by Sourcery
Refactor app dragging implementation to use MouseArea instead of DragHandler, simplifying drag control, unifying click handling, improving drag visuals, and eliminating crash potential
Bug Fixes:
Enhancements: