Skip to content

fix: correct mouse event handling area for icon items#724

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
18202781743:master
Mar 6, 2026
Merged

fix: correct mouse event handling area for icon items#724
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 6, 2026

  • fix: correct mouse event handling area for icon items
  • chore: bump version to 2.0.30

Summary by Sourcery

Adjust icon item mouse interaction area and update package version metadata.

Bug Fixes:

  • Correct the mouse interaction area for icon items to align with the full control instead of only the inner content.

Chores:

  • Bump the package version in the Debian changelog to 2.0.30.

The MouseArea was incorrectly placed inside the icon's contentItem,
causing mouse events to only be captured within the icon image area
rather than the entire delegate item. This led to poor user experience
where drag-and-drop and click operations only worked when clicking
directly on the icon image, not the surrounding area.

Moved the MouseArea from inside the icon's contentItem to be a direct
child of the Control's background. This ensures the MouseArea covers
the entire delegate area, making drag-and-drop and click operations work
consistently across the whole item surface.

Log: Fixed issue where drag-and-drop and click operations only worked
when clicking directly on app icons

Influence:
1. Test drag-and-drop functionality by clicking and dragging from any
area within app icon items
2. Verify click operations work consistently across entire icon item
surface
3. Test both normal clicks and drag operations to ensure they don't
interfere
4. Verify hover states and visual feedback work correctly
5. Test with various icon sizes and delegate configurations

fix: 修复图标项鼠标事件处理区域错误

MouseArea 原本错误地放置在图标 contentItem 内部,导致鼠标事件只能在图标
图像区域内被捕获,而不是在整个委托项区域内。这导致了糟糕的用户体验,拖放
和点击操作只有在直接点击图标图像时才有效,而不是在周围区域。

将 MouseArea 从图标的 contentItem 内部移动到 Control 背景的直接子元素。
这确保了 MouseArea 覆盖整个委托区域,使拖放和点击操作在整个项目表面上都
能一致工作。

Log: 修复了拖放和点击操作仅在直接点击应用图标时才有效的问题

Influence:
1. 通过从应用图标项的任何区域点击和拖动来测试拖放功能
2. 验证点击操作在整个图标项表面上都能一致工作
3. 测试正常点击和拖动操作,确保它们不会相互干扰
4. 验证悬停状态和视觉反馈正常工作
5. 使用各种图标大小和委托配置进行测试
update changelog to 2.0.30
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

TAG Bot

TAG: 2.0.30
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 6, 2026

Reviewer's Guide

Adjusts the MouseArea handling for icon items so it covers the entire control instead of just the icon, and updates the Debian package version to 2.0.30.

Sequence diagram for icon click vs drag with new MouseArea

sequenceDiagram
    actor User
    participant IconItemDelegate as IconItemDelegate
    participant MouseArea as mouseArea
    participant AppIconButton as appIcon
    participant Drag as Drag

    User->>MouseArea: press(leftButton)
    MouseArea->>IconItemDelegate: check dndEnabled
    alt dndEnabled and leftButton
        MouseArea->>AppIconButton: grabToImage(callback)
        AppIconButton-->>MouseArea: result(url)
        MouseArea->>Drag: set imageSource(result.url)
    end

    User-->>MouseArea: release(click)
    MouseArea->>MouseArea: onClicked()
    alt drag not active
        MouseArea->>IconItemDelegate: itemClicked()
    else drag active
        MouseArea-->>User: drag operation continues
    end
Loading

Class diagram for updated IconItemDelegate mouse handling

classDiagram
    class IconItemDelegate {
        +bool dndEnabled
        +void itemClicked()
    }

    class Control {
    }

    class MouseArea {
        +bool hoverEnabled
        +int acceptedButtons
        +bool enabled
        +object drag_target
        +void onPressed(mouse)
        +void onClicked()
    }

    class Column {
    }

    class AppIconButton {
        +void grabToImage(callback)
    }

    IconItemDelegate --|> Control

    IconItemDelegate *-- MouseArea : root_mouseArea
    IconItemDelegate *-- Column : contentItem
    Column *-- AppIconButton : appIcon

    %% Previous structure (for comparison of containment)
    class PreviousStructure {
    }

    PreviousStructure *-- AppIconButton : appIcon
    AppIconButton *-- MouseArea : icon_mouseArea

    %% New structure
    class NewStructure {
    }

    NewStructure *-- IconItemDelegate : root
    IconItemDelegate *-- MouseArea : mouseArea
    IconItemDelegate *-- AppIconButton : appIcon
Loading

File-Level Changes

Change Details Files
Reposition MouseArea so click/drag handling applies to the whole control rather than just the icon element.
  • Move MouseArea definition from inside the icon RowLayout to be a direct child of the Control, anchored to fill the entire parent.
  • Keep existing drag-and-drop logic using appIcon.grabToImage and root.Drag.imageSource in the new MouseArea location.
  • Retain click handling logic so itemClicked() is only invoked when a drag is not active.
qml/windowed/IconItemDelegate.qml
Update package version metadata.
  • Increment Debian changelog version to 2.0.30 to reflect the new release.
debian/changelog

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Now that the MouseArea is attached to the whole control rather than the icon, consider whether its enabled state should also depend on root.enabled (or similar) so it doesn’t react when the delegate is disabled but dndEnabled happens to be true.
  • With the MouseArea filling the parent, verify whether it unintentionally intercepts other mouse interactions (e.g., context menus or other buttons in the delegate) and, if so, consider constraining its anchors or using acceptedButtons/propagateComposedEvents to avoid blocking them.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that the MouseArea is attached to the whole control rather than the icon, consider whether its `enabled` state should also depend on `root.enabled` (or similar) so it doesn’t react when the delegate is disabled but `dndEnabled` happens to be true.
