Skip to content

fix(editor): add hover and press states to color mark icons - #520

Open
tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:fix-196825-color-mark-states
Open

fix(editor): add hover and press states to color mark icons#520
tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:fix-196825-color-mark-states

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Aug 13, 2026

Copy link
Copy Markdown

根因分析

颜色标记图标 ColorLabelsrc/widgets/ColorSelectWdg.h:53-63)仅实现 m_bSelected 一个状态,缺失 hover 和 press 交互状态:

  • 构造函数虽调用了 setMouseTracking(true),但未重写 enterEvent()/leaveEvent()
  • mousePressEvent() 直接选中,无 press 过渡反馈
  • paintEvent() 只绘制默认圆/选中圆环两态

修复方案

ColorLabel 增加 m_bHover/m_bPressed 状态变量,重写 enterEvent()/leaveEvent()/mousePressEvent()/mouseReleaseEvent()paintEvent() 三分支渲染:press 态颜色加深+微缩,hover 态外扩,normal 保持原有逻辑。选中信号改为 release 触发(与 Qt 按钮标准行为一致)。

改动安全评估

低风险。ColorLabelColorSelectWdg 中的私有控件,无外部引用。新增 hover/press 属纯叠加性视觉增强,sigColorClicked 信号语义不变(仅触发时机从 press 改为 release),不破坏 ColorSelectWdg 的互斥选中逻辑。

PMS: BUG-196825

Summary by Sourcery

Enhance the color selection widget’s icon interactions by adding hover and press visual states and updating selection to trigger on mouse release.

New Features:

  • Introduce hover visual feedback for ColorLabel color mark icons.
  • Introduce press visual feedback for ColorLabel color mark icons with a distinct pressed appearance.

Enhancements:

  • Refine ColorLabel painting logic to support distinct normal, hover, and pressed states while preserving the existing selected state behavior.
  • Update ColorLabel mouse interaction handling to align selection emission with Qt’s standard release-based behavior.
  • Extend widget license headers to include years up to 2026.

ColorLabel widget only implements selected/unselected visual states,
missing hover and press feedback. This adds enterEvent/leaveEvent for
hover highlighting and mousePressEvent/mouseReleaseEvent for press
animation, improving interaction experience.

为颜色标记图标增加悬停与按压交互状态。ColorLabel 原先仅有选中/未选中两种
视觉状态,缺少 hover 和 press 反馈。新增 enterEvent/leaveEvent 实现悬停
高亮,mousePressEvent/mouseReleaseEvent 实现按压动画。

Log: 为颜色标记图标增加悬停与按压交互状态
PMS: BUG-196825
Influence: 右键菜单颜色标记子菜单的颜色图标现在有 hover/press 视觉反馈,
不影响已有标记和清除功能。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @tianming-1996, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

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

@sourcery-ai

sourcery-ai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds hover and press interaction states to the ColorLabel widget so color mark icons provide visual feedback on hover/press and emit their selection signal on mouse release, aligning behavior with Qt button conventions.

Sequence diagram for ColorLabel hover/press and selection behavior

sequenceDiagram
    actor User
    participant ColorLabel
    participant ColorSelectWdg

    User->>ColorLabel: mouseMove (hover enter)
    ColorLabel->>ColorLabel: enterEvent
    Note over ColorLabel: m_bHover = true
    ColorLabel->>ColorLabel: paintEvent

    User->>ColorLabel: mousePressEvent (LeftButton)
    ColorLabel->>ColorLabel: mousePressEvent
    Note over ColorLabel: m_bPressed = true
    ColorLabel->>ColorLabel: paintEvent

    User->>ColorLabel: mouseReleaseEvent (LeftButton)
    ColorLabel->>ColorLabel: mouseReleaseEvent
    Note over ColorLabel: m_bPressed = false
    Note over ColorLabel: m_bSelected = true
    ColorLabel-->>ColorSelectWdg: sigColorClicked(m_bSelected, m_color)
    ColorLabel->>ColorLabel: paintEvent

    User->>ColorLabel: mouseMove (hover leave)
    ColorLabel->>ColorLabel: leaveEvent
    Note over ColorLabel: m_bHover = false, m_bPressed = false
    ColorLabel->>ColorLabel: paintEvent
Loading

File-Level Changes

Change Details Files
Implement hover and press visual states for color mark icons and adjust click handling to emit selection on mouse release.
  • Refactor paintEvent to branch on normal, hover, and pressed states, adding distinct rendering paths with size and color adjustments for each state while preserving the existing selected ring behavior.
  • Introduce m_bHover and m_bPressed state members and update them in overridden enterEvent, leaveEvent, mousePressEvent, and mouseReleaseEvent handlers, including repaint triggers via update().
  • Change click behavior from emitting sigColorClicked on mouse press to emitting on mouse release when a valid press occurred, matching standard Qt button interaction.
  • Update includes to add QEvent and mark overridden event handlers with override for clarity and correctness.
  • Refresh SPDX copyright year range from 2019-2022 to 2019-2026 in both the implementation and header files.
src/widgets/ColorSelectWdg.cpp
src/widgets/ColorSelectWdg.h

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了颜色控件交互状态反馈重构,将点击响应规范至释放事件中
逻辑正确但因保留了历史拼写错误扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

将选中逻辑及信号发送从 mousePressEvent 拆分至 mouseReleaseEvent,符合标准的“按下-释放”交互规范。在 leaveEvent 中重置 m_bPressed 状态,有效防止了鼠标移出控件后释放导致的异常状态残留。mouseReleaseEvent 中通过 m_bPressed 标志进行拦截,避免了非左键按下时释放左键的误触发。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

新增了 override 关键字,符合现代 C++ 编码规范;引入 m_bHoverm_bPressed 状态机使得 paintEvent 中的绘制分支清晰明了;补充了必要的 <QEvent> 头文件引用。
潜在问题:在 paintEvent 的 normal 分支中,沿用了原代码里的变量名拼写错误 sencondCircle,应为 secondCircle
建议:修正 sencondCircle 的拼写错误以提升代码可读性和专业度。

  • 3.代码性能(无性能问题)✓

paintEvent 中虽在每次绘制时创建了多个 QPainterPathQRectF 局部对象,但这属于 Qt 绘图事件中的常规轻量级栈内存分配,由编译器优化且无堆内存分配开销,不会引起性能瓶颈。
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及前端 UI 绘制与基础的鼠标键盘事件分发,不涉及文件系统操作、网络请求、命令执行或底层内存越界访问,无安全攻击面。

  • 建议:保持当前的纯 UI 逻辑隔离设计。

■ 【改进建议代码示例】

diff --git a/src/widgets/ColorSelectWdg.cpp b/src/widgets/ColorSelectWdg.cpp
index 62929c46..corrected_hash 100644
--- a/src/widgets/ColorSelectWdg.cpp
+++ b/src/widgets/ColorSelectWdg.cpp
@@ -76,7 +76,7 @@ void ColorLabel::paintEvent(QPaintEvent *event)
         // 如果点击选择画圆环
         if (m_bSelected) {
             r = rect();
-            QPainterPath sencondCircle;
-            sencondCircle.addEllipse(r.adjusted(distance, distance, -distance, -distance));
+            QPainterPath secondCircle;
+            secondCircle.addEllipse(r.adjusted(distance, distance, -distance, -distance));
             // 大圆减小圆等于圆环
-            QPainterPath path = bigCircle - sencondCircle;
+            QPainterPath path = bigCircle - secondCircle;
             painter.fillPath(path, m_color);
         }

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.

2 participants