Skip to content

fix: adjust search icon size in compact mode - #433

Open
GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/bug-224407-search-icon-size
Open

GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/bug-224407-search-icon-size

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

DTK's DSearchEdit hardcodes the internal DIconButton iconSize to 20×20 regardless of DSizeMode (dsearchedit.cpp:303). In deepin-reader's FindWidget, CompactMode sets the search edit height to 24px, making the icon ratio 83.3% (20/24) versus 55.6% (20/36) in NormalMode — visually the magnifier icon appears oversized. This was confirmed via an independent offscreen demo (repro/before.log).

Fix

Added a setSearchIconSize lambda in FindWidget::initWidget() that locates the internal DIconButton by accessibleName == "DSearchEditIconButton" and calls setIconSize. In NormalMode the icon is set to 20×20 (default), in CompactMode to 14×14 (ratio ~58.3%, matching NormalMode). Applied in both the initial setup block and the sizeModeChanged handler. This is a symptom-layer patch as adopted by the root-cause review conclusion; the root-cause DTK fix is out of scope.

Change Safety Assessment

Code Safety

  • Risk Level: Medium
  • The patch bypasses DSearchEdit encapsulation via findChildren to reach the internal DIconButton — a DTK upgrade changing the internal structure (accessibleName rename, layout change) could break the fix.
  • No historical fix is reverted; the change only appends iconSize-setting calls at the end of existing CompactMode/NormalMode branches without modifying existing logic.

Business Impact Scope

  • Affected module: Document viewer search bar (FindWidget).
  • User scenario: When the system is in CompactMode (紧凑模式), the magnifier icon in the search box will render at 14×14 instead of the hardcoded 20×20, making it visually proportional to the 24px search bar height.
  • NormalMode search icon is unchanged (20×20).

Verification Suggestion

  • Verify the search box magnifier icon appears proportionally sized in CompactMode (14×14) and NormalMode (20×20).
  • Verify icon size updates correctly when switching between NormalMode and CompactMode at runtime while the search box is open.

根因分析

DTK 的 DSearchEdit 将内部 DIconButton 的 iconSize 硬编码为 20×20,不随 DSizeMode 变化(dsearchedit.cpp:303)。deepin-reader 的 FindWidget 在 CompactMode 下将搜索框高度设为 24px,导致图标占比达 83.3%(20/24),而 NormalMode 为 55.6%(20/36),视觉上放大镜图标过大。此结论已通过独立 offscreen demo 验证(repro/before.log)。

修复方案

在 FindWidget::initWidget() 中新增 setSearchIconSize lambda,通过 accessibleName == "DSearchEditIconButton" 定位内部 DIconButton 并调用 setIconSize。NormalMode 设为 20×20(默认),CompactMode 设为 14×14(占比约 58.3%,与 NormalMode 一致)。初始设置块与 sizeModeChanged 回调中同步调用。本修复为症状层补丁,根因层 DTK 修复不在本次范围。

改动安全评估

代码安全评估

  • 风险等级: 中风险
  • 本补丁通过 findChildren 绕过 DSearchEdit 封装直接操作内部 DIconButton,DTK 升级若改变内部结构(accessibleName 改名、控件层级调整)可能导致修复失效。
  • 不撤销任何历史修复;改动仅在现有 CompactMode/NormalMode 分支末尾追加 iconSize 设置,不修改已有逻辑。

业务影响范围

  • 受影响模块: 文档查看器搜索栏(FindWidget)。
  • 用户场景: 系统处于紧凑模式时,搜索框放大镜图标将以 14×14 渲染,与 24px 搜索框高度比例协调。
  • 普通模式下搜索图标无变化(20×20)。

验证建议

  • 验证紧凑模式下搜索框放大镜图标尺寸为 14×14,普通模式下为 20×20。
  • 验证运行时在普通模式与紧凑模式间切换时,图标尺寸同步更新。

Summary by Sourcery

Adjust the FindWidget search icon sizing to keep it visually proportional across supported UI size modes.

Bug Fixes:

  • Scale the document viewer search icon appropriately in compact mode while preserving the existing normal-mode size.

Enhancements:

  • Update the search icon size when switching between normal and compact UI modes at runtime.

