2020-09-24 09:57:54 +10:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
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-16 09:32:44 +10:00
|
|
|
|
|
|
|
property Flickable flickable: parent
|
|
|
|
|
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-09-24 13:22:28 +10:00
|
|
|
|
|
|
|
const speedMultiply =
|
|
|
|
Qt.styleHints.wheelScrollLines *
|
|
|
|
window.settings.nonKineticScrollingSpeed
|
|
|
|
|
2020-07-23 03:57:32 +10:00
|
|
|
const pixelDelta = {
|
2020-09-24 13:22:28 +10:00
|
|
|
x: wheel.pixelDelta.x || wheel.angleDelta.x / 8 * speedMultiply,
|
|
|
|
y: wheel.pixelDelta.y || wheel.angleDelta.y / 8 * speedMultiply,
|
2020-07-23 03:57:32 +10:00
|
|
|
}
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
// Return current position if there was not any movement
|
2020-07-23 03:57:32 +10:00
|
|
|
if (
|
|
|
|
flickable.contentHeight < flickable.height ||
|
|
|
|
(! pixelDelta.x && ! pixelDelta.y)
|
|
|
|
)
|
|
|
|
return {x: flickable.contentX, y: flickable.contentY}
|
|
|
|
|
|
|
|
// Rotate the direction if shift is pressed
|
|
|
|
if (wheel.modifiers === Qt.ShiftModifier)
|
|
|
|
[pixelDelta.x, pixelDelta.y] = [pixelDelta.y, pixelDelta.x]
|
|
|
|
|
|
|
|
const maxScroll = {
|
|
|
|
x: flickable.contentWidth +
|
|
|
|
flickable.originX - // Why subtract?
|
|
|
|
flickable.rightMargin -
|
|
|
|
flickable.width,
|
|
|
|
y: flickable.contentHeight +
|
|
|
|
flickable.originY +
|
|
|
|
flickable.bottomMargin -
|
|
|
|
flickable.height,
|
|
|
|
}
|
2020-05-16 07:48:31 +10:00
|
|
|
|
2020-07-23 03:57:32 +10:00
|
|
|
const minScroll = {
|
|
|
|
x: flickable.originX - flickable.leftMargin,
|
|
|
|
y: flickable.originY - flickable.topMargin,
|
|
|
|
}
|
2020-05-16 07:48:31 +10:00
|
|
|
|
|
|
|
// Avoid overscrolling
|
2020-07-23 03:57:32 +10:00
|
|
|
return {
|
|
|
|
x: Math.max(
|
|
|
|
minScroll.x,
|
|
|
|
Math.min(maxScroll.x, flickable.contentX - pixelDelta.x)
|
|
|
|
),
|
|
|
|
y: Math.max(
|
|
|
|
minScroll.y,
|
|
|
|
Math.min(maxScroll.y, flickable.contentY - pixelDelta.y)
|
|
|
|
),
|
|
|
|
}
|
2020-05-16 07:48:31 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
enabled: ! window.settings.enableKineticScrolling
|
|
|
|
propagateComposedEvents: true
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
|
|
|
|
onWheel: {
|
|
|
|
// Make components below the stack notice the wheel event
|
|
|
|
wheel.accepted = false
|
|
|
|
|
2020-07-23 03:57:32 +10:00
|
|
|
if (wheel.modifiers === Qt.ControlModifier)
|
|
|
|
return
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
const pos = getNewPosition(flickable, wheel)
|
|
|
|
flickable.flick(0, 0)
|
2020-07-23 03:57:32 +10:00
|
|
|
flickable.contentX = pos.x
|
|
|
|
flickable.contentY = pos.y
|
2020-07-12 14:25:57 +10:00
|
|
|
}
|
|
|
|
|
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-07-14 19:46:48 +10:00
|
|
|
value:
|
|
|
|
mouseArea.enabled ?
|
|
|
|
0 :
|
|
|
|
window.settings.kineticScrollingDeceleration
|
2020-05-16 07:48:31 +10:00
|
|
|
}
|
|
|
|
}
|