2020-05-16 07:48:31 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
2020-05-21 12:03:36 +10:00
|
|
|
enabled: ! window.settings.enableKineticScrolling
|
2020-05-16 07:48:31 +10:00
|
|
|
propagateComposedEvents: true
|
2020-05-16 09:32:44 +10:00
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
onWheel: {
|
2020-05-19 00:53:26 +10:00
|
|
|
// Make components below the stack notice the wheel event
|
|
|
|
wheel.accepted = false
|
2020-05-16 07:48:31 +10:00
|
|
|
|
2020-05-16 09:32:44 +10:00
|
|
|
const pos = getNewPosition(flickable, wheel)
|
2020-05-16 07:48:31 +10:00
|
|
|
flickable.flick(0, 0)
|
|
|
|
flickable.contentY = pos
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:32:44 +10:00
|
|
|
|
|
|
|
property Flickable flickable: parent
|
|
|
|
|
2020-05-18 11:32:39 +10:00
|
|
|
// Used to get default flickDeceleration value
|
|
|
|
readonly property Flickable dummy: Flickable {}
|
|
|
|
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
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
|
2020-05-16 09:32:44 +10:00
|
|
|
const pixelDelta =
|
2020-05-21 12:03:36 +10:00
|
|
|
wheel.pixelDelta.y ||
|
|
|
|
wheel.angleDelta.y / 8 * Qt.styleHints.wheelScrollLines
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
// Return current position if there was not any movement
|
|
|
|
if (flickable.contentHeight < flickable.height || !pixelDelta)
|
|
|
|
return flickable.contentY
|
|
|
|
|
2020-05-16 09:32:44 +10:00
|
|
|
const maxScroll =
|
2020-05-16 07:48:31 +10:00
|
|
|
flickable.contentHeight +
|
|
|
|
flickable.originY +
|
2020-05-16 09:32:44 +10:00
|
|
|
flickable.bottomMargin -
|
|
|
|
flickable.height
|
|
|
|
const minScroll = flickable.topMargin + flickable.originY
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
// Avoid overscrolling
|
|
|
|
return Math.max(
|
|
|
|
minScroll,
|
|
|
|
Math.min(maxScroll, flickable.contentY - pixelDelta)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-19 00:53:26 +10:00
|
|
|
Binding {
|
|
|
|
target: flickable
|
|
|
|
property: "maximumFlickVelocity"
|
2020-06-27 22:56:50 +10:00
|
|
|
value: mouseArea.enabled ? 0 : window.settings.kineticScrollingMaxSpeed
|
2020-05-19 00:53:26 +10:00
|
|
|
}
|
|
|
|
|
2020-05-16 09:32:44 +10:00
|
|
|
Binding {
|
|
|
|
target: flickable
|
|
|
|
property: "flickDeceleration"
|
2020-05-21 12:03:36 +10:00
|
|
|
value: mouseArea.enabled ? 0 : dummy.flickDeceleration
|
2020-05-16 07:48:31 +10:00
|
|
|
}
|
|
|
|
}
|