Skip to content

feat: enhance drag-and-drop visual feedback and folder icon animation #716

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-288931
Mar 3, 2026
Merged

feat: enhance drag-and-drop visual feedback and folder icon animation #716
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-288931

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Mar 2, 2026

feat: 增强拖放视觉反馈和文件夹图标动画效果

提供拖动应用到文件夹的动画效果,实现应用原地缩小以及位移到相应的文件夹的应用位置,
采用方案为获取鼠标位置大小,然后采用hotspot的坐标偏移,获取应用图标中心点,然后转为icon坐标系的坐标图标应该放置的应用图标中心点,从而解决由于缩放图标会产生的位置偏移问题。

另外去除 girdview
是由于计算位置正确,但是存在着显示问题却会偏移像素级位置,所以去除。

采用dragAndfolderBackground 为 文件夹的背景,
也是对应的drag时候的图标的背景。

PMS: BUG-288931 BUG-315679

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.

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

Please try again later or upgrade to continue using Sourcery

@wjyrich wjyrich marked this pull request as draft March 2, 2026 03:03
@wjyrich wjyrich changed the title fix: test animation with drag and drop/ feat: enhance drag-and-drop visual feedback and folder icon animation Mar 3, 2026
@wjyrich wjyrich marked this pull request as ready for review March 3, 2026 08:19
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.

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

Please try again later or upgrade to continue using Sourcery

feat: 增强拖放视觉反馈和文件夹图标动画效果

提供拖动应用到文件夹的动画效果,实现应用原地缩小以及位移到相应的文件夹的应用位置,
采用方案为获取鼠标位置大小,然后采用hotspot的坐标偏移,获取应用图标中心点,然后转为icon坐标系的坐标图标应该放置的应用图标中心点,从而解决由于缩放图标会产生的位置偏移问题。

另外去除 girdview
是由于计算位置正确,但是存在着显示问题却会偏移像素级位置,所以去除。

采用dragAndfolderBackground 为 文件夹的背景,
也是对应的drag时候的图标的背景。

PMS: BUG-288931 BUG-315679
@deepin-ci-robot
Copy link

deepin pr auto review

Git Diff 代码审查报告

总体评价

这段代码主要实现了拖拽图标到文件夹的动画效果,增强了用户体验。代码结构基本合理,但在一些细节上可以进一步优化。以下是详细的审查意见。

详细审查

1. 代码语法与逻辑

优点

  • 使用了Qt.callLater来确保在组件创建后执行动画逻辑,避免时机问题
  • 动画使用了ParallelAnimation来同时执行多个属性动画
  • 拖拽状态管理使用了布尔标志isDragHover来跟踪状态

改进建议

  1. FullscreenFrame.qml 和 WindowedFrame.qml 中的重复代码

    • 两个文件中都有相同的dndItem属性定义,建议提取为公共组件或使用继承
    • 这包括currentlyDraggedIdmergeAnimPending等属性
  2. IconItemDelegate.qml 中的动画逻辑

    • iconIntroAnim动画结束后重置了多个dndItem属性,但这些属性应该由设置它们的代码负责重置
    • 建议将动画结束后的清理逻辑集中管理
  3. 文件夹图标布局计算

    • getItemXgetItemY函数中的计算逻辑可以简化,使用更直观的数学表达式

2. 代码质量

优点

  • 使用了有意义的变量名
  • 代码结构清晰,注释适当

改进建议

  1. 魔法数字

    • FolderGridViewPopup.qmlroot.icons !== undefined检查可以改为更明确的属性检查
    • IconItemDelegate.qml中的0.26颜色值应该定义为命名常量
  2. 代码组织

    • IconItemDelegate.qml中的folderComponent组件可以提取为独立文件,提高可维护性
  3. 注释

    • 部分中文注释可以添加英文注释,提高国际化支持
    • 复杂的动画逻辑需要更详细的注释说明

3. 代码性能

优点

  • 使用了属性绑定而非频繁的更新
  • 动画使用了适当的时间和缓动函数

