Skip to content

Revert "Fix: Optimize tooltip positioning logic."#588

Open
JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
JWWTSL:revert-580-master
Open

Revert "Fix: Optimize tooltip positioning logic."#588
JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
JWWTSL:revert-580-master

Conversation

@JWWTSL
Copy link
Contributor

@JWWTSL JWWTSL commented Mar 19, 2026

Reverts #580

Summary by Sourcery

Revert recent tooltip optimization and restore the previous AlertToolTip behavior and usage.

Bug Fixes:

  • Restore AlertToolTip positioning and visibility behavior by switching back to a ToolTip-based implementation with explicit enter/exit transitions and no auto-hide timeout logic.
  • Ensure the edit panel only instantiates the alert tooltip when alerts are actually shown by reintroducing the showAlert condition to the Loader activation.

Enhancements:

  • Adjust AlertToolTip connector shadow positioning to account for margins and padding, keeping the visual connector aligned with the tooltip content.

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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

@github-actions
Copy link
Contributor

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts the previous tooltip optimization by switching AlertToolTip back to a ToolTip-based implementation with explicit enter/exit transitions and restores the prior loader activation behavior in EditPanel, while also updating the SPDX copyright years.

Class diagram for reverted AlertToolTip and EditPanel loader behavior

classDiagram
    class ToolTip
    class AlertToolTip {
        +Item target
        +int x
        +int y
        +int topPadding
        +int bottomPadding
        +int leftPadding
        +int rightPadding
        +int implicitWidth
        +int implicitHeight
        +int margins
        +int closePolicy
        +Transition enter
        +Transition exit
    }

    class EditPanel {
        +bool showAlert
        +string alertText
        +int alertDuration
    }

    class Loader {
        +bool active
        +Component sourceComponent
    }

    AlertToolTip --|> ToolTip
    EditPanel o-- Loader
    Loader o-- AlertToolTip
Loading

File-Level Changes

Change Details Files
Revert AlertToolTip from a custom Control-based implementation back to a ToolTip with original positioning, sizing, and animation behavior.
  • Change root element from Control back to ToolTip, removing custom timeout/_expired visibility management and auto-hide Timer logic.
  • Restore simple y-positioning based directly on target.height and DS.Style.control.spacing, without conditional spacing based on internal _shown state.
  • Simplify implicitWidth to always clamp tooltip width to target.width using DS.Style.control.implicitWidth(control).
  • Reintroduce margins property set to 0 and disable automatic closing with closePolicy set to Popup.NoAutoClose.
  • Add enter and exit Transitions that animate the tooltip’s y position instead of using Behavior on y and opacity changes.
  • Adjust BoxShadow connector positioning to account for topMargin and topPadding in the tooltip.
qt6/src/qml/AlertToolTip.qml
Restore original loader activation semantics in EditPanel so the AlertToolTip only loads when alerts are visible and non-empty.
  • Change Loader.active condition to depend on showAlert in addition to alertText being non-empty, reverting the always-active behavior for non-empty alertText.
qt6/src/qml/EditPanel.qml
Update licensing metadata to the previous copyright year range for AlertToolTip.qml.
  • Change SPDX-FileCopyrightText years from 2021-2026 back to 2021-2022.
qt6/src/qml/AlertToolTip.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
Contributor

deepin pr auto review

这份代码变更主要涉及两个QML文件:AlertToolTip.qmlEditPanel.qml。变更的核心是将 AlertToolTip 从一个自定义的 Control 重构为继承自 ToolTip(实际上是 Popup),并调整了相关的显示逻辑。以下是对代码变更的详细审查意见:

1. 代码逻辑与架构重构

优点:

  • 继承关系优化:将 AlertToolTip 的基类从通用的 Control 改为 ToolTip。这是一个合理的架构决策。ToolTip 本身继承自 PopupContentItem,内置了显示/隐藏、定位、延迟等机制。使用标准控件减少了重复造轮子,利用了 Qt Quick 框架的现有能力。
  • 移除冗余属性:移除了 texttimeout_expired 等属性。这些属性在 ToolTip 基类中已经存在或可以通过 Popup 的行为替代,简化了代码。
  • 移除手动定时器逻辑:原代码使用 Timer 手动控制 _expired 状态来处理超时隐藏。新代码依赖 ToolTip/Popup 的原生机制(尽管代码中设置了 closePolicy: Popup.NoAutoClose,这可能意味着超时逻辑被外部控制或移除了,需结合业务逻辑确认)。

潜在风险与改进建议:

  • closePolicy 设置:代码中设置了 closePolicy: Popup.NoAutoClose
    • 问题ToolTip 的默认行为通常是点击外部或按 ESC 关闭。设置为 NoAutoClose 意味着必须显式调用 close() 才能隐藏。
    • 审查:在 EditPanel.qml 中,Loaderactive 属性绑定为 showAlert && alertText.length !== 0。这意味着提示框的生命周期完全依赖于 Loader 的加载与卸载。
    • 建议:这种设计是可行的,但需要确保 showAlert 的逻辑非常严密。如果 showAlert 状态翻转导致组件销毁,exit 动画可能无法完整播放(因为组件被销毁了)。建议确认是否需要保留组件直到动画结束,或者确保动画足够快。
  • EditPanel.qml 中的 Loader 逻辑变更
    • 变更active 属性从 alertText.length !== 0 变更为 showAlert && alertText.length !== 0
    • 影响:这是一个逻辑增强。以前只要有文本就会加载组件(虽然可能不显示),现在必须显式设置 showAlert 标志位。这增加了控制粒度,防止了无文本时的无效加载,但也要求调用方必须正确维护 showAlert 状态。

