Fix bugs and improve trackpad scroll precision

Improve trackpad precision by making the amount
of scroll, flickVelocity and flickDeceleration
proportional
This commit is contained in:
vslg 2020-05-18 11:53:26 -03:00
parent 107f928007
commit 3094e47a99
3 changed files with 20 additions and 12 deletions

View File

@ -4,16 +4,8 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
Flickable {
id: flickable
interactive: contentWidth > width || contentHeight > height
ScrollBar.vertical: ScrollBar {
visible: flickable.interactive
}
readonly property HTrackpadFix trackpadFix: HTrackpadFix {
flickable: flickable
width: flickable.width
height: flickable.height
visible: parent.interactive
}
}

View File

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

View File

@ -11,7 +11,8 @@ MouseArea {
onWheel: {
wheel.accepted = false // Disable wheel to avoid too much scroll
// Make components below the stack notice the wheel event
wheel.accepted = false
const pos = getNewPosition(flickable, wheel)
flickable.flick(0, 0)
@ -20,6 +21,7 @@ MouseArea {
property Flickable flickable: parent
property int scrollFactor: 5
// Used to get default flickDeceleration value
readonly property Flickable dummy: Flickable {}
@ -32,7 +34,10 @@ MouseArea {
// When higher pixelDelta, more scroll will be applied
const pixelDelta =
wheel.pixelDelta.y ||
wheel.angleDelta.y / 24 * Qt.styleHints.wheelScrollLines
wheel.angleDelta.y /
24 *
Qt.styleHints.wheelScrollLines *
scrollFactor
// Return current position if there was not any movement
if (flickable.contentHeight < flickable.height || !pixelDelta)
@ -53,9 +58,15 @@ MouseArea {
}
Binding {
target: flickable
property: "maximumFlickVelocity"
value: mouseArea.enabled ? scrollFactor : 4000.0
}
Binding {
target: flickable
property: "flickDeceleration"
value: mouseArea.enabled ? 8000.0 : dummy.flickDeceleration
value: mouseArea.enabled ? scrollFactor * 3 : dummy.flickDeceleration
}
}