Skip to content

Commit 957e8a7

Browse files
wjyrichdeepin-bot[bot]
authored andcommitted
fix: replace touch long press handling with TapHandler for better
reliability Replaced the `onPressAndHold` event handler with a `TapHandler` component for touchscreen long press interactions across multiple QML files. This change prevents duplicate handling of touch events by introducing a flag `isTouchLongPressed` that blocks the subsequent `onClicked` execution. The old `onPressAndHold` approach was unreliable and caused duplicated menu triggers. Log: Improved touchscreen long press reliability by using TapHandler Influence: 1. Test touchscreen long press on icon items to trigger context menu 2. Verify that short tap still properly triggers the default action (e.g., launching app) 3. Ensure no duplicate menu popups occur during touch interaction 4. Test with mouse input to confirm no regression in right-click context menu 5. Verify drag-and-drop behavior remains unaffected on touch devices fix: 使用 TapHandler 替代触摸长按处理以提高可靠性 将多个 QML 文件中的 `onPressAndHold` 事件处理器替换为 `TapHandler` 组件 来处理触摸屏长按交互。此修改通过引入 `isTouchLongPressed` 标志位来阻止后 续的 `onClicked` 重复执行,解决了原有 `onPressAndHold` 方法不可靠导致的 菜单重复触发问题。 Log: 通过使用 TapHandler 提高触摸长按的可靠性 Influence: 1. 测试触摸屏长按图标项是否正常触发上下文菜单 2. 验证短触是否仍能正常触发默认操作(如启动应用) 3. 确保触摸交互期间不会出现重复的菜单弹窗 4. 测试鼠标输入,确认右键上下文菜单无回归问题 5. 验证触摸设备上的拖拽功能不受影响 PMS: BUG-358827
1 parent b0c62f2 commit 957e8a7

4 files changed

Lines changed: 77 additions & 28 deletions

File tree

