@@ -306,6 +306,15 @@ Item {
306306 if (! drag .active ) {
307307 Panel .contextDragging = false
308308 root .dragFinished ()
309+ // 确保拖拽结束时关闭回收站提示
310+ if (root .itemId === " dde-trash" ) {
311+ console .warn (" MouseArea drag.onActiveChanged: drag finished, closing dragToolTip for trash" )
312+ isDragOver = false
313+ shouldShowTooltip = false
314+ tooltipVisible = false
315+ tooltipDelayTimer .stop ()
316+ dragToolTip .close ()
317+ }
309318 return
310319 }
311320 Panel .contextDragging = true
@@ -409,24 +418,103 @@ Item {
409418 DropArea {
410419 anchors .fill : parent
411420 keys: [" dfm_app_type_for_drag" ]
421+
422+ property bool isDragOver: false
423+ property var lastDragPosition: Qt .point (0 , 0 )
424+ property int dragStableThreshold: 5 // 像素阈值,小于这个距离的移动不重新计算位置
425+ property bool shouldShowTooltip: false
426+ property int lastEnterTime: 0
427+ property int lastExitTime: 0
428+ property int debounceThreshold: 50 // 50ms防抖阈值,更严格的防抖
429+ property bool tooltipVisible: false
412430
413431 onEntered : function (drag ) {
432+ var currentTime = Date .now ()
433+ console .warn (" AppItem DropArea onEntered:" , root .itemId , " drag entered at time" , currentTime, " last exit:" , lastExitTime, " diff:" , currentTime - lastExitTime)
434+
435+ // 如果距离上次退出时间太短,忽略这次进入事件
436+ if (currentTime - lastExitTime < debounceThreshold) {
437+ console .warn (" AppItem DropArea onEntered: ignoring rapid enter event, too soon after exit" )
438+ return
439+ }
440+
414441 if (root .itemId === " dde-trash" ) {
415- var point = root .mapToItem (null , root .width / 2 , root .height / 2 )
416- dragToolTip .DockPanelPositioner .bounding = Qt .rect (point .x , point .y , dragToolTip .width , dragToolTip .height )
417- dragToolTip .open ()
442+ isDragOver = true
443+ lastDragPosition = Qt .point (drag .x , drag .y )
444+ lastEnterTime = currentTime
445+ shouldShowTooltip = true
446+ // 如果提示已经显示,不再重新显示
447+ if (! tooltipVisible) {
448+ // 使用定时器延迟显示,避免快速切换
449+ tooltipDelayTimer .start ()
450+ }
418451 }
419452 }
420453
421454 onExited : function (drag ) {
455+ var currentTime = Date .now ()
456+ console .warn (" AppItem DropArea onExited:" , root .itemId , " drag exited at time" , currentTime, " last enter:" , lastEnterTime, " diff:" , currentTime - lastEnterTime)
457+
458+ // 如果距离上次进入时间太短,忽略这次退出事件
459+ if (currentTime - lastEnterTime < debounceThreshold) {
460+ console .warn (" AppItem DropArea onExited: ignoring rapid exit event, too soon after enter" )
461+ return
462+ }
463+
422464 if (root .itemId === " dde-trash" ) {
465+ isDragOver = false
466+ lastExitTime = currentTime
467+ shouldShowTooltip = false
468+ tooltipVisible = false
469+ tooltipDelayTimer .stop ()
470+ console .warn (" AppItem DropArea onExited: closing dragToolTip for trash" )
423471 dragToolTip .close ()
424472 }
425473 }
474+
475+ onPositionChanged : function (drag ) {
476+ if (root .itemId === " dde-trash" && isDragOver && drag) {
477+ var currentPos = Qt .point (drag .x , drag .y )
478+ var distance = Math .sqrt (Math .pow (currentPos .x - lastDragPosition .x , 2 ) + Math .pow (currentPos .y - lastDragPosition .y , 2 ))
479+
480+ console .warn (" AppItem DropArea onPositionChanged: drag moved" , distance, " pixels, threshold:" , dragStableThreshold)
481+
482+ // 只有当移动距离超过阈值时才更新提示位置
483+ if (distance > dragStableThreshold) {
484+ lastDragPosition = currentPos
485+ var point = root .mapToItem (null , root .width / 2 , root .height / 2 )
486+ console .warn (" AppItem DropArea onPositionChanged: updating dragToolTip position to" , point .x , point .y )
487+ dragToolTip .DockPanelPositioner .bounding = Qt .rect (point .x , point .y , dragToolTip .width , dragToolTip .height )
488+ }
489+ }
490+ }
426491
427492 onDropped : function (drop ){
493+ console .warn (" AppItem DropArea onDropped: files dropped on" , root .itemId )
494+ if (root .itemId === " dde-trash" ) {
495+ isDragOver = false
496+ shouldShowTooltip = false
497+ tooltipVisible = false
498+ tooltipDelayTimer .stop ()
499+ dragToolTip .close ()
500+ console .warn (" AppItem DropArea onDropped: closing dragToolTip for trash after drop" )
501+ }
428502 root .dropFilesOnItem (root .itemId , drop .urls )
429503 }
504+
505+ Timer {
506+ id: tooltipDelayTimer
507+ interval: 50 // 50ms延迟,更快的响应
508+ onTriggered: {
509+ if (shouldShowTooltip && isDragOver) {
510+ var point = root .mapToItem (null , root .width / 2 , root .height / 2 )
511+ console .warn (" AppItem DropArea tooltipDelayTimer: opening dragToolTip for trash at point" , point .x , point .y )
512+ dragToolTip .DockPanelPositioner .bounding = Qt .rect (point .x , point .y , dragToolTip .width , dragToolTip .height )
513+ dragToolTip .open ()
514+ tooltipVisible = true
515+ }
516+ }
517+ }
430518 }
431519
432520 onWindowsChanged: {
0 commit comments