改进建议

  1. 动画性能

    • IconItemDelegate.qml中的多个NumberAnimation可以合并为一个PropertyAnimation,减少动画对象创建开销
    • 考虑使用Loader延迟加载动画组件,特别是对于不常用的动画
  2. 频繁属性访问

    • iconIntroAnim动画中多次访问root.maxIconSizeInFolder,可以缓存为局部变量
  3. 布局计算

    • getItemXgetItemY函数在每次属性变化时都会被调用,可以优化为只在必要时重新计算

4. 代码安全

优点

  • 拖拽操作前进行了ID验证
  • 使用了适当的数据类型

改进建议

  1. 输入验证

    • drag.getDataAsString的返回值应该进行更严格的验证,防止空值或无效值
    • mapFromItem的坐标计算应该添加边界检查
  2. 状态管理

    • mergeAnimPending标志可能在动画未完成时被意外重置,建议添加状态检查
    • 拖拽操作中的多个异步操作应该添加错误处理
  3. 资源管理

    • 动画结束后应该显式释放资源
    • grabToImage的结果应该添加错误处理

具体代码改进建议

1. 提取公共属性为组件

// DragAndDropManager.qml
QtObject {
    id: root
    
    property string currentlyDraggedId
    property string currentlyDraggedIconName
    property bool mergeAnimPending: false
    property string mergeAnimTargetIcon: ""
    property string mergeAnimTargetIcon2: ""
    property real mergeAnimStartX: 0
    property real mergeAnimStartY: 0
    property real mergeSize: 0
    
    signal dragEnded()
    
    function reset() {
        currentlyDraggedId = ""
        currentlyDraggedIconName = ""
        mergeAnimPending = false
        mergeAnimTargetIcon = ""
        mergeAnimTargetIcon2 = ""
        mergeAnimStartX = 0
        mergeAnimStartY = 0
        mergeSize = 0
    }
}

2. 优化文件夹图标布局计算

// IconItemDelegate.qml
function getItemX(index) {
    const col = index % maxIconCount
    return spacing + col * (itemWidth + spacing)
}

function getItemY(index) {
    const row = Math.floor(index / maxIconCount)
    return spacing + row * (itemHeight + spacing)
}

3. 改进动画性能

// IconItemDelegate.qml
ParallelAnimation {
    id: iconIntroAnim
    onStarted: root.iconIntroAnimRunning = true
    
    PropertyAnimation {
        target: folderIcon
        properties: "scale,x,y"
        to: {
            "scale": (itemWidth / root.maxIconSizeInFolder) * root.iconScaleFactor,
            "x": iconItem.getItemX(index),
            "y": iconItem.getItemY(index)
        }
        duration: 400
        easing.type: Easing.OutExpo
    }
    
    onFinished: {
        root.iconIntroAnimRunning = false
        // 不在这里重置dndItem属性,由设置它们的代码负责
    }
}

4. 添加输入验证

// FullscreenFrame.qml
onDropped: function (drop) {
    let dragId = drop.getDataAsString("text/x-dde-launcher-dnd-desktopId")
    if (!dragId || dragId === "") {
        console.warn("Invalid drag ID received")
        return
    }
    
    // 添加边界检查
    if (drop.x < 0 || drop.x > width || drop.y < 0 || drop.y > height) {
        console.warn("Drop position out of bounds")
        return
    }
    
    // 其余代码...
}

总结

这段代码实现了拖拽动画功能,整体质量良好,但存在一些可以改进的地方:

  1. 减少代码重复,提取公共组件
  2. 优化动画性能,减少不必要的计算
  3. 加强输入验证和错误处理
  4. 提高代码可维护性,添加更详细的注释

建议在后续版本中逐步实施这些改进,以提高代码质量和可维护性。

@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

@wjyrich
Copy link
Contributor Author

wjyrich commented Mar 3, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 3, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 0848d6b into linuxdeepin:master Mar 3, 2026
8 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