Skip to content

fix: adapt search edit icon size to size mode - #798

Draft
GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/search-edit-icon-size-dtkwidget
Draft

GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/search-edit-icon-size-dtkwidget

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 29, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

DSearchEdit's search icon button size is hardcoded to QSize(20, 20) in DSearchEditPrivate::init() via createSearchIconButton lambda (src/widgets/dsearchedit.cpp:303). This value does not adapt to DSizeMode (compact/normal), causing the magnifying glass icon to appear oversized when the application is in compact mode. The same issue applies to both icon button instances: the visible search icon (iconbtn) and the leading-position action widget (iconAction).

Fix

Replace the hardcoded QSize(20, 20) with DSizeModeHelper::element(QSize(16, 16), QSize(20, 20)) so the icon size adapts to compact mode (16x16) vs normal mode (20x20). Additionally, connect DGuiApplicationHelper::sizeModeChanged signal to dynamically update both icon buttons when the size mode switches at runtime. This follows the same pattern used in dfloatingmessage.cpp and dfilechooseredit.cpp.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line (dsearchedit.cpp:303) was last modified by a sync commit (d639dcf), not a historical bug fix — this change does not revert any prior fix
  • No public API change, no signature change; only modifies a local variable initialization value and adds one signal connection

Business Impact Scope

All DSearchEdit instances across applications (e.g., file manager, control center) will now adapt search icon size to the current size mode. In compact mode, the magnifying glass icon will be 16x16 instead of 20x20, consistent with compact mode visual density. Switching size mode at runtime will dynamically update the icon.

Verification Suggestion

Verify DSearchEdit icon display in both normal and compact modes, and confirm dynamic update when switching size modes at runtime.


根因分析

DSearchEdit 的搜索图标按钮尺寸在 DSearchEditPrivate::init() 的 createSearchIconButton lambda 中被硬编码为 QSize(20, 20)(src/widgets/dsearchedit.cpp:303),不随 DSizeMode 自适应,导致紧凑模式下放大镜图标过大。两个图标按钮实例(iconbtn 和 iconAction)均存在此问题。

修复方案

将硬编码的 QSize(20, 20) 替换为 DSizeModeHelper::element(QSize(16, 16), QSize(20, 20)),使图标尺寸随紧凑模式(16x16)和正常模式(20x20)自适应。同时连接 DGuiApplicationHelper::sizeModeChanged 信号,在运行时切换尺寸模式时动态更新两个图标按钮的尺寸。此方案与 dfloatingmessage.cpp 和 dfilechooseredit.cpp 中的实现模式一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行(dsearchedit.cpp:303)最后由同步提交(d639dcf1)修改,非历史 bug 修复产物——本次改动不撤销任何已有修复
  • 无公开 API 变更、无签名变更;仅修改局部变量初始值并新增一条信号连接

业务影响范围

所有使用 DSearchEdit 控件的应用(如文件管理器、控制中心等)的搜索框图标将随尺寸模式自适应。紧凑模式下放大镜图标为 16x16(原为 20x20),与紧凑模式视觉密度一致。运行时切换尺寸模式时图标将动态更新。

验证建议

验证正常模式和紧凑模式下搜索框图标显示,并确认运行时切换尺寸模式时图标是否动态更新。

PMS: BUG-224407

Summary by Sourcery

Bug Fixes:

  • Adapt DSearchEdit search icon sizing to compact and normal size modes, including runtime mode changes.

@GongHeng2017
GongHeng2017 marked this pull request as draft October 29, 2026 20:55
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[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 DSearchEdit to use DSizeModeHelper for compact/normal search icon sizing and connects to sizeModeChanged so both icon-button instances stay synchronized when the application size mode changes.

Sequence diagram for dynamic DSearchEdit icon sizing

sequenceDiagram
    participant DSearchEdit
    participant DGuiApplicationHelper
    participant DSizeModeHelper
    participant iconbtn
    participant iconAction

    DSearchEdit->>DSizeModeHelper: element(QSize(16, 16), QSize(20, 20))
    DSizeModeHelper-->>DSearchEdit: iconSize
    DSearchEdit->>iconbtn: setIconSize(iconSize)
    DSearchEdit->>iconAction: setIconSize(iconSize)
    DSearchEdit->>DGuiApplicationHelper: connect(sizeModeChanged, updateIconSize)
    DGuiApplicationHelper-->>DSearchEdit: sizeModeChanged
    DSearchEdit->>DSizeModeHelper: element(QSize(16, 16), QSize(20, 20))
    DSizeModeHelper-->>DSearchEdit: iconSize
    DSearchEdit->>iconbtn: setIconSize(iconSize)
    DSearchEdit->>iconAction: setIconSize(iconSize)
Loading

File-Level Changes

Change Details Files
Make search icon sizing responsive to the application size mode.
  • Use 16×16 in compact mode and 20×20 in normal mode instead of a fixed 20×20 size.
  • Apply the computed size to both the visible icon button and leading action widget.
  • Recompute both icon sizes when the global size mode changes at runtime.
src/widgets/dsearchedit.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: DSearchEditPrivate::init() hardcoded icon size to
   QSize(20, 20) without DSizeMode awareness, causing oversized
   icon in compact mode
2. Fix: use DSizeModeHelper::element() for adaptive sizing and
   connect sizeModeChanged signal for dynamic updates
3. Impact: all DSearchEdit instances now adapt icon size to
   compact/normal mode

Log: Fix search edit icon not adapting to compact mode

Influence:
1. Test DSearchEdit icon display in normal mode
2. Test DSearchEdit icon display in compact mode
3. Verify icon updates when switching size modes at runtime

fix: 搜索框图标尺寸适配紧凑模式

1. 根因:DSearchEditPrivate::init() 硬编码图标尺寸为
   QSize(20, 20),不随 DSizeMode 自适应
2. 方案:使用 DSizeModeHelper::element() 实现自适应尺寸,
   并监听 sizeModeChanged 信号动态更新
3. 影响:所有 DSearchEdit 实例的图标尺寸将随紧凑/正常模式自适应

Log: 修复搜索框图标在紧凑模式下过大的问题

Influence:
1. 测试正常模式下搜索框图标显示
2. 测试紧凑模式下搜索框图标显示
3. 验证运行时切换尺寸模式时图标是否动态更新

PMS: BUG-224407
@GongHeng2017
GongHeng2017 force-pushed the fix/search-edit-icon-size-dtkwidget branch from e5484ed to 454516e Compare October 29, 2026 21:22

This branch has not been deployed

No deployments
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