Skip to content

fix: adjust window decoration button background opacity#724

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Feb 2, 2026
Merged

fix: adjust window decoration button background opacity#724
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

Changed the background opacity of window decoration buttons from 5%
to 10% for both light and dark themes. This adjustment improves the
visual distinction of window control buttons (minimize, maximize, close)
against the window background, enhancing user interface clarity and
accessibility.

Log: Improved visibility of window control buttons by increasing
background opacity

Influence:

  1. Test window decoration buttons in both light and dark themes
  2. Verify button visibility against various window backgrounds
  3. Check hover and pressed states of window control buttons
  4. Test with different window sizes and states (maximized, normal)
  5. Verify consistency across different application windows

fix: 调整窗口装饰器按钮背景透明度

将窗口装饰器按钮的背景透明度从5%调整为10%,适用于浅色和深色主题。这一调
整增强了窗口控制按钮(最小化、最大化、关闭)在窗口背景上的视觉区分度,提
升了用户界面的清晰度和可访问性。

Log: 通过增加背景透明度提高了窗口控制按钮的可见性

Influence:

  1. 在浅色和深色主题下测试窗口装饰器按钮
  2. 验证按钮在不同窗口背景下的可见性
  3. 检查窗口控制按钮的悬停和按下状态
  4. 测试不同窗口大小和状态(最大化、正常)下的显示效果
  5. 验证不同应用程序窗口之间的一致性

PMS: BUG-302267

Changed the background opacity of window decoration buttons from 5%
to 10% for both light and dark themes. This adjustment improves the
visual distinction of window control buttons (minimize, maximize, close)
against the window background, enhancing user interface clarity and
accessibility.

Log: Improved visibility of window control buttons by increasing
background opacity

Influence:
1. Test window decoration buttons in both light and dark themes
2. Verify button visibility against various window backgrounds
3. Check hover and pressed states of window control buttons
4. Test with different window sizes and states (maximized, normal)
5. Verify consistency across different application windows

fix: 调整窗口装饰器按钮背景透明度

将窗口装饰器按钮的背景透明度从5%调整为10%,适用于浅色和深色主题。这一调
整增强了窗口控制按钮(最小化、最大化、关闭)在窗口背景上的视觉区分度,提
升了用户界面的清晰度和可访问性。

Log: 通过增加背景透明度提高了窗口控制按钮的可见性

Influence:
1. 在浅色和深色主题下测试窗口装饰器按钮
2. 验证按钮在不同窗口背景下的可见性
3. 检查窗口控制按钮的悬停和按下状态
4. 测试不同窗口大小和状态(最大化、正常)下的显示效果
5. 验证不同应用程序窗口之间的一致性

PMS: BUG-302267
@18202781743 18202781743 requested review from BLumia and mhduiy February 2, 2026 05:54
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这段代码修改主要涉及 Qt 界面绘制中的颜色透明度调整。以下是对该 git diff 的审查意见,分为代码逻辑、代码质量、性能和安全四个方面:

1. 代码逻辑审查

  • 修改意图:代码将 Window 角色的画刷颜色透明度从 0.05 (约 5%) 调整到了 0.1 (约 10%)。
  • 影响分析
    • 这意味着在绘制某些图元(PrimitiveElement)时,背景色的不透明度增加了一倍。
    • 深色模式:白色背景的不透明度增加,会使高亮或叠加层更明显。
    • 浅色模式:黑色背景的不透明度增加,会使阴影或分割线更深。
  • 潜在问题:如果原设计 0.05 是为了极其微弱的视觉效果,改为 0.1 可能会导致界面元素过于突兀,特别是在某些高分辨率屏幕或特定背景下,可能会显得"脏"或对比度过高。建议结合 UI 设计稿确认是否确实需要加强对比度。

2. 代码质量审查

  • 硬编码问题:代码中存在大量的"魔法数字"(Magic Numbers),如 2550.050.1
    • 建议:将这些常量定义为具有语义名称的宏、static const 变量或枚举值。
    • 示例
      // 在类定义或头文件中
      static constexpr qreal WINDOW_COLOR_OPACITY_HIGH_CONTRAST = 0.1;
      static constexpr int COLOR_CHANNEL_MAX = 255;
      
      // 使用时
      color = QColor(255, 255, 255, COLOR_CHANNEL_MAX * WINDOW_COLOR_OPACITY_HIGH_CONTRAST);
  • 浮点数运算255 * 0.1 的结果是浮点数,虽然 QColor 的构造函数接受 int 类型的 alpha 通道(会进行截断或转换),但在某些严格的编译器或静态分析工具中可能会提示精度丢失警告。
    • 建议:显式转换为 int,例如 static_cast<int>(255 * 0.1),或者直接写 25(如果是固定值)。

3. 代码性能审查

  • 计算开销DGuiApplicationHelper::instance()->themeType() 是一个函数调用,且通常涉及单例模式的访问。
    • 现状:在 drawPrimitive 这种高频调用的绘制函数中,每次都调用可能存在微小的性能开销,尽管通常可以忽略不计。
    • 建议:如果 drawPrimitive 在同一帧内被大量调用,且主题类型不会在绘制过程中改变,可以考虑在绘制循环外缓存主题类型,但这取决于 drawPrimitive 的调用上下文,此处改动可能涉及较大架构调整,暂不强制要求。
  • 对象构造QColor 的构造和 QPalette 的设置开销很小,属于正常绘图操作,无明显性能问题。

4. 代码安全审查

  • 类型安全:如上所述,浮点数乘积传递给接受整型的参数时,依赖隐式类型转换。虽然 Qt 处理得很好,但显式转换更安全。
  • 空指针检查DGuiApplicationHelper::instance() 返回的是单例指针。虽然单例通常保证不为空,但在极端初始化顺序问题下,理论上存在风险。
    • 建议:虽然 Qt 单例模式通常很安全,但为了防御性编程,可以添加断言或空指针检查(视项目严格程度而定):
      Q_ASSERT(guiAppHelp != nullptr);

总结与改进建议代码

这段代码修改在功能上是正确的,能够实现加深颜色的目的。但从可维护性和规范性角度,建议进行如下优化:

// 建议在类的头文件或全局常量定义处添加:
// static constexpr int ALPHA_CHANNEL_BASE = 255;
// static constexpr qreal WINDOW_BACKGROUND_OPACITY = 0.1;

// 修改后的代码片段:
void DStyle::drawPrimitive(const QStyle *style, DStyle::PrimitiveElement pe, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    // ... 其他代码 ...

    if (/* 判断条件 */) {
        QColor color;
        DGuiApplicationHelper *guiAppHelp = DGuiApplicationHelper::instance();
        
        // 建议增加断言确保单例有效性
        Q_ASSERT(guiAppHelp);

        // 使用常量替代魔法数字,并显式转换类型
        const int alphaValue = static_cast<int>(ALPHA_CHANNEL_BASE * WINDOW_BACKGROUND_OPACITY);

        if (guiAppHelp->themeType() == DGuiApplicationHelper::ColorType::DarkType) {
            color = QColor(255, 255, 255, alphaValue);
        } else {
            color = QColor(0, 0, 0, alphaValue);
        }
        
        pa.setBrush(QPalette::Window, color);
    }
    
    // ... 其他代码 ...
}

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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
Contributor

deepin-bot bot commented Feb 2, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit d6e0a11 into linuxdeepin:master Feb 2, 2026
18 of 19 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