Skip to content

fix(attributes): use palette text color - #216

Closed
Resurgamz wants to merge 2 commits into
linuxdeepin:release/eaglefrom
Resurgamz:feature/fix-BUG231619
Closed

fix(attributes): use palette text color#216
Resurgamz wants to merge 2 commits into
linuxdeepin:release/eaglefrom
Resurgamz:feature/fix-BUG231619

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Jul 23, 2026

Copy link
Copy Markdown

问题\n修复右侧工具属性栏中颜色属性标签与圆角控件文字颜色不一致的问题。\n\n## 修复方案\n颜色属性标签绘制时使用当前调色板的 QPalette::WindowText,替代硬编码的深浅主题色值,使其与 DTK 控件保持一致并随主题自动适配。\n\n## 验证\n- cmake --build obj-x86_64-linux-gnu -j2\n\n## PMS\n- BUG-231619\n- 根因分析:analysis-report.md

Summary by Sourcery

Align attribute color label text with the active theme palette and adjust print dialog rendering to use a white background image.

Bug Fixes:

  • Use the current palette's window text color for color attribute labels to keep them consistent with themed controls.
  • Render the page image with an explicit white background when opening the print dialog to avoid incorrect background colors.

zhangjiarui added 2 commits July 22, 2026 21:14
Use the current palette WindowText color for color property labels so they match adjacent DTK controls.

Log: 修复工具属性文字颜色与圆角控件不一致的问题

Bug: https://pms.uniontech.com/bug-view-231619.html
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Resurgamz

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

@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR updates color handling in the attributes sidebar to use the current palette’s text color instead of hard‑coded theme colors, and adjusts the print dialog to render pages with an explicit white background.

Sequence diagram for print dialog rendering with white background

sequenceDiagram
    actor User
    participant TopTilte
    participant CPrintManager
    participant Page
    participant PageContext

    User->>TopTilte: triggerPrintAction
    TopTilte->>Page: currentPage
    TopTilte->>PageContext: context
    TopTilte->>CPrintManager: CPrintManager(topMainWindowWidget)
    TopTilte->>PageContext: renderToImage(Qt::white)
    PageContext-->>TopTilte: renderedImage
    TopTilte->>CPrintManager: showPrintDialog(renderedImage, topMainWindowWidget, page->name)
    CPrintManager-->>User: printDialogShown
Loading

File-Level Changes

Change Details Files
Make color attribute labels use the active palette text color instead of hard-coded theme colors.
  • Replace dark/light theme conditional text color with palette-based QPalette::WindowText when painting the fill label.
  • Apply the same palette-based text color when painting the stroke label.
src/frame/AttributesWidgets/private/cattributeitemwidget.cpp
Ensure print dialog previews are rendered on a white background.
  • Change renderToImage call when opening the print dialog to pass Qt::white as the background color.
src/frame/toptoolbar.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

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

Hey - I've left some high level feedback:

  • In CColorSettingButton::paintFillArea and paintFillBorder, consider whether QPalette::WindowText is the best matching role for these labels or if another role (e.g., ButtonText or Text) would better align with how DTK controls derive their label colors to avoid subtle inconsistencies across themes.
  • The change to page->context()->renderToImage(Qt::white) hardcodes a white background for printing; if the application supports custom or dark backgrounds, consider deriving this color from the page/background or palette instead of a fixed Qt::white to preserve WYSIWYG behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `CColorSettingButton::paintFillArea` and `paintFillBorder`, consider whether `QPalette::WindowText` is the best matching role for these labels or if another role (e.g., `ButtonText` or `Text`) would better align with how DTK controls derive their label colors to avoid subtle inconsistencies across themes.
- The change to `page->context()->renderToImage(Qt::white)` hardcodes a white background for printing; if the application supports custom or dark backgrounds, consider deriving this color from the page/background or palette instead of a fixed `Qt::white` to preserve WYSIWYG behavior.

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.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了主题颜色适配和打印预览背景透明的问题,逻辑正确且提升了代码健壮性
修改精准有效,去除了硬编码并显式指定渲染背景,无明显质量与性能缺陷,故给予高分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码修改位于 cattributeitemwidget.cpppaintFillAreapaintFillBorder 函数,以及 toptoolbar.cppTopTilte::initMenu 函数。使用 palette().color(QPalette::WindowText) 替换硬编码颜色,以及为 renderToImage 传入 Qt::white 参数,均符合 Qt 框架的 API 规范,未引入任何语法或逻辑错误。
潜在问题:无
建议:无需额外修改

  • 2.代码质量(优秀)✓

修改消除了原先通过 darkTheme 变量进行判断的硬编码颜色逻辑,使控件文字颜色能够自动跟随系统主题变化。同时,在 renderToImage 中显式指定白色背景,避免了隐式依赖带来的显示异常,提高了代码的可读性和可维护性。
潜在问题:无
建议:可考虑在项目中统一排查其他类似的硬编码颜色使用,确保全局主题适配的一致性

  • 3.代码性能(良好)✓

调用 palette().color() 获取颜色的开销极小,且 renderToImage(Qt::white) 仅增加了一个颜色参数的传递,不会对程序运行性能产生任何负面影响。
潜在问题:无
建议:无需额外优化

  • 4.代码安全(安全,存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改仅涉及 UI 显示逻辑的参数调整,未引入任何外部输入处理、文件操作或网络请求,不存在安全风险。

  • 建议:继续保持良好的安全编码习惯

■ 【改进建议代码示例】

diff --git a/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp b/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp
index 91ac47b4b..6b2de977a 100644
--- a/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp
+++ b/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp
@@ -197,7 +197,7 @@ void DrawAttribution::CColorSettingButton::paintFillArea(QPainter *painter)
 
     //绘制常量文字("填充")
     painter->save();
-    painter->setPen(darkTheme ? QColor("#C0C6D4") : QColor("#414D68"));
+    painter->setPen(palette().color(QPalette::WindowText));
     painter->drawText(textRct, _text, QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
     painter->restore();
 }
@@ -258,7 +258,7 @@ void DrawAttribution::CColorSettingButton::paintFillBorder(QPainter *painter)
 
     //绘制常量文字("描边")
     painter->save();
-    painter->setPen(darkTheme ? QColor("#C0C6D4") : QColor("#414D68"));
+    painter->setPen(palette().color(QPalette::WindowText));
     painter->drawText(textRct, _text, QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
     painter->restore();
 }
diff --git a/src/frame/toptoolbar.cpp b/src/frame/toptoolbar.cpp
index 052313287..2c627fb79 100644
--- a/src/frame/toptoolbar.cpp
+++ b/src/frame/toptoolbar.cpp
@@ -202,8 +202,8 @@ void TopTilte::initMenu()
             CPrintManager manager(drawApp->topMainWindowWidget());
             auto page = drawApp->drawBoard()->currentPage();
             if (page != nullptr && page->context() != nullptr)
-                manager.showPrintDialog(page->context()->renderToImage(), drawApp->topMainWindowWidget(),
-                                        page->name());
+                manager.showPrintDialog(page->context()->renderToImage(Qt::white), drawApp->topMainWindowWidget(),
+                                         page->name());
         });
     } else {
         QAction *exportAc = new QAction(tr("Export"), this);

@Resurgamz

Copy link
Copy Markdown
Author

该 PR 混入了两个独立问题的提交,已拆分为 #217(BUG-231619 属性文字颜色)和 #218(BUG-221301 打印背景)。

@Resurgamz Resurgamz closed this Jul 23, 2026
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.

2 participants