1. Root cause: DSearchEdit hardcodes DIconButton iconSize to 20x20
   regardless of SizeMode, so in CompactMode (search edit height 24px)
   the icon ratio reaches 83.3% vs 55.6% in NormalMode (height 36px)
2. Fix: add setSearchIconSize lambda in FindWidget to set the internal
   DIconButton iconSize to 20 in NormalMode and 14 in CompactMode,
   applied in both initial setup and the sizeModeChanged handler
3. Impact: only affects FindWidget search icon visual size in
   CompactMode; NormalMode icon size unchanged, no behavior change

Log: Adjusted search magnifier icon size to match compact mode layout

Influence:
1. Test search box icon display in NormalMode (icon should be 20x20)
2. Test search box icon display in CompactMode (icon should be 14x14)
3. Test icon size updates when switching SizeMode at runtime

fix: 调整紧凑模式下搜索图标尺寸

1. 根因:DSearchEdit 硬编码 DIconButton iconSize 为 20×20,不随
   SizeMode 变化,CompactMode 下搜索框高度仅 24px 时图标占比达
   83.3%(NormalMode 为 55.6%),视觉上放大镜图标过大
2. 方案:在 FindWidget 中新增 setSearchIconSize lambda,NormalMode
   设 20、CompactMode 设 14,初始设置与 sizeModeChanged 回调中
   同步调用
3. 影响:仅影响 CompactMode 下搜索框图标的视觉尺寸,NormalMode
   无行为变化

Log: 调整紧凑模式下搜索放大镜图标尺寸以匹配布局比例

Influence:
1. 测试普通模式下搜索框图标显示(应为 20×20)
2. 测试紧凑模式下搜索框图标显示(应为 14×14)
3. 测试运行时在普通模式与紧凑模式间切换时图标尺寸是否同步更新

PMS: BUG-224407
@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

Adjusts the FindWidget search magnifier to remain visually proportional across size modes by reaching the DSearchEdit internal icon button and applying mode-specific sizes during initial setup and subsequent size-mode changes.

Sequence diagram for responsive search icon sizing

sequenceDiagram
    participant FindWidget
    participant DGuiApplicationHelper
    participant DSearchEdit
    participant DIconButton

    FindWidget->>DSearchEdit: findChildren<DIconButton *>()
    DSearchEdit-->>FindWidget: DSearchEditIconButton
    FindWidget->>DIconButton: setIconSize(QSize(20, 20))
    DGuiApplicationHelper-->>FindWidget: sizeModeChanged(sizeMode)
    alt NormalMode
        FindWidget->>DSearchEdit: findChildren<DIconButton *>()
        DSearchEdit-->>FindWidget: DSearchEditIconButton
        FindWidget->>DIconButton: setIconSize(QSize(20, 20))
    else CompactMode
        FindWidget->>DSearchEdit: findChildren<DIconButton *>()
        DSearchEdit-->>FindWidget: DSearchEditIconButton
        FindWidget->>DIconButton: setIconSize(QSize(14, 14))
    end
Loading

File-Level Changes

Change Details Files
Override the search edit’s internal icon size according to the active UI size mode.
  • Locate the internal icon button by its accessible name and set its icon size.
  • Use 20×20 in NormalMode and 14×14 in CompactMode.
  • Apply the sizing during initialization and on runtime size-mode changes.
reader/widgets/FindWidget.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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了紧凑模式下搜索图标尺寸未调整的问题,通过引入lambda函数setSearchIconSize统一设置图标大小,代码逻辑正确,无安全漏洞,四维度均通过。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: ['可考虑将lambda捕获改为 [searchEdit = m_pSearchEdit](int size),使依赖更显式并降低耦合']


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 建议改进:直接捕获 m_pSearchEdit 而非 this,使依赖更显式
auto setSearchIconSize = [searchEdit = m_pSearchEdit](int size) {
    const auto buttons = searchEdit->findChildren<DIconButton *>();
    for (auto btn : buttons) {
        if (btn->accessibleName() == QStringLiteral("DSearchEditIconButton")) {
            btn->setIconSize(QSize(size, size));
            break;
        }
    }
};

本报告由 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