From a60d3e0df7085d077aaed93d9243cf3d57b59464 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 12 Jan 2017 15:57:20 +0100 Subject: TreeView: allow selecting items by touch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only single items can be selected via an actual touchscreen, because the keyboard modifiers are not accessible in a mouse event synthesized from touch. With a mouse, if the system has a touchscreen, then selections done by consecutive clicking (with or without modifiers) will work, whereas dragging across a consecutive range will not work because dragging is the same as flicking. But on systems which do not have a touchscreen at all, the behavior is the same as before. Task-number: QTBUG-47243 Change-Id: Ib0fa1a75592b982fe93da46f0c2e3018219947d0 Reviewed-by: Gabriel de Dietrich Reviewed-by: Jan Arve Sæther Reviewed-by: Shawn Rutledge --- src/controls/TreeView.qml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/controls/TreeView.qml b/src/controls/TreeView.qml index aa21acc1..6a38acff 100644 --- a/src/controls/TreeView.qml +++ b/src/controls/TreeView.qml @@ -118,8 +118,8 @@ BasicTableView { z: -1 propagateComposedEvents: true focus: true - // Note: with boolean preventStealing we are keeping - // the flickable from eating our mouse press events + // If there is not a touchscreen, keep the flickable from eating our mouse drags. + // If there is a touchscreen, flicking is possible, but selection can be done only by tapping, not by dragging. preventStealing: !Settings.hasTouchScreen property var clickedIndex: undefined @@ -323,8 +323,22 @@ BasicTableView { modelAdaptor.collapse(modelIndex) else modelAdaptor.expand(modelIndex) - } else if (root.__activateItemOnSingleClick) { - root.activated(modelIndex) + } else { + if (Settings.hasTouchScreen) { + // compensate for the fact that onPressed didn't select on press: do it here instead + pressedIndex = modelAdaptor.mapRowToModelIndex(clickIndex) + pressedColumn = __listView.columnAt(mouseX) + selectOnRelease = false + __listView.forceActiveFocus() + __listView.currentIndex = clickIndex + if (!clickedIndex) + clickedIndex = pressedIndex + mouseSelect(pressedIndex, mouse.modifiers, false) + if (!mouse.modifiers) + clickedIndex = pressedIndex + } + if (root.__activateItemOnSingleClick && !mouse.modifiers) + root.activated(modelIndex) } root.clicked(modelIndex) } -- cgit v1.2.1