Skip to content

fix: use active color as fallback for dark active color in treeland#378

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
May 7, 2026
Merged

fix: use active color as fallback for dark active color in treeland#378
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

Treeland platform does not provide a separate dark active color
property. When the system theme is set to dark mode, the dark active
color was returning an invalid default value, causing the active color
to appear blank or invisible. This fix returns the regular active color
as a fallback, ensuring consistent visual appearance in dark themes.

Log: Fixed dark active color display issue in treeland platform

Influence:

  1. Test active color display in light theme mode
  2. Test active color display in dark theme mode
  3. Verify that active color is visible and correct in both themes
  4. Check color consistency when switching between light and dark themes

fix: 修复treeland平台暗色主题下活动色无效的问题

Treeland平台没有提供独立的暗色主题活动色属性。当系统主题切换为暗色模式
时,暗色活动色返回了无效的默认值,导致活动色显示为空白或不可见。此修复将
常规活动色作为暗色活动色的回退值,确保在暗色主题下保持一致的视觉表现。

Log: 修复treeland平台暗色主题活动色显示问题

Influence:

  1. 测试浅色主题模式下的活动色显示
  2. 测试暗色主题模式下的活动色显示
  3. 验证两种主题下活动色均可见且正确
  4. 检查在切换深浅色主题时颜色的表现一致性

PMS: BUG-344937

Treeland platform does not provide a separate dark active color
property. When the system theme is set to dark mode, the dark active
color was returning an invalid default value, causing the active color
to appear blank or invisible. This fix returns the regular active color
as a fallback, ensuring consistent visual appearance in dark themes.

Log: Fixed dark active color display issue in treeland platform

Influence:
1. Test active color display in light theme mode
2. Test active color display in dark theme mode
3. Verify that active color is visible and correct in both themes
4. Check color consistency when switching between light and dark themes

fix: 修复treeland平台暗色主题下活动色无效的问题

Treeland平台没有提供独立的暗色主题活动色属性。当系统主题切换为暗色模式
时,暗色活动色返回了无效的默认值,导致活动色显示为空白或不可见。此修复将
常规活动色作为暗色活动色的回退值,确保在暗色主题下保持一致的视觉表现。

Log: 修复treeland平台暗色主题活动色显示问题

Influence:
1. 测试浅色主题模式下的活动色显示
2. 测试暗色主题模式下的活动色显示
3. 验证两种主题下活动色均可见且正确
4. 检查在切换深浅色主题时颜色的表现一致性

PMS: BUG-344937
@18202781743 18202781743 requested review from BLumia and mhduiy May 7, 2026 12:27
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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
Contributor

deepin pr auto review

这段代码是一个针对 Qt 平台插件(Treeland 平台)的修改,主要是在接口类中新增了一个 darkActiveColor 方法,并提供了简单的实现。

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

1. 语法逻辑

  • 基本正确:代码的 C++ 语法是正确的,符合 Qt 的编程规范。在头文件中声明,在源文件中实现,并且正确地重写了基类的虚函数(override 关键字使用正确)。
  • 逻辑一致性:注释说明 "treeland does not provide dark active color, return active color as fallback"(treeland 不提供深色主题的高亮色,回退使用普通高亮色),这与实现代码 return m_activeColor; 是一致的。

2. 代码质量

  • 文档注释:建议在头文件 .h 中的函数声明上方添加 Doxygen 风格的注释,而不仅仅是在 .cpp 文件中。这样其他开发者在查看头文件接口定义时,就能直接了解该函数的行为和回退逻辑,而不需要跳转到实现文件。
    • 建议
      /**
       * @brief 获取深色主题下的高亮色
       * @note 由于 Treeland 后端不提供单独的深色高亮色,此处回退返回普通高亮色
       */
      QColor darkActiveColor() const override;
  • 常量性:函数 darkActiveColor 被正确地标记为 const,这是好的做法,因为它不修改对象状态。

3. 代码性能

  • 性能优秀:该函数仅返回一个成员变量,没有内存分配、复杂的计算或 I/O 操作。性能开销极小,可以忽略不计。

4. 代码安全

  • 线程安全:代码仅读取成员变量 m_activeColor。如果 m_activeColor 在其他地方(例如信号槽回调)被修改,且没有互斥锁保护,在多线程环境下可能会读到处于“半写”状态的值(尽管对于 QColor 这种简单的值类型,风险较低)。
    • 审查意见:通常 Qt GUI 组件主要在主线程运行,如果此接口仅在主线程调用,则不存在线程安全问题。如果存在跨线程调用的可能性,建议检查 m_activeColor 的写入是否线程安全,或者确保此接口的调用方在同一线程。
  • 空指针/未初始化风险:代码直接返回 m_activeColor。需要确保在 DTreelandPlatformInterface 构造函数或初始化函数中,m_activeColor 已被正确初始化。如果 m_activeColor 未初始化,返回的 QColor 可能是无效的(QColor() 默认构造为无效颜色 isValid() == false)。
    • 建议:确认 m_activeColor 的初始化逻辑。如果后端可能不提供颜色,可以考虑返回一个硬编码的默认安全颜色(如 Qt 默认的高亮色),而不是依赖可能未初始化的成员变量。不过,考虑到已有 activeColor() 函数存在,假设 m_activeColor 的生命周期管理是已受控的。

总结与改进建议

这段代码改动简单且功能明确,主要改进点在于文档完善潜在的健壮性检查

优化后的代码建议:

头文件:

    /**
     * @brief darkActiveColor 获取深色模式下的高亮色
     * @return 返回当前高亮色。注意:Treeland 平台暂不支持独立的深色高亮色,因此此处回退返回普通高亮色。
     */
    QColor darkActiveColor() const override;

源文件:

QColor DTreelandPlatformInterface::darkActiveColor() const
{
    // Treeland 后端暂不提供独立的深色高亮色,作为回退策略,返回当前的高亮色。
    // 如果 m_activeColor 无效,返回一个默认的蓝色作为保底值。
    if (m_activeColor.isValid()) {
        return m_activeColor;
    }
    // 返回一个默认颜色,防止 UI 显示异常
    return QColor(0, 120, 215); // 举例:常见的系统高亮蓝
}

理由
增加了对 m_activeColor.isValid() 的检查。虽然现有逻辑可能保证它总是有效的,但在处理平台接口时,防御性编程(Defensive Programming)可以避免因后端数据异常导致的 UI 渲染错误(例如文字变成透明色或黑色)。

@18202781743 18202781743 merged commit 683147b into linuxdeepin:master May 7, 2026
21 of 22 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