Commit a6e732f3 authored by Noah Davis's avatar Noah Davis 🌵
Browse files

kickoff: Replace Kicker DragHelper with Qt Quick Drag

Originally, I thought it wasn't possible to use Qt Quick Drag here, but
then I found out I could use Item::grabToImage()'s function callback
parameter to set Drag.imageSource.

BUG: 443708


(cherry picked from commit d754291b)
parent 796eb9e0
......@@ -179,6 +179,11 @@ T.ItemDelegate {
maximumLineCount: 1
}
Drag.active: mouseArea.drag.active
Drag.dragType: Drag.Automatic
Drag.mimeData: { "text/uri-list" : root.url }
Drag.onDragFinished: Drag.imageSource = ""
MouseArea {
id: mouseArea
parent: root
......@@ -201,16 +206,6 @@ T.ItemDelegate {
minimumY: 0
maximumY: root.view ? Math.min(root.view.contentHeight - root.height, root.view.availableHeight - root.height) : root.y
}
Binding {
target: KickoffSingleton; when: root.dragActive
property: "dragSource"; value: root
restoreMode: Binding.RestoreBindingOrValue
}
Binding {
target: KickoffSingleton.dragHelper; when: root.dragActive
property: "dragIconSize"; value: root.icon.height
restoreMode: Binding.RestoreBindingOrValue
}
// Using onPositionChanged instead of onEntered to prevent changing
// categories while scrolling with the mouse wheel.
onPositionChanged: {
......@@ -223,6 +218,11 @@ T.ItemDelegate {
// built into QQuickListView::setCurrentIndex() already
root.view.currentIndex = index
}
onPressed: if (root.dragEnabled && root.Drag.imageSource == "") {
iconItem.grabToImage((result) => {
return root.Drag.imageSource = result.url
})
}
onClicked: if (mouse.button === Qt.LeftButton) {
root.forceActiveFocus(Qt.MouseFocusReason)
root.action.trigger() // clicked() is emmitted when action is triggered
......@@ -277,15 +277,9 @@ T.ItemDelegate {
indicator = null
}
}
// NOTE: Not using Drag attached properties because we're using DragHelper instead.
// Drag doesn't support QIcons for the imageSource, only URLs.
onDragActiveChanged: if (dragActive) {
dragStartPosition = Qt.point(x,y)
dragStartIndex = index
// Fixes warning: "Passing incompatible arguments to C++ functions from JavaScript is dangerous and deprecated."
//const url = root.url ? root.url : ""
KickoffSingleton.dragHelper.startDrag(root, url, decoration)
} else if (dragStartIndex === index) {
x = dragStartPosition.x
y = dragStartPosition.y
......
......@@ -45,17 +45,6 @@ Item {
}
//END
//BEGIN Drag and Drop elements
property Item dragSource: null
// We have to use DragHelper here because the models use QIcons for the decoration role.
// DragHelper supports QIcons and Drag.imageSource only supports urls.
readonly property Kicker.DragHelper dragHelper: Kicker.DragHelper {
id: dragHelper
dragIconSize: PlasmaCore.Units.iconSizes.medium
onDropped: dragSource = null
}
//END
//BEGIN UI elements
// Set in FullRepresentation.qml
property Item header: null
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment