Skip to content

feat(widget): add hover border effect to RoundColorWidget - #346

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-394181-add-hover-border-roundcolor
Aug 27, 2026
Merged

feat(widget): add hover border effect to RoundColorWidget#346
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-394181-add-hover-border-roundcolor

Conversation

@add-uos

@add-uos add-uos commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Add enter/leave event handlers to draw a theme-aware hover border on the round color button (15% black in light, 15% white in dark).

为圆形颜色按钮添加鼠标悬停边框效果,浅色主题用15%黑、深色主题用15%白。

Log: 添加RoundColorWidget悬停边框效果
PMS: TASK-394181
Influence: 颜色选项按钮鼠标悬停时显示边框反馈,提升交互体验,不影响选中态显示。

Summary by Sourcery

New Features:

  • Add theme-aware hover border feedback to round color buttons while preserving the selected-state appearance.

Add enter/leave event handlers to draw a theme-aware hover border
on the round color button (15% black in light, 15% white in dark).

为圆形颜色按钮添加鼠标悬停边框效果,浅色主题用15%黑、深色主题用15%白。

Log: 添加RoundColorWidget悬停边框效果
PMS: TASK-394181
Influence: 颜色选项按钮鼠标悬停时显示边框反馈,提升交互体验,不影响选中态显示。

@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 @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements hover feedback for RoundColorWidget by handling pointer entry and exit, maintaining a hover flag, and rendering a theme-aware 15% opacity border while preserving selected-state visuals and Qt 5/6 compatibility.

Sequence diagram for RoundColorWidget hover feedback

sequenceDiagram
    actor User
    participant Widget as RoundColorWidget
    participant Painter as QPainter
    participant Theme as DGuiApplicationHelper

    User->>Widget: enterEvent(event)
    Widget->>Widget: m_isHovered = true
    Widget->>Widget: update()
    Widget->>Widget: paintEvent(event)
    Widget->>Theme: themeType()
    Theme-->>Widget: DarkType or LightType
    Widget->>Painter: drawEllipse(hover border)

    User->>Widget: leaveEvent(event)
    Widget->>Widget: m_isHovered = false
    Widget->>Widget: update()
    Widget->>Widget: paintEvent(event)
    Widget->>Painter: drawEllipse(without hover border)
Loading

State diagram for RoundColorWidget visual states

stateDiagram-v2
    [*] --> Normal
    Normal --> Hovered: enterEvent(event)
    Hovered --> Normal: leaveEvent(event)
    Normal --> Selected: mousePressEvent(event)
    Hovered --> Selected: mousePressEvent(event)
    Selected --> Normal: selection cleared
    Selected --> Hovered: enterEvent(event)

    state Normal {
        [*] --> ColorCircle
    }
    state Hovered {
        [*] --> ThemeAwareBorder
    }
    state Selected {
        [*] --> HighlightBorder
    }
Loading

File-Level Changes

Change Details Files
Adds theme-aware hover-state tracking and border rendering for the circular color button.
  • Overrides enter and leave events with Qt 5/Qt 6-compatible signatures.
  • Tracks hover state, schedules repainting, and preserves base widget event handling.
  • Draws a 15% alpha black border in light themes or white border in dark themes only when the widget is hovered and not selected.
  • Retains selected-state highlight precedence over hover feedback.
reader/widgets/RoundColorWidget.cpp
reader/widgets/RoundColorWidget.h
Updates source and header copyright metadata and removes obsolete debug comments.
  • Extends copyright years through 2026.
  • Removes commented-out paint-event logging and drawing notes.
reader/widgets/RoundColorWidget.cpp
reader/widgets/RoundColorWidget.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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 97 分,大于 70 分通过阈值,代码质量符合要求。
提交信息 feat(widget): add hover border effect to RoundColorWidget
修改文件 reader/widgets/RoundColorWidget.cpp, reader/widgets/RoundColorWidget.h
分析模式 全量分析(GitHub PR)

📋 需求背景

Commit Message:
feat(widget): add hover border effect to RoundColorWidget

Add enter/leave event handlers to draw a theme-aware hover border
on the round color button (15% black in light, 15% white in dark).

Log: 添加RoundColorWidget悬停边框效果
PMS: TASK-394181
Influence: 颜色选项按钮鼠标悬停时显示边框反馈,提升交互体验,不影响选中态显示。

本次提交的目的是为 RoundColorWidget(圆形颜色选择按钮)添加鼠标悬停时的边框效果,浅色主题使用15%透明度黑色边框,深色主题使用15%透明度白色边框,提升交互体验。代码实现与 commit 目的一致。


🔍 详细分析

1. 语法逻辑 ✅

评分: 25/25 ✓ 语法正确,逻辑清晰

潜在问题:
✅ 未发现明显问题

