Skip to content

refactor: migrate icons to theme-based system with DTK#311

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Kakueeen:master
May 27, 2026
Merged

refactor: migrate icons to theme-based system with DTK#311
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Kakueeen:master

Conversation

@Kakueeen
Copy link
Copy Markdown
Contributor

  1. Replace hardcoded SVG icons with DTK theme-based icon system using
    QIcon::fromTheme()
  2. Remove deprecated light/dark icon variants and manual theme suffix
    handling
  3. Move icons to new theme directory structure under builtin/texts/ and
    builtin/icons/
  4. Reduce SWITCHWIDGETICONSIZE from 36 to 24 pixels for better visual
    consistency
  5. Update CMakeLists.txt to reference new resource.qrc location
  6. Simplify icon loading logic in BestMatchWidget, ScopeWidget,
    PlanWidget and ConfigWidget
  7. Remove fixed icon label size constraint in SwitchWidget for flexible
    sizing

Log: Migrated search configuration icons to DTK theme system with
standardized 24px sizing

Influence:

  1. Verify all search configuration icons display correctly in both light
    and dark themes
  2. Test icon appearance in BestMatchWidget, ScopeWidget, PlanWidget
    sections
  3. Confirm window icon loads properly in ConfigWidget titlebar
  4. Check icon sizing consistency across different DPI settings
  5. Validate theme switching updates icons without restart
  6. Ensure no broken image references in search settings UI

refactor: 迁移图标至基于 DTK 主题的图标系统

  1. 使用 QIcon::fromTheme() 替换硬编码的 SVG 图标,采用 DTK 主题图标系统
  2. 移除废弃的浅色/深色图标变体及手动主题后缀处理逻辑
  3. 将图标移至新的主题目录结构,位于 builtin/texts/ 和 builtin/icons/ 下
  4. 将 SWITCHWIDGETICONSIZE 从 36 减小至 24 像素,提升视觉一致性
  5. 更新 CMakeLists.txt 以引用新的 resource.qrc 位置
  6. 简化 BestMatchWidget、ScopeWidget、PlanWidget 和 ConfigWidget 中的图
    标加载逻辑
  7. 移除 SwitchWidget 中固定的图标标签尺寸约束,实现灵活 sizing

Log: 搜索配置图标已迁移至 DTK 主题系统,采用标准化的 24px 尺寸

Influence:

  1. 验证所有搜索配置图标在浅色和深色主题下均能正确显示
  2. 测试 BestMatchWidget、ScopeWidget、PlanWidget 区域中的图标外观
  3. 确认 ConfigWidget 标题栏中的窗口图标正常加载
  4. 检查不同 DPI 设置下图标尺寸的一致性
  5. 验证主题切换无需重启即可更新图标
  6. 确保搜索设置 UI 中没有损坏的图片引用

BUG: https://pms.uniontech.com/bug-view-361095.html

1. Replace hardcoded SVG icons with DTK theme-based icon system using
QIcon::fromTheme()
2. Remove deprecated light/dark icon variants and manual theme suffix
handling
3. Move icons to new theme directory structure under builtin/texts/ and
builtin/icons/
4. Reduce SWITCHWIDGETICONSIZE from 36 to 24 pixels for better visual
consistency
5. Update CMakeLists.txt to reference new resource.qrc location
6. Simplify icon loading logic in BestMatchWidget, ScopeWidget,
PlanWidget and ConfigWidget
7. Remove fixed icon label size constraint in SwitchWidget for flexible
sizing

Log: Migrated search configuration icons to DTK theme system with
standardized 24px sizing

Influence:
1. Verify all search configuration icons display correctly in both light
and dark themes
2. Test icon appearance in BestMatchWidget, ScopeWidget, PlanWidget
sections
3. Confirm window icon loads properly in ConfigWidget titlebar
4. Check icon sizing consistency across different DPI settings
5. Validate theme switching updates icons without restart
6. Ensure no broken image references in search settings UI

refactor: 迁移图标至基于 DTK 主题的图标系统

1. 使用 QIcon::fromTheme() 替换硬编码的 SVG 图标,采用 DTK 主题图标系统
2. 移除废弃的浅色/深色图标变体及手动主题后缀处理逻辑
3. 将图标移至新的主题目录结构,位于 builtin/texts/ 和 builtin/icons/ 下
4. 将 SWITCHWIDGETICONSIZE 从 36 减小至 24 像素,提升视觉一致性
5. 更新 CMakeLists.txt 以引用新的 resource.qrc 位置
6. 简化 BestMatchWidget、ScopeWidget、PlanWidget 和 ConfigWidget 中的图
标加载逻辑
7. 移除 SwitchWidget 中固定的图标标签尺寸约束,实现灵活 sizing

Log: 搜索配置图标已迁移至 DTK 主题系统,采用标准化的 24px 尺寸

Influence:
1. 验证所有搜索配置图标在浅色和深色主题下均能正确显示
2. 测试 BestMatchWidget、ScopeWidget、PlanWidget 区域中的图标外观
3. 确认 ConfigWidget 标题栏中的窗口图标正常加载
4. 检查不同 DPI 设置下图标尺寸的一致性
5. 验证主题切换无需重启即可更新图标
6. 确保搜索设置 UI 中没有损坏的图片引用

BUG: https://pms.uniontech.com/bug-view-361095.html
Copy link
Copy Markdown

@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.

Sorry @Kakueeen, 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

deepin pr auto review