- With the MouseArea filling the parent, verify whether it unintentionally intercepts other mouse interactions (e.g., context menus or other buttons in the delegate) and, if so, consider constraining its `anchors` or using `acceptedButtons`/`propagateComposedEvents` to avoid blocking them.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码 diff 显示了对 dde-launchpad 项目中 IconItemDelegate.qml 文件的修改。主要改动是将 MouseAreacontentItem 内部移动到了 Control 的顶层(即 background 之前)。

以下是对这段代码的详细审查意见,包括语法逻辑、代码质量、性能和安全性方面:

1. 语法逻辑与代码逻辑

改进点:

  • 修复了事件处理区域(核心逻辑修正):

    • 原代码问题: 在原代码中,MouseArea 被放置在 contentItem 内部的 Column 布局中,并且它填充的是 appIcon(可能是 DciIcon)的区域。这意味着只有图标本身响应鼠标点击和拖拽。如果图标周围有文字标签(Label),或者图标未填满整个 Item 区域,点击这些非图标区域将无法触发点击或拖拽事件。
    • 新代码改进: 修改后,MouseArea 被移动到了 Control 的根层级下,使用 anchors.fill: parent 填充整个 IconItemDelegate 组件。这确保了用户点击图标项的任何位置(包括文字部分或空白边距)都能被正确捕获,从而触发 itemClicked 或拖拽操作。这与 changelog 中描述的 "correct mouse event handling area for icon items" 完全一致。
  • 逻辑一致性:

    • MouseArea 的逻辑(onPressed, onClicked, drag 属性)保持不变,这表明原有的事件处理逻辑是正确的,仅仅是位置放置不当导致了交互体验问题。移动位置后,逻辑依然成立且更加健壮。

2. 代码质量

改进点:

  • 结构清晰度: 将通用的交互层(MouseArea)从具体的展示层(contentItem / Column)中剥离出来,符合 QML 组件化的最佳实践。ControlbackgroundcontentItem 应主要负责视觉呈现,而交互逻辑通常应覆盖整个控件。

建议:

  • 命名冲突风险: MouseArea 的 ID 仍然是 mouseArea。虽然在新的作用域下没有问题,但如果代码其他地方有引用 contentItem.mouseArea,这会导致引用错误。不过 diff 中没有显示其他文件的修改,且通常内部 ID 不应被外部直接依赖,因此这通常是一个安全的重构。
  • z-order 顺序: 新代码中 MouseArea 位于 background 之前声明。在 QML 中,后声明的子项 z 轴顺序更高(覆盖在上面)。这意味着 background(如果有定义)可能会绘制在 MouseArea 之上。如果 background 包含可见内容且不透明,它可能会阻挡鼠标事件传递给 MouseArea
    • 审查建议: 请确认 Controlbackground 属性(在 diff 未显示的部分)是否仅为颜色填充或装饰性边框,且不处理鼠标事件。如果 background 是一个复杂的 Item,可能需要调整声明顺序或确保 background 不接收鼠标事件(如 acceptedButtons: Qt.NoButton)。

3. 代码性能

分析:

  • 渲染性能: 移动 MouseArea 本身不会显著影响渲染性能。
  • 事件处理性能: 事件处理逻辑没有变化。grabToImage 是一个相对昂贵的操作,因为它涉及截图和纹理生成。它仅在 onPressed 时触发,且仅在 dndEnabled 为真时执行,这是合理的。由于拖拽操作本身不是高频触发(不像鼠标移动),这里的性能开销是可以接受的。

4. 代码安全

分析:

  • 输入验证: 代码中使用了 root.dndEnabled 来控制 MouseAreaenabled 属性以及 onPressed 中的逻辑判断。这种双重检查是好的,防止了状态不一致时的意外行为。
  • 拖拽安全: drag.target: root 将整个控件设为拖拽目标。由于 MouseArea 现在覆盖了整个控件,拖拽交互会更加流畅和符合预期。

总结

这是一个高质量的修复补丁。

  1. 主要成就: 成功修复了图标项鼠标事件响应区域过小的问题,提升了用户体验。
  2. 代码结构: 将交互逻辑提升至组件顶层,结构更加合理。
  3. 风险点: 唯一需要注意的是 MouseAreabackground 的层级关系,确保 background 不会遮挡鼠标事件。

最终建议:
该修改可以合并。建议在测试阶段重点验证以下场景:

  1. 点击图标文字部分是否能正常打开应用。
  2. 在图标文字部分按下鼠标并拖拽,是否能正常开始拖拽。
  3. 如果该控件有自定义的 background(如悬停高亮背景),确保背景显示正常且不影响鼠标交互。

@18202781743 18202781743 changed the title master fix: correct mouse event handling area for icon items Mar 6, 2026
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, robertkill

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 6, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit c28015b into linuxdeepin:master Mar 6, 2026
9 checks passed
@deepin-bot
Copy link

deepin-bot bot commented Mar 6, 2026

TAG Bot

Tag created successfully

📋 Tag Details
  • Tag Name: 2.0.30
  • Tag SHA: cdf56f8e623034e818a1f47cb323c6388d5f40a1
  • Commit SHA: d4ef0036895b70a6e77bfe1bde22768aad5637d5
  • Tag Message:
    Release dde-launchpad 2.0.30
    
    
  • Tagger:
    • Name: 18202781743
  • Distribution: unstable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants