66 lines
1.8 KiB
QML
66 lines
1.8 KiB
QML
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
import QtQuick 2.12
|
|
|
|
MouseArea {
|
|
id: mouseArea
|
|
|
|
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
|
|
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)
|
|
)
|
|
}
|
|
|
|
|
|
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
|
|
}
|
|
|
|
Binding {
|
|
target: flickable
|
|
property: "maximumFlickVelocity"
|
|
value: mouseArea.enabled ? 0 : window.settings.kineticScrollingMaxSpeed
|
|
}
|
|
|
|
Binding {
|
|
target: flickable
|
|
property: "flickDeceleration"
|
|
value:
|
|
mouseArea.enabled ?
|
|
0 :
|
|
window.settings.kineticScrollingDeceleration
|
|
}
|
|
}
|