This commit is contained in:
miruka 2020-05-20 23:40:41 -04:00
commit e128471628
7 changed files with 84 additions and 40 deletions

View File

@ -235,6 +235,7 @@ class UISettings(JSONDataFile):
"clearRoomFilterOnEscape": True,
"clearMemberFilterOnEscape": True,
"collapseSidePanesUnderWindowWidth": 400,
"enableKineticScrolling": True,
"hideProfileChangeEvents": True,
"hideMembershipEvents": False,
"hideUnknownEvents": True,

View File

@ -5,5 +5,7 @@ import QtQuick.Controls 2.12
Flickable {
interactive: contentWidth > width || contentHeight > height
ScrollBar.vertical: ScrollBar {}
ScrollBar.vertical: ScrollBar {
visible: parent.interactive
}
}

View File

@ -26,4 +26,9 @@ HPage {
height: flickable.height
}
}
HKineticScrollingDisabler {
flickable: flickable
anchors.fill: flickable
}
}

View File

@ -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,22 +117,8 @@ GridView {
}
Connections {
target: gridView
enabled: ! gridView.allowDragging
// interactive gets temporarily set to true below to allow wheel scroll
onDraggingChanged: gridView.interactive = false
}
MouseArea {
HKineticScrollingDisabler {
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
}
}
}

View 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
}
}

View File

@ -5,7 +5,6 @@ import QtQuick.Controls 2.12
ListView {
id: listView
interactive: allowDragging
currentIndex: -1
keyNavigationWraps: true
highlightMoveDuration: theme.animationDuration
@ -24,7 +23,7 @@ ListView {
}
ScrollBar.vertical: ScrollBar {
visible: listView.interactive || ! listView.allowDragging
visible: listView.interactive
}
// property bool debug: false
@ -60,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
@ -120,22 +118,8 @@ ListView {
}
Connections {
target: listView
enabled: ! listView.allowDragging
// interactive gets temporarily set to true below to allow wheel scroll
onDraggingChanged: listView.interactive = false
}
MouseArea {
HKineticScrollingDisabler {
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
}
}
}

View File

@ -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