你好!我是CodeGeeX。我已经仔细审查了你提供的Git Diff。这次代码变更的核心是将图标加载方式从硬编码的资源文件路径(区分明暗主题)迁移到了系统主题图标机制(QIcon::fromTheme,同时调整了图标尺寸、布局伸展因子,并对资源文件进行了重组。

总体来说,这是一次非常优秀且符合Qt/Deepin平台最佳实践的重构。以下是针对语法逻辑、代码质量、性能和安全方面的详细审查意见及改进建议:

一、 语法与逻辑

1. QIcon::fromTheme 的引用陷阱(重要)
bestmatchwidget.cppplanwidget.cppscopewidget.cpp 中,代码修改为:

const auto &icon = QIcon::fromTheme(iconName);

问题QIcon::fromTheme() 返回的是一个 QIcon 对象(右值)。将其绑定到 const auto&(常量左值引用)虽然利用了C++的引用折叠延长了生命周期,语法上合法,但容易引起误解,且在某些老旧编译器下可能引发悬垂引用或额外的拷贝开销。
建议:直接使用值类型接收,依赖现代C++的返回值优化(RVO/NRVO):

const QIcon icon = QIcon::fromTheme(iconName);
// 或者更简洁:
// const auto icon = QIcon::fromTheme(iconName);

2. QIcon::fromTheme 的降级逻辑缺失
问题:原先通过 QString::arg() 拼接路径时,如果文件不存在,QIcon 会构造为空图标。现在使用 QIcon::fromTheme(),如果系统主题中找不到对应的图标名,也会返回空图标,但没有任何提示。
建议:为了保证兼容性(特别是在系统主题未安装或名称不匹配时),建议使用 QIcon::fromTheme 的第二个参数提供降级图标:

// 以 configwidget.cpp 为例
QIcon tmpIcon = QIcon::fromTheme("dde-grand-search-setting", QIcon(":/icons/deepin/builtin/icons/dde-grand-search-setting_32px.svg"));

这样即使系统主题缺失,也能从内置资源中加载图标。

二、 代码质量

1. 布局伸展因子修正(优秀)
switchwidget.cpp 中:

- m_mainLayout->addLayout(labelLayout, 0);
+ m_mainLayout->addLayout(labelLayout, 1);

评价:这是一个很好的修复!将 labelLayout 的伸展因子从 0 改为 1,意味着中间的文本区域会占据剩余的可用空间,而图标和开关按钮保持其固有大小。这符合常见UI设计的伸缩逻辑,避免了窗口变宽时控件不跟随拉伸的问题。

2. 图标尺寸与固定大小约束的解耦(优秀)

-#define ICONLABELSIZE   36
 m_iconLabel->setFixedSize(ICONLABELSIZE, ICONLABELSIZE); // 被移除

同时 SWITCHWIDGETICONSIZE36 改为 24
评价:移除了 m_iconLabel 的硬编码固定大小,转而依赖 switchWidget->setIcon(icon, { SWITCHWIDGETICONSIZE, SWITCHWIDGETICONSIZE }); 传入的尺寸,使得图标尺寸控制更加集中和灵活。新尺寸 24x24 更符合现代Deepin UOS的UI设计规范。

3. 资源文件前缀的规范化(优秀)

- <qresource prefix="/">
+ <qresource prefix="/icons/deepin">

评价:将资源前缀从根目录 / 改为 /icons/deepin,避免了根命名空间的污染,结构更加清晰,也与Deepin的图标主题规范对齐。

三、 代码性能

1. 减少磁盘I/O和内存占用(提升)
分析:原先的实现需要在资源文件中打包明暗两套SVG(如 appsearch-dark.svgappsearch-light.svg),并在运行时通过 Utils::iconThemeSuffix() 动态拼接路径加载。
现在的实现使用 QIcon::fromTheme,由系统主题引擎统一管理图标的明暗主题切换。这不仅减小了应用程序的打包体积(删除了大量冗余SVG),还利用了系统级的图标缓存机制,提升了图标加载速度和内存使用效率。

四、 代码安全

1. 路径注入风险消除(提升)
分析:原先使用 QString().arg() 动态拼接文件路径,如果 iconName 包含特殊字符或路径穿越符(如 ../),可能存在加载非预期文件的风险(尽管在硬编码资源前缀的情况下风险极低)。
现在使用 QIcon::fromTheme(iconName),传入的仅是图标名称(纯标识符),由系统主题引擎在合法的图标目录下进行安全查找,彻底杜绝了路径拼接引发的安全隐患。


综合修改建议代码示例

针对上述审查意见,建议对代码进行如下微调:

1. bestmatchwidget.cpp / planwidget.cpp / scopewidget.cpp

// 修改前:
const auto &icon = QIcon::fromTheme(iconName);

// 修改后:去掉引用,使用值语义;并视情况增加 fallback(可选)
const QIcon icon = QIcon::fromTheme(iconName);

2. configwidget.cpp

// 修改前:
QIcon tmpIcon = QIcon::fromTheme("dde-grand-search-setting");

// 修改后:增加 fallback 保证极端情况下的显示
QIcon tmpIcon = QIcon::fromTheme("dde-grand-search-setting", QIcon(":/icons/deepin/builtin/icons/dde-grand-search-setting_32px.svg"));

总结:这次重构方向非常正确,显著提升了代码的维护性、性能和安全性,且更加贴合系统原生风格。只需注意 QIcon::fromTheme 返回值的接收方式和降级策略即可。代码可以合并!

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, Kakueeen

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

@Kakueeen
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot deepin-bot Bot merged commit 150852e into linuxdeepin:master May 27, 2026
11 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