Skip to content

fix(ButtonPanel): add hasAnimation check to enableAnimation property#629

Merged
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:animation
Jun 1, 2026
Merged

fix(ButtonPanel): add hasAnimation check to enableAnimation property#629
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:animation

Conversation

@mhduiy
Copy link
Copy Markdown
Contributor

@mhduiy mhduiy commented May 30, 2026

  1. Added D.DTK.hasAnimation guard to the enableAnimation condition in ButtonPanel
  2. Prevents animation from being enabled when the system or theme does not support it

Log: Add hasAnimation check to ButtonPanel enableAnimation to respect system animation settings

fix(ButtonPanel): 为 enableAnimation 属性添加 hasAnimation 检查

  1. 在 ButtonPanel 的 enableAnimation 条件中添加 D.DTK.hasAnimation 守卫
  2. 当系统或主题不支持动画时,避免启用动画

Log: 为 ButtonPanel 的 enableAnimation 添加 hasAnimation 检查,以遵循系统动画设置

Copy link
Copy Markdown

@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.

Sorry @mhduiy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Comment thread qt6/src/qml/private/ButtonPanel.qml Outdated
1. Remove CicleSpreadAnimation and its hover state handler from ButtonPanel
2. Remove Rectangle overlay and trigger function tied to button.hoveredChanged
3. Update copyright year to 2022-2026

Log: Remove CicleSpreadAnimation hover effect from ButtonPanel

refactor(ButtonPanel): 移除 CicleSpreadAnimation 悬停动画效果

1. 从 ButtonPanel 中移除 CicleSpreadAnimation 及其悬停状态处理器
2. 移除与 button.hoveredChanged 绑定的 Rectangle 覆盖层和 trigger 函数
3. 更新版权年份至 2022-2026

Log: 从 ButtonPanel 移除 CicleSpreadAnimation 悬停动画效果
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff 输入。本次代码变更主要涉及两部分:一是更新了版权声明年份,二是删除了 ButtonPanel.qml 中的 CicleSpreadAnimation 及其相关逻辑。

以下是我对本次代码变更的详细审查意见:

1. 语法逻辑

  • 删除逻辑的完整性:从当前 diff 来看,删除 CicleSpreadAnimation 及其内部逻辑是完整的,没有留下悬空的引用或未闭合的括号。
  • 潜在的业务逻辑缺失:删除这段代码意味着 ButtonPanel 失去了鼠标悬停时的波纹扩散动画效果。请确认这是否符合预期?如果是因为重构将动画逻辑移到了父组件或全局主题中,那是合理的;如果是直接砍掉了该交互,建议与 UI/UX 团队确认。
  • 关联代码清理:原代码中 visible: enableAnimation 依赖了一个名为 enableAnimation 的属性。删除动画组件后,请务必检查 enableAnimation 属性是否在文件其他位置或父组件中声明过。如果它是专为此动画服务的,应一并删除,避免留下无用代码。

2. 代码质量

  • 拼写错误随代码一同移除:原代码中存在拼写错误,函数名为 triggle(),正确的英语拼写应为 trigger()。随着这段代码的删除,这个拼写错误也被移除了,这是一个正向的改善。
  • 死代码清理:原代码中有一行被注释掉的 // gradient: ...,这也随着代码的删除被清理了,有助于提高代码的整洁度。
  • 建议:如果未来还需要实现类似的动画,建议注意命名规范,避免拼写错误。

3. 代码性能

  • 性能提升(正向):原实现在 Component.onCompleted 中使用了 button.hoveredChanged.connect(hoverAnimation.triggle)。在 QML 中,这种显式 connect 虽然可行,但如果在组件销毁时没有对应的 disconnect,或者组件生命周期复杂,容易导致内存泄漏或重复绑定。删除这段代码消除了这一潜在的性能隐患。
  • 更好的 QML 实践:如果未来需要恢复此功能,建议使用 QML 声明式的绑定方式,而不是命令式的 connect。例如:
    CicleSpreadAnimation {
        // ...
        onHoveredChanged: triggle() // 假设放在包含 button id 的作用域内
    }

4. 代码安全

  • 版权声明更新2022 - 2026 的修改符合法务合规要求,将版权保护期延伸至 2026 年,没有问题。
  • 无新增安全风险:本次变更为纯删除操作,且原代码中使用的 mapFromGlobalcursorPosition 均为 QML 标准且安全的 API,删除它们不会引入任何新的安全问题。

💡 附加建议(针对原代码的复盘)

虽然原代码已被删除,但为了帮助你在未来编写更优质的 QML 代码,我对原代码的写法做一个复盘:

点击查看原代码改进方案(如果保留的话)

如果这段动画逻辑需要保留或在未来重写,建议进行如下优化:

CicleSpreadAnimation {
    id: hoverAnimation
    anchors.fill: parent
    visible: enableAnimation

    Rectangle {
        anchors.fill: parent
        radius: control.radius
        color: control.D.ColorSelector.color1
    }

    // 1. 修正拼写错误 triggle -> trigger
    function trigger() {
        if (button.hovered) {
            // 2. 建议增加边界检查,防止 cursorPosition 返回无效值
            var pos = D.DTK.cursorPosition()
            if (pos) {
                hoverAnimation.centerPoint = hoverAnimation.mapFromGlobal(pos.x, pos.y)
                hoverAnimation.start()
            }
        } else {
            hoverAnimation.stop()
        }
    }

    // 3. 使用声明式绑定替代命令式 connect,更符合 QML 范式,且自动管理生命周期
    Connections {
        target: button
        function onHoveredChanged() {
            hoverAnimation.trigger()
        }
    }
}

总结:本次 Diff 整体变更清晰,删除了冗余和带有轻微代码异味(拼写错误、命令式 connect)的代码,且没有引入新的语法或安全问题。唯一需要确认的是:删除悬停动画是否符合产品需求,以及是否需要同步清理 enableAnimation 属性。

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

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

@mhduiy
Copy link
Copy Markdown
Contributor Author

mhduiy commented Jun 1, 2026

跟设计师沟通过,直接删除Hover下的扩散动画

@mhduiy mhduiy merged commit 0802dd7 into linuxdeepin:master Jun 1, 2026
18 of 20 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