From d840080fdb6cc952fad13144058dc64c6da1b72f Mon Sep 17 00:00:00 2001 From: vslg Date: Fri, 15 May 2020 18:48:31 -0300 Subject: [PATCH 1/7] Add custom scroll handler to MouseArea --- src/gui/Base/HListView.qml | 11 ++---- src/gui/Base/HScrollMouseArea.qml | 65 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/gui/Base/HScrollMouseArea.qml diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 4e938c6e..3725372c 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -5,7 +5,8 @@ import QtQuick.Controls 2.12 ListView { id: listView - interactive: allowDragging + //interactive: allowDragging + interactive: false currentIndex: -1 keyNavigationWraps: true highlightMoveDuration: theme.animationDuration @@ -127,15 +128,11 @@ ListView { onDraggingChanged: listView.interactive = false } - MouseArea { + HScrollMouseArea { id: mouseArea anchors.fill: parent enabled: ! parent.allowDragging || cursorShape !== Qt.ArrowCursor acceptedButtons: Qt.NoButton - onWheel: { - // Allow wheel usage, will be back to false on any drag attempt - parent.interactive = true - wheel.accepted = false - } + flickable: listView } } diff --git a/src/gui/Base/HScrollMouseArea.qml b/src/gui/Base/HScrollMouseArea.qml new file mode 100644 index 00000000..22f235ec --- /dev/null +++ b/src/gui/Base/HScrollMouseArea.qml @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +// Mouse area model to fix scroll on trackpad +MouseArea { + id: mouseArea + propagateComposedEvents: true + z: flickable.z + 1 + + onWheel: { + wheel.accepted = false // Disable wheel to avoid too much scroll + + var pos = getNewPosition(flickable, wheel) + flickable.flick(0, 0) + flickable.contentY = pos + cancelFlickTimer.start() // Stop the flick + } + + // Required assignment for flickable scroll to work. + // It must be specified when using this class. + property Flickable flickable + + function getNewPosition(flickable, wheel) { + // wheel.pixelDelta will be available on high resolution trackpads. + // Otherwise use wheel.angleDelta, which is available from mouses and + // low resolution trackpads. + // When higher pixelDelta, more scroll will be applied + var pixelDelta = wheel.pixelDelta.y || (wheel.angleDelta.y / 8) + + // Return current position if there was not any movement + if (flickable.contentHeight < flickable.height || !pixelDelta) + return flickable.contentY + + var maxScroll = ( + flickable.contentHeight + + flickable.originY + + flickable.bottomMargin + ) - flickable.height + var minScroll = flickable.topMargin + flickable.originY + + // Avoid overscrolling + return Math.max( + minScroll, + Math.min(maxScroll, flickable.contentY - pixelDelta) + ) + } + + Timer { + id: cancelFlickTimer + interval: 100 // Flick duration in ms + onTriggered: { + flickable.cancelFlick() + // print("aaa") + } + } + + Rectangle { + anchors.fill: parent + color: "transparent" + border.color: "red" + border.width: 5 + } +} From b179480327bced1f5c5fd022a4768fa865b27686 Mon Sep 17 00:00:00 2001 From: vslg Date: Fri, 15 May 2020 20:23:20 -0300 Subject: [PATCH 2/7] Remove allowDragging, as it is not needed anymore --- src/gui/Base/HGridView.qml | 12 +----------- src/gui/Base/HListView.qml | 13 +------------ src/gui/Utils.qml | 6 +++--- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/gui/Base/HGridView.qml b/src/gui/Base/HGridView.qml index 2bb2f5ad..4c97e66d 100644 --- a/src/gui/Base/HGridView.qml +++ b/src/gui/Base/HGridView.qml @@ -5,7 +5,6 @@ import QtQuick.Controls 2.12 GridView { id: gridView - interactive: allowDragging currentIndex: -1 keyNavigationWraps: true highlightMoveDuration: theme.animationDuration @@ -23,7 +22,7 @@ GridView { } ScrollBar.vertical: ScrollBar { - visible: gridView.interactive || ! gridView.allowDragging + visible: gridView.interactive } // property bool debug: false @@ -59,7 +58,6 @@ GridView { onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0 - property bool allowDragging: true property alias cursorShape: mouseArea.cursorShape property int currentItemHeight: currentItem ? currentItem.height : 0 @@ -119,17 +117,9 @@ GridView { } - Connections { - target: gridView - enabled: ! gridView.allowDragging - // interactive gets temporarily set to true below to allow wheel scroll - onDraggingChanged: gridView.interactive = false - } - MouseArea { id: mouseArea anchors.fill: parent - enabled: ! parent.allowDragging || cursorShape !== Qt.ArrowCursor acceptedButtons: Qt.NoButton onWheel: { // Allow wheel usage, will be back to false on any drag attempt diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 3725372c..6687b15a 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -5,8 +5,6 @@ import QtQuick.Controls 2.12 ListView { id: listView - //interactive: allowDragging - interactive: false currentIndex: -1 keyNavigationWraps: true highlightMoveDuration: theme.animationDuration @@ -25,7 +23,7 @@ ListView { } ScrollBar.vertical: ScrollBar { - visible: listView.interactive || ! listView.allowDragging + visible: listView.interactive } // property bool debug: false @@ -61,7 +59,6 @@ ListView { onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0 - property bool allowDragging: true property alias cursorShape: mouseArea.cursorShape property int currentItemHeight: currentItem ? currentItem.height : 0 @@ -121,17 +118,9 @@ ListView { } - Connections { - target: listView - enabled: ! listView.allowDragging - // interactive gets temporarily set to true below to allow wheel scroll - onDraggingChanged: listView.interactive = false - } - HScrollMouseArea { id: mouseArea anchors.fill: parent - enabled: ! parent.allowDragging || cursorShape !== Qt.ArrowCursor acceptedButtons: Qt.NoButton flickable: listView } diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 3add6868..ad7b550d 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -325,7 +325,7 @@ QtObject { function flickPages(flickable, pages) { // Adapt velocity and deceleration for the number of pages to flick. // If this is a repeated flicking, flick faster than a single flick. - if (! flickable.interactive && flickable.allowDragging) return + if (! flickable.interactive) return const futureVelocity = -flickable.height * pages const currentVelocity = -flickable.verticalVelocity @@ -351,7 +351,7 @@ QtObject { function flickToTop(flickable) { - if (! flickable.interactive && flickable.allowDragging) return + if (! flickable.interactive) return if (flickable.visibleArea.yPosition < 0) return flickable.contentY -= flickable.contentHeight @@ -361,7 +361,7 @@ QtObject { function flickToBottom(flickable) { - if (! flickable.interactive && flickable.allowDragging) return + if (! flickable.interactive) return if (flickable.visibleArea.yPosition < 0) return flickable.contentY = flickable.contentHeight - flickable.height From f72544e3d05b4788edfa108b268bce6c4d95d574 Mon Sep 17 00:00:00 2001 From: vslg Date: Fri, 15 May 2020 20:32:44 -0300 Subject: [PATCH 3/7] Improve trackpad fix - Add it to remaining components - Do not use Timer, as flickDeceleration from Flickable is more performant - Add a setting option for it: useTrackpadFix --- src/backend/user_files.py | 1 + src/gui/Base/HFlickable.qml | 12 ++++- src/gui/Base/HGridView.qml | 8 +--- src/gui/Base/HListView.qml | 4 +- ...{HScrollMouseArea.qml => HTrackpadFix.qml} | 44 ++++++++----------- 5 files changed, 33 insertions(+), 36 deletions(-) rename src/gui/Base/{HScrollMouseArea.qml => HTrackpadFix.qml} (55%) diff --git a/src/backend/user_files.py b/src/backend/user_files.py index 68f23fbf..5769a96e 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -241,6 +241,7 @@ class UISettings(JSONDataFile): "maxMessageCharactersPerLine": 65, "ownMessagesOnLeftAboveWidth": 895, "theme": "Midnight.qpl", + "useTrackpadFix": False, "writeAliases": {}, "media": { "autoLoad": True, diff --git a/src/gui/Base/HFlickable.qml b/src/gui/Base/HFlickable.qml index 92d024d7..7f1b5576 100644 --- a/src/gui/Base/HFlickable.qml +++ b/src/gui/Base/HFlickable.qml @@ -4,6 +4,16 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 Flickable { + id: flickable interactive: contentWidth > width || contentHeight > height - ScrollBar.vertical: ScrollBar {} + ScrollBar.vertical: ScrollBar { + visible: flickable.interactive + } + + + readonly property HTrackpadFix trackpadFix: HTrackpadFix { + flickable: flickable + width: flickable.width + height: flickable.height + } } diff --git a/src/gui/Base/HGridView.qml b/src/gui/Base/HGridView.qml index 4c97e66d..f59f88d3 100644 --- a/src/gui/Base/HGridView.qml +++ b/src/gui/Base/HGridView.qml @@ -117,14 +117,8 @@ GridView { } - MouseArea { + HTrackpadFix { id: mouseArea anchors.fill: parent - acceptedButtons: Qt.NoButton - onWheel: { - // Allow wheel usage, will be back to false on any drag attempt - parent.interactive = true - wheel.accepted = false - } } } diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 6687b15a..a5c65ee3 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -118,10 +118,8 @@ ListView { } - HScrollMouseArea { + HTrackpadFix { id: mouseArea anchors.fill: parent - acceptedButtons: Qt.NoButton - flickable: listView } } diff --git a/src/gui/Base/HScrollMouseArea.qml b/src/gui/Base/HTrackpadFix.qml similarity index 55% rename from src/gui/Base/HScrollMouseArea.qml rename to src/gui/Base/HTrackpadFix.qml index 22f235ec..6db63bc3 100644 --- a/src/gui/Base/HScrollMouseArea.qml +++ b/src/gui/Base/HTrackpadFix.qml @@ -1,44 +1,46 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 -import QtQuick.Controls 2.12 // Mouse area model to fix scroll on trackpad MouseArea { id: mouseArea + enabled: window.settings.useTrackpadFix propagateComposedEvents: true - z: flickable.z + 1 + acceptedButtons: Qt.NoButton + onWheel: { wheel.accepted = false // Disable wheel to avoid too much scroll - var pos = getNewPosition(flickable, wheel) + const pos = getNewPosition(flickable, wheel) flickable.flick(0, 0) flickable.contentY = pos - cancelFlickTimer.start() // Stop the flick } - // Required assignment for flickable scroll to work. - // It must be specified when using this class. - property Flickable flickable + + property Flickable flickable: parent + function getNewPosition(flickable, wheel) { // wheel.pixelDelta will be available on high resolution trackpads. // Otherwise use wheel.angleDelta, which is available from mouses and // low resolution trackpads. // When higher pixelDelta, more scroll will be applied - var pixelDelta = wheel.pixelDelta.y || (wheel.angleDelta.y / 8) + const pixelDelta = + wheel.pixelDelta.y || + wheel.angleDelta.y / 24 * Qt.styleHints.wheelScrollLines // Return current position if there was not any movement if (flickable.contentHeight < flickable.height || !pixelDelta) return flickable.contentY - var maxScroll = ( + const maxScroll = flickable.contentHeight + flickable.originY + - flickable.bottomMargin - ) - flickable.height - var minScroll = flickable.topMargin + flickable.originY + flickable.bottomMargin - + flickable.height + const minScroll = flickable.topMargin + flickable.originY // Avoid overscrolling return Math.max( @@ -47,19 +49,11 @@ MouseArea { ) } - Timer { - id: cancelFlickTimer - interval: 100 // Flick duration in ms - onTriggered: { - flickable.cancelFlick() - // print("aaa") - } - } - Rectangle { - anchors.fill: parent - color: "transparent" - border.color: "red" - border.width: 5 + Binding { + target: flickable + property: "flickDeceleration" + value: 8000 + when: mouseArea.enabled } } From 107f92800731f3bd1d8efeca98f6ba2c764ac457 Mon Sep 17 00:00:00 2001 From: vslg Date: Sun, 17 May 2020 22:32:39 -0300 Subject: [PATCH 4/7] Fix bug when setting useTrackpadFix option --- src/gui/Base/HTrackpadFix.qml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/Base/HTrackpadFix.qml b/src/gui/Base/HTrackpadFix.qml index 6db63bc3..d5537869 100644 --- a/src/gui/Base/HTrackpadFix.qml +++ b/src/gui/Base/HTrackpadFix.qml @@ -2,7 +2,7 @@ import QtQuick 2.12 -// Mouse area model to fix scroll on trackpad +// MouseArea component to fix scroll on trackpad MouseArea { id: mouseArea enabled: window.settings.useTrackpadFix @@ -21,6 +21,9 @@ MouseArea { property Flickable flickable: parent + // Used to get default flickDeceleration value + readonly property Flickable dummy: Flickable {} + function getNewPosition(flickable, wheel) { // wheel.pixelDelta will be available on high resolution trackpads. @@ -53,7 +56,6 @@ MouseArea { Binding { target: flickable property: "flickDeceleration" - value: 8000 - when: mouseArea.enabled + value: mouseArea.enabled ? 8000.0 : dummy.flickDeceleration } } From 3094e47a99ec77a7cddaea1f626348f25f8f6ce6 Mon Sep 17 00:00:00 2001 From: vslg Date: Mon, 18 May 2020 11:53:26 -0300 Subject: [PATCH 5/7] Fix bugs and improve trackpad scroll precision Improve trackpad precision by making the amount of scroll, flickVelocity and flickDeceleration proportional --- src/gui/Base/HFlickable.qml | 10 +--------- src/gui/Base/HFlickableColumnPage.qml | 5 +++++ src/gui/Base/HTrackpadFix.qml | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/gui/Base/HFlickable.qml b/src/gui/Base/HFlickable.qml index 7f1b5576..83c07352 100644 --- a/src/gui/Base/HFlickable.qml +++ b/src/gui/Base/HFlickable.qml @@ -4,16 +4,8 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 Flickable { - id: flickable interactive: contentWidth > width || contentHeight > height ScrollBar.vertical: ScrollBar { - visible: flickable.interactive - } - - - readonly property HTrackpadFix trackpadFix: HTrackpadFix { - flickable: flickable - width: flickable.width - height: flickable.height + visible: parent.interactive } } diff --git a/src/gui/Base/HFlickableColumnPage.qml b/src/gui/Base/HFlickableColumnPage.qml index 8ce563ff..093153ca 100644 --- a/src/gui/Base/HFlickableColumnPage.qml +++ b/src/gui/Base/HFlickableColumnPage.qml @@ -26,4 +26,9 @@ HPage { height: flickable.height } } + + HTrackpadFix { + flickable: flickable + anchors.fill: flickable + } } diff --git a/src/gui/Base/HTrackpadFix.qml b/src/gui/Base/HTrackpadFix.qml index d5537869..308a4cef 100644 --- a/src/gui/Base/HTrackpadFix.qml +++ b/src/gui/Base/HTrackpadFix.qml @@ -11,7 +11,8 @@ MouseArea { onWheel: { - wheel.accepted = false // Disable wheel to avoid too much scroll + // Make components below the stack notice the wheel event + wheel.accepted = false const pos = getNewPosition(flickable, wheel) flickable.flick(0, 0) @@ -20,6 +21,7 @@ MouseArea { property Flickable flickable: parent + property int scrollFactor: 5 // Used to get default flickDeceleration value readonly property Flickable dummy: Flickable {} @@ -32,7 +34,10 @@ MouseArea { // When higher pixelDelta, more scroll will be applied const pixelDelta = wheel.pixelDelta.y || - wheel.angleDelta.y / 24 * Qt.styleHints.wheelScrollLines + wheel.angleDelta.y / + 24 * + Qt.styleHints.wheelScrollLines * + scrollFactor // Return current position if there was not any movement if (flickable.contentHeight < flickable.height || !pixelDelta) @@ -53,9 +58,15 @@ MouseArea { } + Binding { + target: flickable + property: "maximumFlickVelocity" + value: mouseArea.enabled ? scrollFactor : 4000.0 + } + Binding { target: flickable property: "flickDeceleration" - value: mouseArea.enabled ? 8000.0 : dummy.flickDeceleration + value: mouseArea.enabled ? scrollFactor * 3 : dummy.flickDeceleration } } From 1bad1e1106e604633c9effcd9b5f288e10715b11 Mon Sep 17 00:00:00 2001 From: vslg Date: Mon, 18 May 2020 12:43:06 -0300 Subject: [PATCH 6/7] Multiply scrollFactor to wheel.pixelDelta --- src/gui/Base/HTrackpadFix.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/Base/HTrackpadFix.qml b/src/gui/Base/HTrackpadFix.qml index 308a4cef..507e7155 100644 --- a/src/gui/Base/HTrackpadFix.qml +++ b/src/gui/Base/HTrackpadFix.qml @@ -33,7 +33,7 @@ MouseArea { // low resolution trackpads. // When higher pixelDelta, more scroll will be applied const pixelDelta = - wheel.pixelDelta.y || + wheel.pixelDelta.y * scrollFactor || wheel.angleDelta.y / 24 * Qt.styleHints.wheelScrollLines * From 6f68f35810d0327cd087b4748eecea655fd7bbf8 Mon Sep 17 00:00:00 2001 From: vslg Date: Wed, 20 May 2020 23:03:36 -0300 Subject: [PATCH 7/7] Fix goal is disabling kinetic scrolling --- src/backend/user_files.py | 2 +- src/gui/Base/HFlickableColumnPage.qml | 2 +- src/gui/Base/HGridView.qml | 2 +- ...kpadFix.qml => HKineticScrollingDisabler.qml} | 16 ++++++---------- src/gui/Base/HListView.qml | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) rename src/gui/Base/{HTrackpadFix.qml => HKineticScrollingDisabler.qml} (78%) diff --git a/src/backend/user_files.py b/src/backend/user_files.py index 5769a96e..20425f32 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -235,13 +235,13 @@ class UISettings(JSONDataFile): "clearRoomFilterOnEscape": True, "clearMemberFilterOnEscape": True, "collapseSidePanesUnderWindowWidth": 400, + "enableKineticScrolling": True, "hideProfileChangeEvents": True, "hideMembershipEvents": False, "hideUnknownEvents": False, "maxMessageCharactersPerLine": 65, "ownMessagesOnLeftAboveWidth": 895, "theme": "Midnight.qpl", - "useTrackpadFix": False, "writeAliases": {}, "media": { "autoLoad": True, diff --git a/src/gui/Base/HFlickableColumnPage.qml b/src/gui/Base/HFlickableColumnPage.qml index 093153ca..027281d7 100644 --- a/src/gui/Base/HFlickableColumnPage.qml +++ b/src/gui/Base/HFlickableColumnPage.qml @@ -27,7 +27,7 @@ HPage { } } - HTrackpadFix { + HKineticScrollingDisabler { flickable: flickable anchors.fill: flickable } diff --git a/src/gui/Base/HGridView.qml b/src/gui/Base/HGridView.qml index f59f88d3..79bdc3d0 100644 --- a/src/gui/Base/HGridView.qml +++ b/src/gui/Base/HGridView.qml @@ -117,7 +117,7 @@ GridView { } - HTrackpadFix { + HKineticScrollingDisabler { id: mouseArea anchors.fill: parent } diff --git a/src/gui/Base/HTrackpadFix.qml b/src/gui/Base/HKineticScrollingDisabler.qml similarity index 78% rename from src/gui/Base/HTrackpadFix.qml rename to src/gui/Base/HKineticScrollingDisabler.qml index 507e7155..b0a49ea0 100644 --- a/src/gui/Base/HTrackpadFix.qml +++ b/src/gui/Base/HKineticScrollingDisabler.qml @@ -2,10 +2,10 @@ import QtQuick 2.12 -// MouseArea component to fix scroll on trackpad +// MouseArea component to disable kinetic scrolling MouseArea { id: mouseArea - enabled: window.settings.useTrackpadFix + enabled: ! window.settings.enableKineticScrolling propagateComposedEvents: true acceptedButtons: Qt.NoButton @@ -21,7 +21,6 @@ MouseArea { property Flickable flickable: parent - property int scrollFactor: 5 // Used to get default flickDeceleration value readonly property Flickable dummy: Flickable {} @@ -33,11 +32,8 @@ MouseArea { // low resolution trackpads. // When higher pixelDelta, more scroll will be applied const pixelDelta = - wheel.pixelDelta.y * scrollFactor || - wheel.angleDelta.y / - 24 * - Qt.styleHints.wheelScrollLines * - scrollFactor + wheel.pixelDelta.y || + wheel.angleDelta.y / 8 * Qt.styleHints.wheelScrollLines // Return current position if there was not any movement if (flickable.contentHeight < flickable.height || !pixelDelta) @@ -61,12 +57,12 @@ MouseArea { Binding { target: flickable property: "maximumFlickVelocity" - value: mouseArea.enabled ? scrollFactor : 4000.0 + value: mouseArea.enabled ? 0 : 4000.0 } Binding { target: flickable property: "flickDeceleration" - value: mouseArea.enabled ? scrollFactor * 3 : dummy.flickDeceleration + value: mouseArea.enabled ? 0 : dummy.flickDeceleration } } diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index a5c65ee3..82391d64 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -118,7 +118,7 @@ ListView { } - HTrackpadFix { + HKineticScrollingDisabler { id: mouseArea anchors.fill: parent }