Merge pull request #43 from vSLG/trackpad
Add option to disable kinetic scrolling
This commit is contained in:
commit
fc28ffd741
|
@ -235,6 +235,7 @@ class UISettings(JSONDataFile):
|
||||||
"clearRoomFilterOnEscape": True,
|
"clearRoomFilterOnEscape": True,
|
||||||
"clearMemberFilterOnEscape": True,
|
"clearMemberFilterOnEscape": True,
|
||||||
"collapseSidePanesUnderWindowWidth": 400,
|
"collapseSidePanesUnderWindowWidth": 400,
|
||||||
|
"enableKineticScrolling": True,
|
||||||
"hideProfileChangeEvents": True,
|
"hideProfileChangeEvents": True,
|
||||||
"hideMembershipEvents": False,
|
"hideMembershipEvents": False,
|
||||||
"hideUnknownEvents": False,
|
"hideUnknownEvents": False,
|
||||||
|
|
|
@ -5,5 +5,7 @@ import QtQuick.Controls 2.12
|
||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
interactive: contentWidth > width || contentHeight > height
|
interactive: contentWidth > width || contentHeight > height
|
||||||
ScrollBar.vertical: ScrollBar {}
|
ScrollBar.vertical: ScrollBar {
|
||||||
|
visible: parent.interactive
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,9 @@ HPage {
|
||||||
height: flickable.height
|
height: flickable.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HKineticScrollingDisabler {
|
||||||
|
flickable: flickable
|
||||||
|
anchors.fill: flickable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import QtQuick.Controls 2.12
|
||||||
|
|
||||||
GridView {
|
GridView {
|
||||||
id: gridView
|
id: gridView
|
||||||
interactive: allowDragging
|
|
||||||
currentIndex: -1
|
currentIndex: -1
|
||||||
keyNavigationWraps: true
|
keyNavigationWraps: true
|
||||||
highlightMoveDuration: theme.animationDuration
|
highlightMoveDuration: theme.animationDuration
|
||||||
|
@ -23,7 +22,7 @@ GridView {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollBar.vertical: ScrollBar {
|
ScrollBar.vertical: ScrollBar {
|
||||||
visible: gridView.interactive || ! gridView.allowDragging
|
visible: gridView.interactive
|
||||||
}
|
}
|
||||||
|
|
||||||
// property bool debug: false
|
// property bool debug: false
|
||||||
|
@ -59,7 +58,6 @@ GridView {
|
||||||
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
||||||
|
|
||||||
|
|
||||||
property bool allowDragging: true
|
|
||||||
property alias cursorShape: mouseArea.cursorShape
|
property alias cursorShape: mouseArea.cursorShape
|
||||||
property int currentItemHeight: currentItem ? currentItem.height : 0
|
property int currentItemHeight: currentItem ? currentItem.height : 0
|
||||||
|
|
||||||
|
@ -119,22 +117,8 @@ GridView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connections {
|
HKineticScrollingDisabler {
|
||||||
target: gridView
|
|
||||||
enabled: ! gridView.allowDragging
|
|
||||||
// interactive gets temporarily set to true below to allow wheel scroll
|
|
||||||
onDraggingChanged: gridView.interactive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
68
src/gui/Base/HKineticScrollingDisabler.qml
Normal file
68
src/gui/Base/HKineticScrollingDisabler.qml
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtQuick 2.12
|
||||||
|
|
||||||
|
// MouseArea component to disable kinetic scrolling
|
||||||
|
MouseArea {
|
||||||
|
id: mouseArea
|
||||||
|
enabled: ! window.settings.enableKineticScrolling
|
||||||
|
propagateComposedEvents: true
|
||||||
|
acceptedButtons: Qt.NoButton
|
||||||
|
|
||||||
|
|
||||||
|
onWheel: {
|
||||||
|
// Make components below the stack notice the wheel event
|
||||||
|
wheel.accepted = false
|
||||||
|
|
||||||
|
const pos = getNewPosition(flickable, wheel)
|
||||||
|
flickable.flick(0, 0)
|
||||||
|
flickable.contentY = pos
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
// Otherwise use wheel.angleDelta, which is available from mouses and
|
||||||
|
// low resolution trackpads.
|
||||||
|
// When higher pixelDelta, more scroll will be applied
|
||||||
|
const pixelDelta =
|
||||||
|
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)
|
||||||
|
return flickable.contentY
|
||||||
|
|
||||||
|
const maxScroll =
|
||||||
|
flickable.contentHeight +
|
||||||
|
flickable.originY +
|
||||||
|
flickable.bottomMargin -
|
||||||
|
flickable.height
|
||||||
|
const minScroll = flickable.topMargin + flickable.originY
|
||||||
|
|
||||||
|
// Avoid overscrolling
|
||||||
|
return Math.max(
|
||||||
|
minScroll,
|
||||||
|
Math.min(maxScroll, flickable.contentY - pixelDelta)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Binding {
|
||||||
|
target: flickable
|
||||||
|
property: "maximumFlickVelocity"
|
||||||
|
value: mouseArea.enabled ? 0 : 4000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
Binding {
|
||||||
|
target: flickable
|
||||||
|
property: "flickDeceleration"
|
||||||
|
value: mouseArea.enabled ? 0 : dummy.flickDeceleration
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import QtQuick.Controls 2.12
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listView
|
id: listView
|
||||||
interactive: allowDragging
|
|
||||||
currentIndex: -1
|
currentIndex: -1
|
||||||
keyNavigationWraps: true
|
keyNavigationWraps: true
|
||||||
highlightMoveDuration: theme.animationDuration
|
highlightMoveDuration: theme.animationDuration
|
||||||
|
@ -24,7 +23,7 @@ ListView {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollBar.vertical: ScrollBar {
|
ScrollBar.vertical: ScrollBar {
|
||||||
visible: listView.interactive || ! listView.allowDragging
|
visible: listView.interactive
|
||||||
}
|
}
|
||||||
|
|
||||||
// property bool debug: false
|
// property bool debug: false
|
||||||
|
@ -60,7 +59,6 @@ ListView {
|
||||||
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
||||||
|
|
||||||
|
|
||||||
property bool allowDragging: true
|
|
||||||
property alias cursorShape: mouseArea.cursorShape
|
property alias cursorShape: mouseArea.cursorShape
|
||||||
property int currentItemHeight: currentItem ? currentItem.height : 0
|
property int currentItemHeight: currentItem ? currentItem.height : 0
|
||||||
|
|
||||||
|
@ -120,22 +118,8 @@ ListView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connections {
|
HKineticScrollingDisabler {
|
||||||
target: listView
|
|
||||||
enabled: ! listView.allowDragging
|
|
||||||
// interactive gets temporarily set to true below to allow wheel scroll
|
|
||||||
onDraggingChanged: listView.interactive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ QtObject {
|
||||||
function flickPages(flickable, pages) {
|
function flickPages(flickable, pages) {
|
||||||
// Adapt velocity and deceleration for the number of pages to flick.
|
// Adapt velocity and deceleration for the number of pages to flick.
|
||||||
// If this is a repeated flicking, flick faster than a single 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 futureVelocity = -flickable.height * pages
|
||||||
const currentVelocity = -flickable.verticalVelocity
|
const currentVelocity = -flickable.verticalVelocity
|
||||||
|
@ -351,7 +351,7 @@ QtObject {
|
||||||
|
|
||||||
|
|
||||||
function flickToTop(flickable) {
|
function flickToTop(flickable) {
|
||||||
if (! flickable.interactive && flickable.allowDragging) return
|
if (! flickable.interactive) return
|
||||||
if (flickable.visibleArea.yPosition < 0) return
|
if (flickable.visibleArea.yPosition < 0) return
|
||||||
|
|
||||||
flickable.contentY -= flickable.contentHeight
|
flickable.contentY -= flickable.contentHeight
|
||||||
|
@ -361,7 +361,7 @@ QtObject {
|
||||||
|
|
||||||
|
|
||||||
function flickToBottom(flickable) {
|
function flickToBottom(flickable) {
|
||||||
if (! flickable.interactive && flickable.allowDragging) return
|
if (! flickable.interactive) return
|
||||||
if (flickable.visibleArea.yPosition < 0) return
|
if (flickable.visibleArea.yPosition < 0) return
|
||||||
|
|
||||||
flickable.contentY = flickable.contentHeight - flickable.height
|
flickable.contentY = flickable.contentHeight - flickable.height
|
||||||
|
|
Loading…
Reference in New Issue
Block a user