Fix: Optimize tooltip positioning logic.#580
Fix: Optimize tooltip positioning logic.#580deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's GuideRefactors AlertToolTip from a ToolTip/Popup-based component to a regular Control-based item that lives in the content visual tree, adds explicit text/timeout handling and a custom enter animation, and adjusts layout/connector positioning so the tooltip scrolls and clips correctly with its target. Sequence diagram for updated tooltip positioning and scrolling behaviorsequenceDiagram
actor User
participant Viewport
participant TargetItem
participant NewAlertToolTip as AlertToolTip_ControlItem
User->>TargetItem: hover
TargetItem->>NewAlertToolTip: set target, text, timeout
NewAlertToolTip->>NewAlertToolTip: compute _displayY = target.height
NewAlertToolTip->>NewAlertToolTip: set y = _displayY + spacing
NewAlertToolTip->>NewAlertToolTip: enterAnim.start()
User->>Viewport: scroll or resize window
Viewport->>TargetItem: layout updated (position, clipping)
TargetItem->>NewAlertToolTip: position follows parent in content tree
NewAlertToolTip->>NewAlertToolTip: y recomputed via binding to _displayY
Note over NewAlertToolTip: Tooltip remains aligned and clipped with TargetItem
User->>NewAlertToolTip: wait for timeout
NewAlertToolTip->>NewAlertToolTip: Timer triggers onTriggered
NewAlertToolTip->>NewAlertToolTip: visible = false
Updated class diagram for AlertToolTip Control-based implementationclassDiagram
class AlertToolTip {
+Item target
+string text
+int timeout
+real _displayY
+int x
+int y
+int topPadding
+int bottomPadding
+int leftPadding
+int rightPadding
+int implicitWidth
+int implicitHeight
+int z
}
class FloatingPanel {
+int radius
+int borderWidth
+int margins
+int normalColor
+int borderColor
}
class ContentText {
+Palette textColor
+int horizontalAlignment
+int verticalAlignment
+int fontPixelSize
+string fontFamily
+bool wrapMode
}
class TooltipTimer {
+int interval
+bool running
+onTriggered()
}
class EnterAnimation {
+AlertToolTip target
+string property
+real from
+real to
+int duration
+start()
}
class ConnectorBoxShadow {
+Palette dropShadowColor
+Palette backgroundColor
+Palette borderColor
+real x
+real y
+int width
+int height
+int shadowBlur
+int radius
+int cornerRadius
}
AlertToolTip o-- FloatingPanel : background
AlertToolTip o-- ContentText : contentItem
AlertToolTip o-- TooltipTimer : timer
AlertToolTip o-- EnterAnimation : enterAnim
AlertToolTip o-- ConnectorBoxShadow : connectorShadow
AlertToolTip --> Item : target
ContentText --> AlertToolTip : owner
TooltipTimer --> AlertToolTip : controls_visibility
EnterAnimation --> AlertToolTip : animates_y
ConnectorBoxShadow --> AlertToolTip : anchored_to_tooltip
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The new
textproperty onControlis never bound tocontentText.text, so the tooltip content will always be empty; consider wiringcontentText.text: control.text(or equivalent) to preserve behavior. - The enter animation is only triggered once via
Component.onCompleted, so reopening the tooltip by togglingvisiblewill not re-run the animation; consider starting the animation inonVisibleChangedwhen becoming visible instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `text` property on `Control` is never bound to `contentText.text`, so the tooltip content will always be empty; consider wiring `contentText.text: control.text` (or equivalent) to preserve behavior.
- The enter animation is only triggered once via `Component.onCompleted`, so reopening the tooltip by toggling `visible` will not re-run the animation; consider starting the animation in `onVisibleChanged` when becoming visible instead.
## Individual Comments
### Comment 1
<location path="qt6/src/qml/AlertToolTip.qml" line_range="52" />
<code_context>
- // NumberAnimation { properties: "opacity"; from: 0.0; to: 1.0; duration: 200 }
- NumberAnimation { properties: "y"; from: control.target.height; to: control.target.height + DS.Style.control.spacing; duration: 200 }
- }
+ Component.onCompleted: enterAnim.start()
- exit: Transition {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The enter animation only runs once on component creation, not on subsequent show/hide cycles.
With `Component.onCompleted: enterAnim.start()`, the enter animation only runs once when the tooltip instance is created. Re-showing the same control (e.g. toggling `visible` or reusing the instance) won’t trigger the enter animation again, changing the previous behavior. To match the old behavior, start `enterAnim` in response to visibility or state changes instead of only on creation.
Suggested implementation:
```
onVisibleChanged: if (visible) enterAnim.restart()
```
If the tooltip uses a different property or state to represent "shown" (e.g. `control.visible`, a `state` change, or `control.toolTipVisible`), replace `visible` in the handler with the appropriate property or attach the handler to the root/control item that actually changes visibility. This ensures the enter animation runs on every show cycle, matching the old `enter` transition behavior.
</issue_to_address>
### Comment 2
<location path="qt6/src/qml/AlertToolTip.qml" line_range="54-60" />
<code_context>
- exit: Transition {
- // NumberAnimation { properties: "opacity"; from: 1.0; to: 0.0 }
- NumberAnimation { properties: "y"; from: control.target.height + DS.Style.control.spacing ; to: control.target.height }
+ NumberAnimation {
+ id: enterAnim
+ target: control
+ property: "y"
+ from: control._displayY
+ to: control._displayY + DS.Style.control.spacing
+ duration: 200
}
</code_context>
<issue_to_address>
**question:** Only the enter animation remains; the exit animation was removed, changing the close behavior.
With only the enter `NumberAnimation`, the tooltip now vanishes instantly (e.g., when the timeout triggers) instead of animating out. If that behavior isn’t desired and you want consistent UX, consider reintroducing a matching exit animation or using states/transitions to preserve the previous behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
qt6/src/qml/AlertToolTip.qml
Outdated
| // NumberAnimation { properties: "opacity"; from: 0.0; to: 1.0; duration: 200 } | ||
| NumberAnimation { properties: "y"; from: control.target.height; to: control.target.height + DS.Style.control.spacing; duration: 200 } | ||
| } | ||
| Component.onCompleted: enterAnim.start() |
There was a problem hiding this comment.
suggestion (bug_risk): The enter animation only runs once on component creation, not on subsequent show/hide cycles.
With Component.onCompleted: enterAnim.start(), the enter animation only runs once when the tooltip instance is created. Re-showing the same control (e.g. toggling visible or reusing the instance) won’t trigger the enter animation again, changing the previous behavior. To match the old behavior, start enterAnim in response to visibility or state changes instead of only on creation.
Suggested implementation:
onVisibleChanged: if (visible) enterAnim.restart()
If the tooltip uses a different property or state to represent "shown" (e.g. control.visible, a state change, or control.toolTipVisible), replace visible in the handler with the appropriate property or attach the handler to the root/control item that actually changes visibility. This ensures the enter animation runs on every show cycle, matching the old enter transition behavior.
qt6/src/qml/AlertToolTip.qml
Outdated
| NumberAnimation { | ||
| id: enterAnim | ||
| target: control | ||
| property: "y" | ||
| from: control._displayY | ||
| to: control._displayY + DS.Style.control.spacing | ||
| duration: 200 |
There was a problem hiding this comment.
question: Only the enter animation remains; the exit animation was removed, changing the close behavior.
With only the enter NumberAnimation, the tooltip now vanishes instantly (e.g., when the timeout triggers) instead of animating out. If that behavior isn’t desired and you want consistent UX, consider reintroducing a matching exit animation or using states/transitions to preserve the previous behavior.
qt6/src/qml/AlertToolTip.qml
Outdated
| } | ||
|
|
||
| contentItem: Text { | ||
| id: contentText |
qt6/src/qml/AlertToolTip.qml
Outdated
| exit: Transition { | ||
| // NumberAnimation { properties: "opacity"; from: 1.0; to: 0.0 } | ||
| NumberAnimation { properties: "y"; from: control.target.height + DS.Style.control.spacing ; to: control.target.height } | ||
| NumberAnimation { |
There was a problem hiding this comment.
是不是不需要定义这条个_displayY,这个直接用动画Behavior on y 就行了吧,
5acf10f to
7d7cac4
Compare
qt6/src/qml/AlertToolTip.qml
Outdated
| Timer { | ||
| interval: control.timeout | ||
| running: control.timeout > 0 && control.visible | ||
| onTriggered: control.visible = false |
There was a problem hiding this comment.
这样弄的话,之前通过visible绑定的就丢掉了,
另外,查看下需不需要加上show这种之前popup提供的接口,兼容一下,
e52a343 to
8111b24
Compare
| // from binding context during recreation. | ||
| Loader { | ||
| active: showAlert && alertText.length !== 0 | ||
| active: alertText.length !== 0 |
qt6/src/qml/AlertToolTip.qml
Outdated
| } | ||
|
|
||
| onVisibleChanged: { | ||
| if (visible) { |
There was a problem hiding this comment.
这里是重置_expired吧,不管什么时候都需要的话,优化下代码,
| NumberAnimation { duration: 200 } | ||
| } | ||
| opacity: _shown ? 1 : 0 | ||
| enabled: _shown |
Log: The Popup is rendered on the window's Overlay layer and is not part of the content visual tree. As a result, the tooltip does not follow its anchor item during scrolling or window resizing, causing positional drift. To resolve this, AlertToolTip has been changed from a ToolTip (which uses Popup) to a regular Item, making it part of the content visual tree. This ensures it naturally scrolls with its parent, respects container clipping, and maintains correct positioning at all times. PMS: bug-341973
deepin pr auto review这段代码主要对 1. 语法逻辑审查
2. 代码质量
3. 代码性能
4. 代码安全
改进意见
总结这段代码重构总体上是积极且高质量的。它解决了 主要优点:
建议关注点:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, JWWTSL The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Log: The Popup is rendered on the window's Overlay layer and is not part of the content visual tree. As a result, the tooltip does not follow its anchor item during scrolling or window resizing, causing positional drift. To resolve this, AlertToolTip has been changed from a ToolTip (which uses Popup) to a regular Item, making it part of the content visual tree. This ensures it naturally scrolls with its parent, respects container clipping, and maintains correct positioning at all times.
PMS: bug-341973
Summary by Sourcery
Convert the alert tooltip to a regular control-based item to keep its position in sync with its target within the content visual tree.
Bug Fixes:
Enhancements: