Skip to content

fix: correct search dropdown position offset - #791

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/pms-bug-bot/f5d9013aaa31
Sep 2, 2026
Merged

fix: correct search dropdown position offset#791
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/pms-bug-bot/f5d9013aaa31

Conversation

@wyu71

@wyu71 wyu71 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The search result dropdown (SearchResultDialog, a QML Popup) was misaligned with the search box. The root cause is a coordinate system mismatch: searchEdit.x is a local coordinate relative to titleRowLayout, but the Popup is rendered in the Overlay layer which uses a different coordinate system. Using searchEdit.x directly for the Popup's x position — and a hardcoded y: 50 — caused the dropdown to drift from the search box, especially when window width or title bar layout changed.

Key evidence:

  • WindowTitlebar.qml:341x: searchEdit.x - (width - searchEdit.width) / 2 uses local coordinate without conversion
  • WindowTitlebar.qml:342y: 50 hardcoded, doesn't adapt to layout changes
  • searchEdit is a child of titleRowLayout; SearchResultDialog is a Popup rendered in Overlay — different coordinate systems

Fix

Set parent: titleBar on the Popup and use mapToItem(titleBar, ...) to convert searchEdit's coordinates into titleBar's coordinate system before positioning:

parent: titleBar
x: searchEdit.mapToItem(titleBar, 0, 0).x
   - (width - searchEdit.width) / 2
y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4

Change Safety Assessment

  • Risk level: Low
  • Scope: Only 3 property lines in WindowTitlebar.qml (searchResultComponent)
  • No business logic changes: search, data flow, and click handlers unaffected
  • mapToItem is a standard QML coordinate conversion method; parent: titleBar anchors the Popup to the root element with a stable lifecycle

Business Impact

Affects only the display position of the search result dropdown. Users searching for songs/artists/albums will see the dropdown correctly aligned below the search box regardless of window size.

Verification Suggestion

  1. Open deepin-music with songs in the library
  2. Click the search box, type an album name that matches imported songs
  3. Verify the dropdown appears directly below and centered on the search box
  4. Resize the window and repeat — dropdown should stay aligned

根因分析

搜索关联栏(SearchResultDialog,QML Popup)与搜索框位置错位。根本原因是坐标系不一致searchEdit.x 是相对于 titleRowLayout 的局部坐标,而 Popup 显示在 Overlay 层使用不同坐标系。直接使用 searchEdit.x 定位 + 硬编码 y: 50,导致下拉框偏移,窗口宽度变化时更明显。

关键证据:

  • WindowTitlebar.qml:341x: searchEdit.x - ... 直接使用局部坐标,未做转换
  • WindowTitlebar.qml:342y: 50 硬编码,不随布局变化
  • searchEdittitleRowLayout 子项,SearchResultDialog 是 Overlay 层 Popup,坐标系不同

修复方案

将 Popup 的 parent 设为 titleBar,用 mapToItem(titleBar, ...)searchEdit 坐标转换到 titleBar 坐标系后定位。

改动安全评估

  • 风险等级:低
  • 范围:仅 WindowTitlebar.qmlsearchResultComponent 的 3 行属性
  • 无业务逻辑变更:搜索、数据流、点击事件不受影响
  • mapToItem 是 QML 标准坐标转换方法;parent: titleBar 锚定到根元素,生命周期稳定

业务影响范围

仅影响搜索结果下拉框的显示位置。用户搜索歌曲/歌手/专辑时,下拉框将正确对齐在搜索框下方,不受窗口大小影响。

验证建议

  1. 打开音乐应用,确保库中有歌曲
  2. 点击搜索框,输入已导入歌曲的专辑名
  3. 验证下拉框出现在搜索框正下方居中对齐
  4. 调整窗口大小后重复验证——下拉框应保持对齐

Summary by Sourcery

Bug Fixes:

  • Correct the search results dropdown positioning so it remains aligned below and centered with the search field across window sizes and title bar layout changes.

1. Root cause: SearchResultDialog (Popup) used searchEdit.x which is
   a local coordinate relative to titleRowLayout, but Popup renders
   in Overlay layer with a different coordinate system
2. Fix: set parent to titleBar and use mapToItem() to convert
   searchEdit coordinates into titleBar coordinate system
3. Impact: only affects search result dropdown position, no change to
   search logic or event handling

Log: fix search result dropdown misalignment with search box