qml/IconItemDelegate.qml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,21 @@ Control {
118118
hoverEnabled: false
119119
drag.target: root.dndEnabled ? root : null
120120
drag.threshold: 1
121+
122+
// 记录是否是触摸长按导致的,防止在 onClicked 中重复处理
123+
property bool isTouchLongPressed: false
124+
125+
TapHandler {
126+
acceptedDevices: PointerDevice.TouchScreen
127+
gesturePolicy: TapHandler.DragThreshold
128+
onLongPressed: {
129+
mouseArea.isTouchLongPressed = true
130+
root.menuTriggered()
131+
}
132+
}
133+
121134
onPressed: function (mouse) {
135+
isTouchLongPressed = false
122136
if (mouse.button === Qt.LeftButton && root.dndEnabled) {
123137
root.Drag.hotSpot = mapToItem(iconLoader, Qt.point(mouse.x, mouse.y))
124138
iconLoader.grabToImage(function(result) {
@@ -146,6 +160,11 @@ Control {
146160
}
147161
}
148162
onClicked: function(mouse) {
163+
if (isTouchLongPressed) {
164+
isTouchLongPressed = false
165+
return
166+
}
167+
149168
if (mouse.button === Qt.LeftButton) {
150169
if (model.itemType === ItemArrangementProxyModel.FolderItemType) {
151170
root.folderClicked()
@@ -156,12 +175,6 @@ Control {
156175
root.menuTriggered()
157176
}
158177
}
159-
// touchscreen long press.
160-
onPressAndHold: function (mouse) {
161-
if (mouse.button === Qt.NoButton) {
162-
root.menuTriggered()
163-
}
164-
}
165178
}
166179
}
167180

qml/windowed/AppListView.qml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,39 @@ FocusScope {
225225
// 当分类菜单打开时,禁用拖拽功能
226226
enabled: !(ddeCategoryMenu.visible || alphabetCategoryPopup.visible)
227227

228+
// 记录是否是触摸长按导致的,防止在 onClicked 中重复处理
229+
property bool isTouchLongPressed: false
230+
231+
TapHandler {
232+
acceptedDevices: PointerDevice.TouchScreen
233+
gesturePolicy: TapHandler.DragThreshold
234+
onLongPressed: {
235+
mouseArea.isTouchLongPressed = true
236+
showContextMenu(itemDelegate, model)
237+
}
238+
}
239+
228240
onPressed: function (mouse) {
241+
isTouchLongPressed = false
229242
if (mouse.button === Qt.LeftButton) {
230243
itemDelegate.contentItem.grabToImage(function(result) {
231244
itemDelegate.Drag.imageSource = result.url
232245
})
233246
}
234247
}
235248
onClicked: function (mouse) {
249+
if (isTouchLongPressed) {
250+
isTouchLongPressed = false
251+
return
252+
}
253+
236254
if (mouse.button === Qt.RightButton) {
237255
showContextMenu(itemDelegate, model)
238256
baseLayer.focus = true
239257
} else {
240258
launchApp(desktopId)
241259
}
242260
}
243-
// touchscreen long press.
244-
onPressAndHold: function (mouse) {
245-
if (mouse.button === Qt.NoButton) {
246-
showContextMenu(itemDelegate, model)
247-
}
248-
}
249261
}
250262
background: ItemBackground {
251263
implicitWidth: DStyle.Style.itemDelegate.width

qml/windowed/FreeSortListView.qml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,23 @@ Item {
332332
acceptedButtons: Qt.LeftButton | Qt.RightButton
333333
drag.target: itemDelegate
334334

335+
// 记录是否是触摸长按导致的,防止在 onClicked 中重复处理
336+
property bool isTouchLongPressed: false
337+
338+
TapHandler {
339+
acceptedDevices: PointerDevice.TouchScreen
340+
gesturePolicy: TapHandler.DragThreshold
341+
onLongPressed: {
342+
mouseArea.isTouchLongPressed = true
343+
showContextMenu(itemDelegate, model, {
344+
hideMoveToTopMenu: index === 0
345+
})
346+
baseLayer.focus = true
347+
}
348+
}
349+
335350
onPressed: function (mouse) {
351+
isTouchLongPressed = false
336352
if (mouse.button === Qt.LeftButton) {
337353
itemDelegate.contentItem.grabToImage(function(result) {
338354
itemDelegate.Drag.imageSource = result.url
@@ -341,6 +357,11 @@ Item {
341357
}
342358

343359
onClicked: function (mouse) {
360+
if (isTouchLongPressed) {
361+
isTouchLongPressed = false
362+
return
363+
}
364+
344365
if (mouse.button === Qt.RightButton) {
345366
showContextMenu(itemDelegate, model, {
346367
hideMoveToTopMenu: index === 0
@@ -350,16 +371,6 @@ Item {
350371
launchItem()
351372
}
352373
}
353-
354-
// touchscreen long press.
355-
onPressAndHold: function (mouse) {
356-
if (mouse.button === Qt.NoButton) {
357-
showContextMenu(itemDelegate, model, {
358-
hideMoveToTopMenu: index === 0
359-
})
360-
baseLayer.focus = true
361-
}
362-
}
363374
}
364375
}
365376

qml/windowed/IconItemDelegate.qml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,37 @@ Control {
5252
acceptedButtons: Qt.LeftButton
5353
enabled: true
5454
drag.target: root.dndEnabled ? root : null
55+
56+
// 记录是否是触摸长按导致的,防止在 onClicked 中重复处理
57+
property bool isTouchLongPressed: false
58+
59+
TapHandler {
60+
acceptedDevices: PointerDevice.TouchScreen
61+
gesturePolicy: TapHandler.DragThreshold
62+
onLongPressed: {
63+
mouseArea.isTouchLongPressed = true
64+
root.menuTriggered()
65+
}
66+
}
67+
5568
onPressed: function (mouse) {
69+
isTouchLongPressed = false
5670
if (mouse.button === Qt.LeftButton && root.dndEnabled) {
5771
appIcon.grabToImage(function(result) {
5872
root.Drag.imageSource = result.url;
5973
})
6074
}
6175
}
6276
onClicked: {
77+
if (isTouchLongPressed) {
78+
isTouchLongPressed = false
79+
return
80+
}
81+
6382
if (!drag.active) {
6483
root.itemClicked()
6584
}
6685
}
67-
// touchscreen long press.
68-
onPressAndHold: function (mouse) {
69-
if (mouse.button === Qt.NoButton) {
70-
root.menuTriggered()
71-
}
72-
}
7386
}
7487
contentItem: Column {
7588
anchors.fill: parent

0 commit comments

Comments
 (0)