Skip to content

fix: use theme-aware color for magnifier background - #436

Draft
GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/pms-193251-magnifier-dark-mode
Draft

GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/pms-193251-magnifier-dark-mode

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When the magnifier is moved to a non-content area (outside document pages), BrowserMagniFier::setMagniFierImage() receives a null QImage and enters the else branch, where it fills the magnifier center with Qt::white. Since Qt::white is a fixed Qt color constant (QColor(255,255,255)) that does not respond to theme changes, the magnifier center displays pure white even in dark mode, creating a jarring contrast with the dark background (~#2B2B2B).

Key evidence: reader/browser/BrowserMagniFier.cpp:207 hardcodes Qt::white; the same module's SheetBrowser.cpp:72 already uses the theme-aware DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color().

Fix

Replace Qt::white at line 207 with DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color(), and add #include <DGuiApplicationHelper>. This is consistent with the existing pattern in SheetBrowser.cpp:72.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line was introduced in the initial magnifier implementation (commit 9417b7de8, 2020-07-14), not a previous bug fix product; this change does not revert any historical fix
  • setMagniFierImage() is a private rendering method with only 3 internal callers; no signature change, no caller impact

Business Impact Scope

  • Affected module: Document viewer magnifier tool
  • User scenario: In dark mode, moving the magnifier to non-content areas now shows the theme background color instead of pure white
  • No impact on normal magnifier behavior (showing page content) — only the null-image fallback path changes

Verification Suggestion

Test the magnifier tool in both light and dark modes: move it onto and off document pages, verify the center area follows the theme in dark mode and remains consistent in light mode.


根因分析

深色模式下放大镜移至非内容区域时,BrowserMagniFier::setMagniFierImage() 收到空 QImage 进入 else 分支,使用 Qt::white 填充放大镜中心。Qt::white 是 Qt 固定常量(QColor(255,255,255)),不随主题变化,导致深色模式下放大镜中心显示纯白,与深色背景(约 #2B2B2B)形成刺眼反差。

关键证据:reader/browser/BrowserMagniFier.cpp:207 硬编码 Qt::white;同模块 SheetBrowser.cpp:72 已使用主题感知的 DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color()。

修复方案

将第 207 行的 Qt::white 替换为 DGuiApplicationHelper::instance()->applicationPalette().itemBackground().color(),并添加 #include <DGuiApplicationHelper>,与 SheetBrowser.cpp:72 保持一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行引入于放大镜初始实现(commit 9417b7de8, 2020-07-14),非历史 bug 修复产物;本次改动不撤销任何历史修复
  • setMagniFierImage() 是私有渲染方法,仅 3 个内部调用方;签名不变,调用方无影响

业务影响范围

  • 受影响模块:文档查看器放大镜工具
  • 用户场景:深色模式下放大镜移至非内容区域时,中心区域跟随主题显示背景色,不再为纯白
  • 正常放大镜行为(显示页面内容)不受影响,仅空图像兜底路径变化

验证建议

在浅色和深色模式下测试放大镜工具:将放大镜移入和移出文档页面,验证深色模式下中心区域跟随主题,浅色模式保持一致。

Summary by Sourcery

Make the document magnifier’s empty-area background follow the application theme.

Bug Fixes:

  • Use the active theme background color for the magnifier fallback area when no document image is available, preventing a jarring white center in dark mode.

Chores:

  • Update the BrowserMagniFier copyright year range.

@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 29, 2026

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

Reviewer's Guide

Updates the magnifier’s non-content fallback rendering to obtain its fill color from the application palette, preventing a white center from clashing with dark mode while preserving existing content rendering behavior.

Sequence diagram for theme-aware magnifier fallback rendering

sequenceDiagram
    participant BrowserMagniFier
    participant DGuiApplicationHelper
    participant QPainter

    BrowserMagniFier->>BrowserMagniFier: setMagniFierImage(image)
    alt image contains page content
        BrowserMagniFier->>QPainter: drawImage()
    else image is null
        BrowserMagniFier->>DGuiApplicationHelper: instance()
        DGuiApplicationHelper-->>BrowserMagniFier: applicationPalette()
        BrowserMagniFier->>QPainter: fillRect(itemBackground().color())
    end
Loading

File-Level Changes

Change Details Files
Make the magnifier’s null-image fallback use the active application theme background instead of a hardcoded white color.
  • Add the DGuiApplicationHelper dependency.
  • Use the palette item background color when filling the magnifier outside document content.
  • Leave normal page-image rendering and the method interface 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

@GongHeng2017
GongHeng2017 marked this pull request as draft October 29, 2026 20:28

@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() hardcoded
   Qt::white to fill magnifier center when image is null, which
   does not adapt to dark mode
2. Fix: replace Qt::white with DGuiApplicationHelper palette
   itemBackground color, consistent with SheetBrowser.cpp:72
3. Impact: magnifier center now follows system theme in dark mode,
   no behavior change for light mode users

Log: Fix magnifier background color not adapting to dark mode

Influence:
1. Test magnifier on non-content area in light mode
2. Test magnifier on non-content area in dark mode
3. Verify magnifier still shows page content correctly

fix: 放大镜背景色适配深色模式

1. 根因:BrowserMagniFier::setMagniFierImage() 在图像为空时
   硬编码 Qt::white 填充放大镜中心,不随系统主题变化
2. 方案:将 Qt::white 替换为 DGuiApplicationHelper 调色板
   itemBackground 颜色,与 SheetBrowser.cpp:72 保持一致
3. 影响:深色模式下放大镜中心跟随主题,浅色模式无行为变化

Log: 修复放大镜背景色不适配深色模式的问题

Influence:
1. 浅色模式下放大镜移至非内容区域测试
2. 深色模式下放大镜移至非内容区域测试
3. 验证放大镜正常显示页面内容无回归

Bug: #193251
@GongHeng2017
GongHeng2017 force-pushed the fix/pms-193251-magnifier-dark-mode branch from 66168d4 to f8c26bb Compare October 29, 2026 21:05
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