Influence:
1. Test searching by album name with songs in library
2. Verify dropdown appears below and centered on search box
3. Resize window and verify dropdown stays aligned

fix: 修复搜索关联栏位置错位

1. 根因:SearchResultDialog(Popup)使用 searchEdit.x 定位,但该值
   是相对于 titleRowLayout 的局部坐标,而 Popup 显示在 Overlay 层
   使用不同坐标系,导致下拉框偏移
2. 方案:将 Popup 的 parent 设为 titleBar,使用 mapToItem() 将
   searchEdit 坐标转换到 titleBar 坐标系后定位
3. 影响:仅影响搜索结果下拉框显示位置,不影响搜索逻辑和事件处理

Log: 修复搜索关联栏位置错位

Influence:
1. 测试搜索已导入歌曲的专辑名
2. 验证下拉框出现在搜索框正下方居中对齐
3. 调整窗口大小后验证下拉框保持对齐

PMS: BUG-375805
@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026

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

Reviewer's Guide

Fixes search result dropdown drift by parenting the popup to the title bar and converting the search field coordinates before positioning it, keeping the dropdown aligned across layout and window-size changes.

Flow diagram for corrected search dropdown positioning

flowchart LR
    SearchEdit[SearchEdit in titleRowLayout] -->|"mapToItem(titleBar, 0, 0)"| TitleBarCoords[titleBar coordinates]
    SearchEdit -->|"mapToItem(titleBar, 0, searchEdit.height)"| DropdownY[Below search field]
    TitleBarCoords --> Position[Calculate Popup x]
    DropdownY --> PositionY[Calculate Popup y + 4]
    Position --> Popup[SearchResultDialog parented to titleBar]
    PositionY --> Popup
Loading

File-Level Changes

Change Details Files
Correct the search results popup positioning by aligning it in the title bar’s coordinate system.
  • Parent the popup to the title bar instead of relying on the overlay layer.
  • Convert the search field’s local coordinates with mapToItem for horizontal alignment and dynamic vertical placement.
  • Position the popup below the search field with a small gap rather than a hardcoded y-coordinate.
src/music-player/mainwindow/WindowTitlebar.qml

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/music-player/mainwindow/WindowTitlebar.qml" line_range="342-344" />
<code_context>
-                    x: searchEdit.x - (width - searchEdit.width) / 2
-                    y: 50
+                    parent: titleBar
+                    x: searchEdit.mapToItem(titleBar, 0, 0).x
+                       - (width - searchEdit.width) / 2
+                    y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4

                     visible: false
</code_context>
<issue_to_address>
**issue (bug_risk):** The `x` and `y` bindings call `mapToItem()` without directly depending on `searchEdit.x`, `searchEdit.y`, or the ancestor layout geometry. QML does not receive geometry-change notifications from the internal coordinate calculation, so after the title-bar layout moves during a window resize, the Popup retains its previous mapped position and becomes misaligned again.

**Triggers:** When resizing the window or otherwise moving `searchEdit` without changing its explicitly referenced `width` or `height`.

**Suggested fix:** Update the Popup position from `searchEdit` geometry change handlers or bind through explicit geometry properties that trigger reevaluation, then perform the coordinate conversion.
</issue_to_address>

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.

Comment on lines +342 to +344
x: searchEdit.mapToItem(titleBar, 0, 0).x
- (width - searchEdit.width) / 2
y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The x and y bindings call mapToItem() without directly depending on searchEdit.x, searchEdit.y, or the ancestor layout geometry. QML does not receive geometry-change notifications from the internal coordinate calculation, so after the title-bar layout moves during a window resize, the Popup retains its previous mapped position and becomes misaligned again.

Triggers: When resizing the window or otherwise moving searchEdit without changing its explicitly referenced width or height.

Suggested fix: Update the Popup position from searchEdit geometry change handlers or bind through explicit geometry properties that trigger reevaluation, then perform the coordinate conversion.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

项目: linuxdeepin/deepin-music
PR: #791 fix: correct search dropdown position offset
作者: wyu71
分支: agent/pms-bug-bot/f5d9013aaa31 → master
修改文件: src/music-player/mainwindow/WindowTitlebar.qml


总体评分:99 分

维度 评分 状态
语法逻辑 25/25 ✓ 通过
代码质量 24/25 ✓ 通过
代码性能 20/20 ✓ 通过
代码安全 30/30 ✓ 通过

