Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Nov 27, 2025

首次计算位置时先计算的bounding后设置的文字,所以首次计算结果肯定不正确.

Summary by Sourcery

Bug Fixes:

  • Fix initial tooltip position being misaligned on first hover by recalculating bounding after setting the tooltip text.

首次计算位置时先计算的bounding后设置的文字,所以首次计算结果肯定不正确.

PMS: BUG-340869
Log:
@BLumia BLumia requested a review from wjyrich November 27, 2025 08:42
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes an initial tooltip misalignment in AppItem.qml by ensuring the tooltip text is set before computing and applying its bounding rectangle for docking panel positioning.

Sequence diagram for corrected tooltip positioning on first hover

sequenceDiagram
    actor User
    participant AppItem as AppItem_QML
    participant Timer as HoverDelayTimer
    participant ToolTip as ToolTip_QML
    participant Positioner as DockPanelPositioner

    User->>AppItem: hover enters AppItem
    AppItem->>Timer: start(interval = 50ms)
    Timer-->>AppItem: triggered
    AppItem->>AppItem: point = mapToItem(null, width/2, height/2)
    AppItem->>ToolTip: set text(name or trashTipText)
    AppItem->>Positioner: set bounding(Qt.rect(point.x, point.y, ToolTip.width, ToolTip.height))
    AppItem->>ToolTip: open()
Loading

Flow diagram for tooltip bounding calculation order

flowchart TD
    A[Hover enters AppItem] --> B[Start HoverDelayTimer]
    B --> C[Timer triggered]
    C --> D[Calculate center point using mapToItem]
    D --> E[Set ToolTip.text based on itemId]
    E --> F[Set DockPanelPositioner.bounding using ToolTip.width and ToolTip.height]
    F --> G[Open ToolTip]
    G --> H[Tooltip appears centered on first hover]
Loading

File-Level Changes

Change Details Files
Ensure tooltip text is set before computing and applying its bounding rectangle so the initial tooltip position is centered correctly.
  • Reorder logic in the tooltip timer handler to assign toolTip.text before referencing toolTip.width and toolTip.height.
  • Compute DockPanelPositioner.bounding after the text is set so size-dependent positioning uses the correct tooltip dimensions.
  • Keep tooltip opening behavior the same while fixing the first-hover centering bug.
panels/dock/taskmanager/package/AppItem.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你分析这段代码的修改。这是一个关于工具提示(ToolTip)位置设置的改动。

  1. 代码逻辑分析:
  • 原代码先设置工具提示的边界矩形(bounding),然后设置文本内容
  • 修改后的代码先设置文本内容,再设置边界矩形
  • 这种改动是有意义的,因为工具提示的文本内容可能会影响其最终的宽度和高度
  1. 改进建议:
    代码逻辑是合理的,但还可以进一步优化:
Timer {
    interval: 50
    onTriggered: {
        // 先设置文本内容
        toolTip.text = root.itemId === "dde-trash" ? root.name + "-" + taskmanager.Applet.getTrashTipText() : root.name
        
        // 等待文本内容更新后再计算位置
        Qt.callLater(() => {
            var point = root.mapToItem(null, root.width / 2, root.height / 2)
            toolTip.DockPanelPositioner.bounding = Qt.rect(point.x, point.y, toolTip.width, toolTip.height)
            toolTip.open()
        })
    }
}
  1. 改进说明:
  • 使用 Qt.callLater 确保在文本内容更新完成后再计算工具提示的位置
  • 这样可以避免因文本内容变化导致的位置计算不准确的问题
  • 这种方式更加可靠,特别是在处理动态文本内容时
  1. 性能考虑:
  • Qt.callLater 的性能开销很小
  • 它只是将函数推迟到下一个事件循环中执行
  • 这种延迟对于确保UI正确更新是必要的
  1. 安全性:
  • 修改不会引入新的安全风险
  • 保持了原有的功能完整性
  • 只是改进了时序控制,使代码更加可靠

这个改进建议主要是为了确保工具提示的位置计算更加准确,特别是在处理动态文本内容时。虽然原代码的修改已经有所改进,但使用 Qt.callLater 可以使代码更加健壮。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Since the tooltip size now depends on setting toolTip.text before computing DockPanelPositioner.bounding, consider adding a short comment explaining this ordering constraint to prevent future refactors from accidentally reintroducing the bug.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the tooltip size now depends on setting `toolTip.text` before computing `DockPanelPositioner.bounding`, consider adding a short comment explaining this ordering constraint to prevent future refactors from accidentally reintroducing the bug.

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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, wjyrich

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

@BLumia BLumia merged commit 178fd7f into linuxdeepin:master Nov 27, 2025
8 of 11 checks passed
@BLumia BLumia deleted the pms-340869 branch November 27, 2025 08:45
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