Skip to content

fix: Remove hardcoded colors in disk health detection dialog for theme compatibility#184

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1071from
itsXuSt:v20
Nov 24, 2025
Merged

fix: Remove hardcoded colors in disk health detection dialog for theme compatibility#184
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1071from
itsXuSt:v20

Conversation

@itsXuSt
Copy link
Contributor

@itsXuSt itsXuSt commented Nov 24, 2025

  • Remove hardcoded DPalette definitions (palette1-6) in DiskHealthDetectionDialog
  • Remove all setPalette() calls that prevented theme color following
  • Use option.palette.color(QPalette::Text) in DiskHealthDetectionDelegate for dynamic theme color
  • Preserve semantic colors for health status indicators (good/damaged/unknown)

Log: Fix disk health panel font color not following dark mode theme
Bug: https://pms.uniontech.com/bug-view-341105.html

Summary by Sourcery

Align disk health detection dialog colors with the active application theme to fix dark mode font visibility issues.

Bug Fixes:

  • Fix disk health panel text colors not following dark mode and becoming unreadable.

Enhancements:

  • Remove hardcoded palettes and delegate text color overrides so the dialog consistently uses theme-provided colors while preserving distinct health status indicator colors.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 24, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors DiskHealthDetectionDialog to rely on theme-driven palettes instead of hardcoded colors while keeping explicit semantic colors only for health state indicators and table delegate rendering.

Sequence diagram for theme-driven text color in DiskHealthDetectionDelegate

sequenceDiagram
    actor "User" as User
    participant "Application" as App
    participant "DiskHealthDetectionDialog" as Dialog
    participant "QTableView" as TableView
    participant "DiskHealthDetectionDelegate" as Delegate
    participant "QStyle" as Style

    "User" ->> "App" : "Open disk health detection dialog"
    "App" ->> "Dialog" : "create() and initUI()"
    "Dialog" ->> "TableView" : "setItemDelegate(Delegate)"

    "User" ->> "System" : "Change theme (light/dark)"
    "App" ->> "TableView" : "update() triggered by theme change"
    "TableView" ->> "Delegate" : "paint(option, index) for each cell"
    "Delegate" ->> "option.palette" : "color(QPalette::Text)"
    "option.palette" -->> "Delegate" : "theme-derived text color"
    "Delegate" ->> "Style" : "drawControl() with palette text color"
    "Style" -->> "TableView" : "cell rendered with correct text color"
    "TableView" -->> "User" : "SMART attributes text matches current theme"
Loading

File-Level Changes

Change Details Files
Remove hardcoded label and table palette customization so text colors follow the active theme
  • Delete local DPalette instances previously used to define fixed text/window colors
  • Remove setPalette() calls from disk info labels, health/temperature labels and values, status tips label, and the table view/header so they inherit colors from the global theme
application/widgets/diskhealthdetectiondialog.cpp
Simplify disk health table delegate color handling to use the option palette text color instead of manual theme branching
  • Remove explicit themeType checks and hardcoded QColor values for delegate text color
  • Rely on DiskHealthDetectionDelegate using option.palette.color(QPalette::Text) so it adapts automatically to light/dark themes
application/widgets/diskhealthdetectiondialog.cpp
Preserve semantic palette usage for health status state indication while cleaning surrounding palette code
  • Keep DPalette usage for state color (good/warning/damaged/unknown) while removing unrelated palette definitions
  • Ensure health state label still conveys status via color without interfering with theme text colors
application/widgets/diskhealthdetectiondialog.cpp

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 there - I've reviewed your changes - here's some feedback:

  • Since the delegate no longer has its text color set from the dialog, consider removing the setTextColor API and any related state from DiskHealthDetectionDelegate if it has become unused to keep the delegate interface minimal and avoid dead code.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the delegate no longer has its text color set from the dialog, consider removing the setTextColor API and any related state from DiskHealthDetectionDelegate if it has become unused to keep the delegate interface minimal and avoid dead code.

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.

…e compatibility

- Remove hardcoded DPalette definitions (palette1-6) in DiskHealthDetectionDialog
- Remove all setPalette() calls that prevented theme color following
- Use option.palette.color(QPalette::Text) in DiskHealthDetectionDelegate for dynamic theme color
- Preserve semantic colors for health status indicators (good/damaged/unknown)

Log: Fix disk health panel font color not following dark mode theme
Bug: https://pms.uniontech.com/bug-view-341105.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码的变更进行审查:

  1. 代码逻辑改进:
  • 移除了大量硬编码的颜色设置,改用系统主题的调色板(option.palette),这是一个很好的改进。这使得界面能够更好地适应深色/浅色主题的切换。
  • 在DiskHealthDetectionDelegate中,将原来的m_color替换为option.palette.color(QPalette::Text),使得文本颜色能够跟随系统主题变化。
  1. 代码质量改进:
  • 删除了多个冗余的DPalette对象声明(palette1-palette6),简化了代码结构。
  • 移除了重复的setPalette调用,减少了代码冗余。
  • 删除了不必要的主题类型判断代码,因为现在使用系统调色板会自动处理。
  1. 性能改进:
  • 减少了DPalette对象的创建,降低了内存开销。
  • 移除了主题类型判断,减少了运行时的条件判断。
  1. 安全性改进:
  • 使用系统提供的调色板而不是硬编码颜色值,可以确保在主题切换时颜色的一致性和可访问性。

建议:

  1. 考虑为不同的UI组件创建统一的样式设置方法,避免在initUI中重复设置相似的属性。
  2. 可以考虑使用Qt的样式表(QSS)来集中管理样式,这样更容易维护和修改。
  3. 建议添加注释说明为什么使用系统调色板而不是硬编码颜色,以便其他开发者理解这个设计决策。

总的来说,这是一个很好的重构,提高了代码的可维护性和主题适配性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: itsXuSt, max-lvs

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

@itsXuSt
Copy link
Contributor Author

itsXuSt commented Nov 24, 2025

/merge

@deepin-bot deepin-bot bot merged commit 46cc882 into linuxdeepin:release/1071 Nov 24, 2025
18 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