diff --git a/qml/FolderGridViewPopup.qml b/qml/FolderGridViewPopup.qml index 47976501..f9b8b2b1 100644 --- a/qml/FolderGridViewPopup.qml +++ b/qml/FolderGridViewPopup.qml @@ -647,7 +647,7 @@ Popup { isDragHover: false displayFont: isWindowedMode ? DTK.fontManager.t9 : DTK.fontManager.t6 Drag.mimeData: Helper.generateDragMimeData(model.desktopId) - visible: dndItem.currentlyDraggedId !== model.desktopId + opacity: dndItem.currentlyDraggedId !== model.desktopId ? 1 : 0 iconSource: iconName padding: isWindowedMode ? 0 : 5 diff --git a/qml/FullscreenFrame.qml b/qml/FullscreenFrame.qml index c8b8cfdb..432532b8 100644 --- a/qml/FullscreenFrame.qml +++ b/qml/FullscreenFrame.qml @@ -639,7 +639,7 @@ InputEventItem { dndEnabled: !folderGridViewPopup.opened isDragHover: parent.isDragHover Drag.mimeData: Helper.generateDragMimeData(model.desktopId) - visible: dndItem.currentlyDraggedId !== model.desktopId + opacity: dndItem.currentlyDraggedId !== model.desktopId ? 1 : 0 iconSource: (iconName && iconName !== "") ? iconName : "application-x-desktop" icons: folderIcons iconScaleFactor: baseLayer.iconScaleFactor diff --git a/qml/IconItemDelegate.qml b/qml/IconItemDelegate.qml index cb86e971..3c02c706 100644 --- a/qml/IconItemDelegate.qml +++ b/qml/IconItemDelegate.qml @@ -44,11 +44,11 @@ Control { states: State { name: "dragged"; - when: dragHandler.active + when: mouseArea.drag.active // FIXME: When dragging finished, the position of the item is changed for unknown reason, // so we use the state to reset the x and y here. PropertyChanges { - target: dragHandler.target + target: mouseArea.drag.target x: x y: y } @@ -111,34 +111,57 @@ Control { anchors.fill: parent asynchronous: true sourceComponent: root.icons !== undefined ? folderComponent : imageComponent - DragHandler { - id: dragHandler - target: root - acceptedButtons: Qt.LeftButton - enabled: root.dndEnabled - dragThreshold: 1 - onActiveChanged: { - if (active) { - // We switch to use the `dndItem` to handle Drag event since that one will always exists. - // If we use the current item, then if the item that provides the drag attached property - // get destoryed (e.g. switch page or folder close caused destory), dropping at that moment - // will cause a crash. - - // Item will be hidden by checking the dndItem.currentlyDraggedId property. We assign the value - // to that property here - dndItem.currentlyDraggedId = target.Drag.mimeData["text/x-dde-launcher-dnd-desktopId"] - dndItem.currentlyDraggedIconName = root.iconSource - dndItem.Drag.hotSpot = target.Drag.hotSpot - dndItem.Drag.mimeData = target.Drag.mimeData - dndItem.mergeSize = Math.min(iconLoader.width, iconLoader.height) + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: false + drag.target: root.dndEnabled ? root : null + drag.threshold: 1 + onPressed: function (mouse) { + if (mouse.button === Qt.LeftButton && root.dndEnabled) { + root.Drag.hotSpot = mapToItem(iconLoader, Qt.point(mouse.x, mouse.y)) iconLoader.grabToImage(function(result) { - dndItem.Drag.imageSource = result.url; + root.Drag.imageSource = result.url; + }) + } + } + drag.onActiveChanged: function() { + if (drag.active) { + dndItem.currentlyDraggedId = root.Drag.mimeData["text/x-dde-launcher-dnd-desktopId"] + dndItem.currentlyDraggedIconName = root.iconSource + dndItem.Drag.hotSpot = root.Drag.hotSpot + dndItem.Drag.mimeData = root.Drag.mimeData + dndItem.mergeSize = Math.min(iconLoader.width, iconLoader.height) + dndItem.Drag.imageSource = root.Drag.imageSource + dndItem.Drag.dragType = root.Drag.Automatic + // Defer the drag start to avoid running a nested event loop + // (QDrag::exec) inside this signal handler. If the delegate + // gets destroyed during the drag (page switch / folder close), + // Qt would otherwise abort because the MouseArea's handler is + // still on the call stack. + Qt.callLater(function() { dndItem.Drag.active = true - dndItem.Drag.startDrag() }) } } + onClicked: function(mouse) { + if (mouse.button === Qt.LeftButton) { + if (model.itemType === ItemArrangementProxyModel.FolderItemType) { + root.folderClicked() + } else { + root.itemClicked() + } + } else if (mouse.button === Qt.RightButton) { + root.menuTriggered() + } + } + // touchscreen long press. + onPressAndHold: function (mouse) { + if (mouse.button === Qt.NoButton) { + root.menuTriggered() + } + } } }