diff --git a/qml/IconItemDelegate.qml b/qml/IconItemDelegate.qml index 3c02c706..189335f9 100644 --- a/qml/IconItemDelegate.qml +++ b/qml/IconItemDelegate.qml @@ -118,7 +118,21 @@ Control { hoverEnabled: false drag.target: root.dndEnabled ? root : null drag.threshold: 1 + + // 记录是否是触摸长按导致的,防止在 onClicked 中重复处理 + property bool isTouchLongPressed: false + + TapHandler { + acceptedDevices: PointerDevice.TouchScreen + gesturePolicy: TapHandler.DragThreshold + onLongPressed: { + mouseArea.isTouchLongPressed = true + root.menuTriggered() + } + } + onPressed: function (mouse) { + isTouchLongPressed = false if (mouse.button === Qt.LeftButton && root.dndEnabled) { root.Drag.hotSpot = mapToItem(iconLoader, Qt.point(mouse.x, mouse.y)) iconLoader.grabToImage(function(result) { @@ -146,6 +160,11 @@ Control { } } onClicked: function(mouse) { + if (isTouchLongPressed) { + isTouchLongPressed = false + return + } + if (mouse.button === Qt.LeftButton) { if (model.itemType === ItemArrangementProxyModel.FolderItemType) { root.folderClicked() @@ -156,12 +175,6 @@ Control { root.menuTriggered() } } - // touchscreen long press. - onPressAndHold: function (mouse) { - if (mouse.button === Qt.NoButton) { - root.menuTriggered() - } - } } } diff --git a/qml/windowed/AppListView.qml b/qml/windowed/AppListView.qml index 866379c6..86dd48b9 100644 --- a/qml/windowed/AppListView.qml +++ b/qml/windowed/AppListView.qml @@ -225,7 +225,20 @@ FocusScope { // 当分类菜单打开时,禁用拖拽功能 enabled: !(ddeCategoryMenu.visible || alphabetCategoryPopup.visible) + // 记录是否是触摸长按导致的,防止在 onClicked 中重复处理 + property bool isTouchLongPressed: false + + TapHandler { + acceptedDevices: PointerDevice.TouchScreen + gesturePolicy: TapHandler.DragThreshold + onLongPressed: { + mouseArea.isTouchLongPressed = true + showContextMenu(itemDelegate, model) + } + } + onPressed: function (mouse) { + isTouchLongPressed = false if (mouse.button === Qt.LeftButton) { itemDelegate.contentItem.grabToImage(function(result) { itemDelegate.Drag.imageSource = result.url @@ -233,6 +246,11 @@ FocusScope { } } onClicked: function (mouse) { + if (isTouchLongPressed) { + isTouchLongPressed = false + return + } + if (mouse.button === Qt.RightButton) { showContextMenu(itemDelegate, model) baseLayer.focus = true @@ -240,12 +258,6 @@ FocusScope { launchApp(desktopId) } } - // touchscreen long press. - onPressAndHold: function (mouse) { - if (mouse.button === Qt.NoButton) { - showContextMenu(itemDelegate, model) - } - } } background: ItemBackground { implicitWidth: DStyle.Style.itemDelegate.width diff --git a/qml/windowed/FreeSortListView.qml b/qml/windowed/FreeSortListView.qml index 895736c2..26573d2e 100644 --- a/qml/windowed/FreeSortListView.qml +++ b/qml/windowed/FreeSortListView.qml @@ -332,7 +332,23 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton drag.target: itemDelegate + // 记录是否是触摸长按导致的,防止在 onClicked 中重复处理 + property bool isTouchLongPressed: false + + TapHandler { + acceptedDevices: PointerDevice.TouchScreen + gesturePolicy: TapHandler.DragThreshold + onLongPressed: { + mouseArea.isTouchLongPressed = true + showContextMenu(itemDelegate, model, { + hideMoveToTopMenu: index === 0 + }) + baseLayer.focus = true + } + } + onPressed: function (mouse) { + isTouchLongPressed = false if (mouse.button === Qt.LeftButton) { itemDelegate.contentItem.grabToImage(function(result) { itemDelegate.Drag.imageSource = result.url @@ -341,6 +357,11 @@ Item { } onClicked: function (mouse) { + if (isTouchLongPressed) { + isTouchLongPressed = false + return + } + if (mouse.button === Qt.RightButton) { showContextMenu(itemDelegate, model, { hideMoveToTopMenu: index === 0 @@ -350,16 +371,6 @@ Item { launchItem() } } - - // touchscreen long press. - onPressAndHold: function (mouse) { - if (mouse.button === Qt.NoButton) { - showContextMenu(itemDelegate, model, { - hideMoveToTopMenu: index === 0 - }) - baseLayer.focus = true - } - } } } diff --git a/qml/windowed/IconItemDelegate.qml b/qml/windowed/IconItemDelegate.qml index 628950f5..ef1ef0ff 100644 --- a/qml/windowed/IconItemDelegate.qml +++ b/qml/windowed/IconItemDelegate.qml @@ -52,7 +52,21 @@ Control { acceptedButtons: Qt.LeftButton enabled: true drag.target: root.dndEnabled ? root : null + + // 记录是否是触摸长按导致的,防止在 onClicked 中重复处理 + property bool isTouchLongPressed: false + + TapHandler { + acceptedDevices: PointerDevice.TouchScreen + gesturePolicy: TapHandler.DragThreshold + onLongPressed: { + mouseArea.isTouchLongPressed = true + root.menuTriggered() + } + } + onPressed: function (mouse) { + isTouchLongPressed = false if (mouse.button === Qt.LeftButton && root.dndEnabled) { appIcon.grabToImage(function(result) { root.Drag.imageSource = result.url; @@ -60,16 +74,15 @@ Control { } } onClicked: { + if (isTouchLongPressed) { + isTouchLongPressed = false + return + } + if (!drag.active) { root.itemClicked() } } - // touchscreen long press. - onPressAndHold: function (mouse) { - if (mouse.button === Qt.NoButton) { - root.menuTriggered() - } - } } contentItem: Column { anchors.fill: parent