2. 代码质量与可读性

优点:

  • 代码简化:移除了大量的状态管理代码(如 _expiredonVisibleChangedonTextChanged 中的重置逻辑),使得代码更专注于布局和样式。
  • 注释处理EditPanel.qml 中移除了关于 Loader 活跃状态的旧注释,因为新的逻辑已经不再依赖该技巧(直接通过 showAlert 控制),减少了误导性注释。

改进建议:

  • TODO 注释
    // TODO: Transparency causes tooltips to appear through the window background - temporarily removed
    // NumberAnimation { properties: "opacity"; from: 0.0; to: 1.0; duration: 200 }
    • 建议:这是一个已知的视觉缺陷。建议在缺陷跟踪系统中记录该问题,并在注释中引用 Issue ID,而不是仅仅保留 TODO。如果透明度问题短期内无法解决,应考虑是否有其他视觉方案(如淡入淡出背景色)来替代。
  • 魔法数字:代码中存在 0.75 这样的硬编码比例。
    y: - height * (0.75) - control.topMargin - control.topPadding
    • 建议:虽然 0.75 可能是几何计算(如三角形连接器的高度比例),但建议将其定义为具名常量(例如 connectorOffsetRatio),以提高代码可读性和可维护性。

3. 代码性能

优点:

  • 属性绑定优化y 坐标的计算从依赖 _shown 状态的复杂表达式简化为直接计算。
  • 减少重绘与重算:移除了 Behavior on y 中的 NumberAnimation(在旧代码中),转而在 enterexit Transition 中定义。这更符合 Qt Quick 的 Popup 生命周期模型,可能减少不必要的属性监听开销。

潜在问题:

  • implicitWidth 的安全性
    implicitWidth: Math.min(DS.Style.control.implicitWidth(control), target.width)
    • 问题:这里直接访问了 target.width。如果 targetnull(虽然 y 坐标处理了 target 为空的情况,但此处未显式判断),在 QML 中访问 null.width 可能会导致运行时错误或警告。
    • 建议:应改为 target ? Math.min(..., target.width) : ...,或者确保 target 属性设置是强制的。虽然原代码也是这样,但在重构时应一并修复。

4. 代码安全

  • 空指针检查:如上所述,implicitWidth 中对 target.width 的访问缺乏空值保护。
  • 版权年份AlertToolTip.qml 头部的版权年份从 2021 - 2026 更新为 2021 - 2022。这看起来像是一个修正(将未来的预测改为实际年份),或者是回退。如果是修正,这是正确的。

5. 具体代码细节审查

  • 动画逻辑
    enter: Transition {
        NumberAnimation { properties: "y"; from: control.target.height; to: control.target.height + DS.Style.control.spacing; duration: 200 }
    }
    • 审查:动画的起点和终点依赖于 control.target.height。如果在动画播放期间 target 的大小发生变化,动画效果可能会跳变。Qt Quick 的动画通常会绑定起始值,但这里需要确保 target 在显示期间是稳定的。

总结

这次重构总体上是正向的,通过继承 ToolTip 简化了组件逻辑,减少了自定义状态管理的复杂性。

主要改进建议:

  1. 安全性:修复 implicitWidth 中潜在的 target 为空访问问题。
  2. 可维护性:将几何计算中的魔法数字 0.75 提取为常量。
  3. 生命周期:确认 Loader 销毁组件时 exit 动画的播放情况,确保用户体验流畅。
  4. 缺陷追踪:为透明度动画的 TODO 添加缺陷追踪链接。

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 - I've left some high level feedback:

  • Several bindings assume target is always non-null (e.g., implicitWidth: Math.min(..., target.width) and the enter/exit transitions using control.target.height); consider guarding these with a null check to avoid runtime errors when target is not yet set.
  • Changing Loader.active back to showAlert && alertText.length !== 0 will reintroduce the destruction/recreation behavior that the previous comment explicitly worked around; if the original issue (wrong text from the binding context) is still relevant, it might be better to preserve the always-active loader or handle the context problem another way.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several bindings assume `target` is always non-null (e.g., `implicitWidth: Math.min(..., target.width)` and the `enter`/`exit` transitions using `control.target.height`); consider guarding these with a null check to avoid runtime errors when `target` is not yet set.
- Changing `Loader.active` back to `showAlert && alertText.length !== 0` will reintroduce the destruction/recreation behavior that the previous comment explicitly worked around; if the original issue (wrong text from the binding context) is still relevant, it might be better to preserve the always-active loader or handle the context problem another way.

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.

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