分析详情:

  • Qt5/Qt6 兼容性处理正确:使用 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 预处理器指令区分 enterEvent 签名(Qt5 使用 QEvent*,Qt6 使用 QEnterEvent*),头文件和实现文件保持一致
  • m_isHovered 标志在 enterEvent(第57行)中设置为 true,在 leaveEvent(第65行)中设置为 false,管理正确
  • paintEvent 中的 else-if 链(第80-98行)确保选中态优先于悬停态显示边框,逻辑正确
  • 父类方法正确调用:DWidget::enterEvent(event)(第59行)和 DWidget::leaveEvent(event)(第67行)
  • Q_UNUSED(event)paintEvent 中正确使用(第72行)
  • 无内存泄漏、空指针解引用风险

2. 代码质量 ✅

评分: 22/25 ✓ 代码结构清晰,注释完整

潜在问题:

  1. reader/widgets/RoundColorWidget.cpp paintEvent 函数第80-97行:选中态边框绘制(第80-87行)与悬停态边框绘制(第88-97行)代码高度重复,均包含创建 QPen、设置 brush/width、adjusted rect、drawEllipse 的相同模式。建议提取为辅助方法如 drawBorder(const QColor &color, int width, QPainter &painter, const QRect &rect) 以减少重复。

分析详情:

  • 新增的 enterEventleaveEvent 在头文件中有完整的 Doxygen 注释(第58-74行),符合注释规范
  • PR 清理了 paintEvent 中旧的注释掉的调试日志(如 // qCDebug(appLog) << "RoundColorWidget paintEvent";),代码整洁度提升
  • 版权年份更新合理(2019 ~ 20202019 - 2026
  • 函数长度适中,结构清晰,无全局变量滥用
  • mousePressEvent 中仍保留两行注释掉的调试日志(第42、44行),为历史遗留代码,不在本次修改范围内

3. 代码性能 ✅

评分: 20/20 ✓ 性能良好,资源使用合理

潜在问题:
✅ 未发现明显问题

分析详情:

  • enterEventleaveEvent 中调用 update() 触发重绘是标准 Qt 机制,性能无问题
  • paintEvent 中创建临时 QColor/QPen/QBrush 对象是 Qt 绘制的正常做法,无需优化
  • DGuiApplicationHelper::instance()->themeType() 是轻量级内联调用,无性能开销
  • DGuiApplicationHelper::instance()->applicationPalette() 同样是轻量级调用
  • 无频繁系统调用、无资源泄漏、无不必要的计算

4. 代码安全 🔒

评分: 30/30 ✓ 存在0个安全漏洞

🔐 存在 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

分析详情:

  • 无用户输入处理,无注入风险(SQL注入、命令注入、XSS等)
  • 无硬编码密钥、密码或敏感信息
  • 无路径遍历、缓冲区溢出风险
  • 纯 UI 绘制逻辑,不涉及文件操作、网络通信或权限管理
  • 安全扫描器(security_scanner.py)确认 0 个漏洞
  • OCR 审查因 commit ref 不匹配未返回结果,已按空结果处理

💡 改进建议代码示例

// 建议提取公共边框绘制逻辑为辅助方法,减少 paintEvent 中的代码重复

// 在 RoundColorWidget.h 中添加私有辅助方法声明:
private:
    void drawBorder(QPainter &painter, const QColor &color, int width, const QRect &rect);

// 在 RoundColorWidget.cpp 中实现:
void RoundColorWidget::drawBorder(QPainter &painter, const QColor &color, int width, const QRect &rect)
{
    QPen pen;
    pen.setBrush(QBrush(color));
    pen.setWidth(width);
    painter.setPen(pen);
    QRect r = rect.adjusted(3, 3, -3, -3);
    painter.drawEllipse(r);
}

// paintEvent 中简化为:
void RoundColorWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)
    QPainter painter(this);
    painter.setPen(Qt::NoPen);
    painter.setRenderHints(QPainter::Antialiasing);

    int borderWidth = style()->pixelMetric(
        static_cast<QStyle::PixelMetric>(DStyle::PM_FocusBorderWidth), nullptr, this);

    QRect squareRect = rect();
    if (m_isSelected) {
        QColor highlightColor = DGuiApplicationHelper::instance()
            ->applicationPalette().highlight().color();
        drawBorder(painter, highlightColor, borderWidth, squareRect);
    } else if (m_isHovered) {
        bool isDark = DGuiApplicationHelper::instance()->themeType()
            == DGuiApplicationHelper::DarkType;
        QColor hoverColor = isDark ? Qt::white : Qt::black;
        hoverColor.setAlpha(38);
        drawBorder(painter, hoverColor, borderWidth, squareRect);
    }

    // ... 后续绘制逻辑保持不变
}

📁 文件分析统计

文件 类型 状态 说明
reader/widgets/RoundColorWidget.cpp C++ 代码 ✅ 已分析 新增 enterEvent/leaveEvent/hover 边框绘制
reader/widgets/RoundColorWidget.h C++ 头文件 ✅ 已分析 新增事件声明、m_isHovered 成员、Qt6 兼容

本报告由 AI 代码审查工具自动生成

项目: linuxdeepin/deepin-reader | PR: #346
扫描时间: 2026-08-27 14:48:27

@add-uos

add-uos commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 4ef8f7f into linuxdeepin:master Aug 27, 2026
9 checks passed
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