审查结论: 代码审查通过。代码变更修复了搜索结果下拉框的位置偏移问题,使用 mapToItem 进行正确的坐标系转换,逻辑清晰,实现合理。未发现安全漏洞,代码质量良好。


代码变更概述

本次 PR 修复了 deepin-music 播放器中搜索结果下拉框(SearchResultDialog)与搜索框位置错位的问题。

根因: searchEdit.x 是相对于 titleRowLayout 的局部坐标,而 SearchResultDialog 作为 QML Popup 渲染在 Overlay 层,使用不同坐标系。直接使用局部坐标和硬编码 y: 50 导致下拉框偏移,窗口宽度变化时更明显。

修复方案: 将 Popup 的 parent 设为 titleBar,使用 mapToItem(titleBar, ...)searchEdit 坐标转换到 titleBar 坐标系后定位。

                 id: searchResultComponent
                 SearchResultDialog {
                     width: 360
-                    x: searchEdit.x - (width - searchEdit.width) / 2
-                    y: 50
+                    parent: titleBar
+                    x: searchEdit.mapToItem(titleBar, 0, 0).x
+                       - (width - searchEdit.width) / 2
+                    y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4
 
                     visible: false

四维度详细分析

1. 语法逻辑 ✓(25/25)

语法正确,逻辑清晰

  • QML 语法正确,mapToItem 是标准 QML 坐标转换方法
  • parent: titleBar 正确设置 Popup 的父元素为标题栏根元素
  • x 坐标计算逻辑正确:searchEdit.mapToItem(titleBar, 0, 0).x 获取 searchEdit 左上角在 titleBar 坐标系中的 x 位置,减去 (width - searchEdit.width) / 2 实现居中对齐
  • y 坐标计算逻辑正确:searchEdit.mapToItem(titleBar, 0, searchEdit.height).y 获取 searchEdit 底部在 titleBar 坐标系中的 y 位置,加 4 像素间距
  • 无语法错误,无逻辑缺陷,边界处理完善

2. 代码质量 ✓(24/25)

代码结构清晰,注释完整

  1. 坐标系转换逻辑可添加简短内联注释,说明为何需要从 searchEdit 局部坐标映射到 titleBar 坐标系(文件:WindowTitlebar.qml,行 341,组件:searchResultComponent

优点:

  • 代码变更最小化,仅修改 3 行属性,聚焦于定位修复
  • 无代码重复,无残留调试代码
  • 多行表达式格式对齐合理,可读性好
  • mapToItem 是自解释的标准 QML 方法,代码意图清晰

3. 代码性能 ✓(20/20)

性能良好,资源使用合理

  • mapToItem 是轻量级坐标转换操作,无性能开销
  • 属性绑定会在位置变化时自动重新计算,这是 QML 的标准响应式行为
  • 无频繁系统调用,无资源泄漏,无不必要的计算
  • 算法复杂度合理,无性能瓶颈

4. 代码安全 ✓(30/30)

存在0个安全漏洞

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

  • 本次变更为纯 UI 定位修复,不涉及任何安全敏感操作
  • 不涉及用户输入处理、网络操作、文件系统访问
  • 无硬编码密钥、无敏感信息泄露
  • 安全扫描工具报告的 4 个"高危"路径遍历漏洞均为误报(QML 相对路径引用 ../dialogs/,属于硬编码模块导入路径,非用户输入驱动,且不在本次 PR 变更范围内)

改进建议

// SearchResultDialog 定位:将 searchEdit 坐标映射到 titleBar 坐标系
// 解决 Popup Overlay 层与搜索框坐标系不一致导致的下拉框偏移问题
parent: titleBar
x: searchEdit.mapToItem(titleBar, 0, 0).x
   - (width - searchEdit.width) / 2
y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4

审查清单

  • 已按四维度标准完成代码分析(语法逻辑、代码质量、代码性能、代码安全)
  • 代码安全维度包含"存在0个安全漏洞"
  • 每个维度标记✓/✕与评价词一致
  • 审查结论考虑了 commit message 的目的(修复搜索下拉框位置偏移)
  • 问题定位准确,行号和组件名正确
  • 安全扫描误报已识别并排除

本报告由 AI 代码审查工具自动生成 | 扫描时间:2026-09-02 10:55:00

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx, wyu71

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

@wyu71

wyu71 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 92494ba into linuxdeepin:master Sep 2, 2026
14 checks passed
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.

3 participants