From 218ff83986140c972078689be1b6156fda7b49a2 Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Mon, 23 Jan 2023 10:25:18 +0800 Subject: [PATCH] plasmoid: port away from custom drag handler BUG: 464528 CCBUG: 402376 --- plasmoid/package/contents/ui/main.qml | 11 +++-------- plasmoid/package/contents/ui/task/TaskItem.qml | 12 +++++++++--- .../package/contents/ui/task/TaskMouseArea.qml | 15 +++++++++------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index 3972500f9..7a5c2d12b 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -598,7 +598,9 @@ Item { TaskManagerApplet.DragHelper { id: dragHelper - dragIconSize: units.iconSizes.medium + Drag.dragType: Drag.Automatic + Drag.supportedActions: Qt.CopyAction | Qt.MoveAction | Qt.LinkAction + Drag.onDragFinished: root.dragSource = null; } TaskManager.VirtualDesktopInfo { @@ -1273,11 +1275,6 @@ Item { return false; } - function resetDragSource() { - dragSource.z = 0; - dragSource = null; - } - ///REMOVE /*function createContextMenu(task) { var menu = root.contextMenuComponent.createObject(task); @@ -1307,7 +1304,6 @@ Item { } root.windowsHovered.connect(backend.windowsHovered); - dragHelper.dropped.connect(resetDragSource); updateListViewParent(); } @@ -1319,7 +1315,6 @@ Item { } root.windowsHovered.disconnect(backend.windowsHovered); - dragHelper.dropped.disconnect(resetDragSource); } //BEGIN states diff --git a/plasmoid/package/contents/ui/task/TaskItem.qml b/plasmoid/package/contents/ui/task/TaskItem.qml index 30d4f8f82..5b773a345 100644 --- a/plasmoid/package/contents/ui/task/TaskItem.qml +++ b/plasmoid/package/contents/ui/task/TaskItem.qml @@ -328,9 +328,15 @@ AbilityItem.BasicItem { onIsDraggedChanged: { if (isDragged){ - root.dragSource = taskItem; - dragHelper.startDrag(taskItem, model.MimeType, model.MimeData, - model.LauncherUrlWithoutIcon, model.decoration); + taskItem.contentItem.monochromizedItem.grabToImage((result) => { + root.dragSource = taskItem; + dragHelper.Drag.imageSource = result.url; + dragHelper.Drag.mimeData = dragHelper.generateMimeData(model.MimeType, model.MimeData, model.LauncherUrlWithoutIcon); + dragHelper.Drag.active = true; + }); + } else { + dragHelper.Drag.active = false; + dragHelper.Drag.imageSource = ""; pressX = -1; pressY = -1; } diff --git a/plasmoid/package/contents/ui/task/TaskMouseArea.qml b/plasmoid/package/contents/ui/task/TaskMouseArea.qml index 4965b9263..95db683ca 100644 --- a/plasmoid/package/contents/ui/task/TaskMouseArea.qml +++ b/plasmoid/package/contents/ui/task/TaskMouseArea.qml @@ -81,12 +81,15 @@ MouseArea { // mouse.button is always 0 here, hence checking with mouse.buttons if (pressX != -1 && mouse.buttons == Qt.LeftButton && isDragged - && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y) ) { - root.dragSource = taskItem; - dragHelper.startDrag(taskItem, model.MimeType, model.MimeData, - model.LauncherUrlWithoutIcon, model.decoration); - pressX = -1; - pressY = -1; + && (Math.abs(pressX - mouse.x) + Math.abs(pressY - mouse.y) >= Qt.styleHints.startDragDistance) ) { + taskItem.contentItem.monochromizedItem.grabToImage((result) => { + pressX = -1; + pressY = -1; + root.dragSource = taskItem; + dragHelper.Drag.imageSource = result.url; + dragHelper.Drag.mimeData = dragHelper.generateMimeData(model.MimeType, model.MimeData, model.LauncherUrlWithoutIcon); + dragHelper.Drag.active = true; + }); } } }