Skip to content

fix: magnifier shows white in dark theme - #432

Open
GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/bug-193251-magnifier-dark-theme
Open

GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/bug-193251-magnifier-dark-theme

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

BrowserMagniFier::setMagniFierImage() (reader/browser/BrowserMagniFier.cpp:178) hardcodes Qt::white as the fill color in the else branch when the mouse is over a non-page background area. This constant does not follow the system theme — in dark mode the background is dark (#2B2B2B) but the magnifier center shows pure white (#FFFFFF). The code was written in 2020 (commit 9417b7de) without dark mode consideration, while SheetBrowser already uses DGuiApplicationHelper::applicationPalette().itemBackground().color() for theme-aware background at SheetBrowser.cpp:2073.

Fix

Replace Qt::white at BrowserMagniFier.cpp:178 with Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color(), consistent with SheetBrowser's background color. Added #include <DGuiApplicationHelper>.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line (Qt::white fill) was introduced in commit 9417b7de (2020-07-14, "chore: 放大镜功能优化"), not a bug fix product — this change does not revert any historical fix
  • 9 references found including tests/browser/ut_browsermagnifier.cpp — the test stubs fillRect by signature (const QRect&, const QColor&), fix still passes a QColor, so no test breakage expected
  • No function signature change, no public API change

Business Impact Scope

The change affects only the magnifier feature: when the mouse is over a non-page background area in dark mode, the magnifier center follows the theme color instead of hardcoded white. Callers (updateImage(), showMagnigierImage(), onUpdateMagnifierImage()) are unaffected — normal image path uses the if branch, empty image path gets theme-aware fill.

Verification Suggestion

  1. Test magnifier over non-page background in dark mode — center should be dark, not white
  2. Test magnifier over non-page background in light mode — center should be near-white, no visible change
  3. Verify magnifier over page content is unaffected

根因分析

BrowserMagniFier::setMagniFierImage()(reader/browser/BrowserMagniFier.cpp:178)的 else 分支在鼠标悬停于非页面背景区域时,使用 Qt::white 硬编码填充放大镜中心。该常量不随系统主题变化——深色模式下背景为深色(#2B2B2B),放大镜中心却显示纯白(#FFFFFF)。代码写于 2020 年(commit 9417b7de),未考虑深色模式,而 SheetBrowser 已在 SheetBrowser.cpp:2073 使用 DGuiApplicationHelper::applicationPalette().itemBackground().color() 作为主题感知背景色。

修复方案

将 BrowserMagniFier.cpp:178 的 Qt::white 替换为 Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color(),与 SheetBrowser 背景色保持一致,并新增 #include <DGuiApplicationHelper> 头文件。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行(Qt::white 填充)由 commit 9417b7de(2020-07-14,"chore: 放大镜功能优化")引入,非 bug 修复产物——本次改动不撤销任何历史修复
  • 9 处引用含 tests/browser/ut_browsermagnifier.cpp——测试 stub fillRect 签名为 (const QRect&, const QColor&),修复后仍传入 QColor,预期不会破坏测试
  • 无函数签名变更,无公开 API 变更

业务影响范围

改动仅影响放大镜功能:深色模式下鼠标悬停在非页面背景区域时,放大镜中心跟随主题色而非硬编码白色。调用方(updateImage()、showMagnigierImage()、onUpdateMagnifierImage())不受影响——正常图像路径走 if 分支,空图像路径获得主题感知填充色。

验证建议

  1. 测试深色模式下放大镜悬停在非页面背景区域——中心应为深色而非白色
  2. 测试浅色模式下放大镜悬停在非页面背景区域——中心应为接近白色的浅色,无可见变化
  3. 验证放大镜悬停在页面内容上不受影响

Summary by Sourcery

Make the browser magnifier follow the application theme when displaying non-page background areas.

Bug Fixes:

  • Use the theme-aware item background color for the magnifier’s empty-area fill so it displays correctly in dark mode.

Chores:

  • Update the SPDX copyright year range for BrowserMagniFier.cpp.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

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 Oct 27, 2026

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

Reviewer's Guide

Updates the magnifier fallback background to use Dtk’s theme-aware item background color, fixing the white center shown in dark mode while preserving page-content rendering and existing APIs.

Flow diagram for theme-aware magnifier fallback

flowchart TD
    A[setMagniFierImage] --> B{Image available?}
    B -->|Yes| C[Draw scaled page image]
    B -->|No| D[DGuiApplicationHelper.applicationPalette]
    D --> E[itemBackground.color]
    E --> F[Fill magnifier background with theme color]
Loading

File-Level Changes

Change Details Files
Make the magnifier’s empty/background rendering follow the active application theme instead of using a hardcoded white fill.
  • Added the DGuiApplicationHelper dependency.
  • Replaced the fallback fill color with the palette’s item background color.
  • Left image rendering and public interfaces unchanged.
reader/browser/BrowserMagniFier.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 reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

1. Root cause: BrowserMagniFier::setMagniFierImage() else branch
   hardcodes Qt::white as fill color when mouse is over non-page
   background area, ignoring the system theme
2. Fix: replace Qt::white with DGuiApplicationHelper theme-aware
   itemBackground().color(), consistent with SheetBrowser background
   color at SheetBrowser.cpp:2073
3. Impact: magnifier background follows theme in dark mode; no
   visible change in light mode; no signature or logic change

Log: Magnifier background now follows system theme in dark mode

Influence:
1. Test magnifier over non-page background in dark mode
2. Test magnifier over non-page background in light mode
3. Verify magnifier over page content is unaffected

fix: 放大镜深色模式下显示白色

1. 根因:BrowserMagniFier::setMagniFierImage() else 分支在鼠标位于
   非页面背景区域时硬编码 Qt::white 填充色,未跟随系统主题
2. 方案:将 Qt::white 替换为 DGuiApplicationHelper 主题感知色
   itemBackground().color(),与 SheetBrowser 背景色一致
3. 影响:深色模式下放大镜背景跟随主题,浅色模式无可见变化,
   无签名或逻辑变更

Log: 放大镜背景色在深色模式下跟随系统主题

Influence:
1. 测试深色模式下放大镜悬停在非页面背景区域
2. 测试浅色模式下放大镜悬停在非页面背景区域
3. 验证放大镜悬停在页面内容上不受影响

PMS: BUG-193251
@GongHeng2017
GongHeng2017 force-pushed the fix/bug-193251-magnifier-dark-theme branch from e306318 to c137838 Compare October 27, 2026 22:48
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了放大镜在深色主题下显示白色背景的问题,通过将硬编码的 Qt::white 替换为 DGuiApplicationHelper 主题调色板的 itemBackground 颜色,使放大镜背景能自适应深色主题。变更简洁聚焦,语法正确,无安全漏洞,四维度均通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 当前修改已为最佳实践,无需额外修改。 // 使用 DGuiApplicationHelper 主题调色板替代硬编码白色, // 使放大镜背景在深色主题下正确显示: // // painter.fillRect(this->rect(), //     Dtk::Gui::DGuiApplicationHelper::instance() //         ->applicationPalette() //         .itemBackground() //         .color());

本报告由 AI 代码审查工具自动生成

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