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:
parent
107f928007
commit
3094e47a99
|
@ -4,16 +4,8 @@ import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.12
|
import QtQuick.Controls 2.12
|
||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
id: flickable
|
|
||||||
interactive: contentWidth > width || contentHeight > height
|
interactive: contentWidth > width || contentHeight > height
|
||||||
ScrollBar.vertical: ScrollBar {
|
ScrollBar.vertical: ScrollBar {
|
||||||
visible: flickable.interactive
|
visible: parent.interactive
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
readonly property HTrackpadFix trackpadFix: HTrackpadFix {
|
|
||||||
flickable: flickable
|
|
||||||
width: flickable.width
|
|
||||||
height: flickable.height
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,9 @@ HPage {
|
||||||
height: flickable.height
|
height: flickable.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTrackpadFix {
|
||||||
|
flickable: flickable
|
||||||
|
anchors.fill: flickable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ MouseArea {
|
||||||
|
|
||||||
|
|
||||||
onWheel: {
|
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)
|
const pos = getNewPosition(flickable, wheel)
|
||||||
flickable.flick(0, 0)
|
flickable.flick(0, 0)
|
||||||
|
@ -20,6 +21,7 @@ MouseArea {
|
||||||
|
|
||||||
|
|
||||||
property Flickable flickable: parent
|
property Flickable flickable: parent
|
||||||
|
property int scrollFactor: 5
|
||||||
|
|
||||||
// Used to get default flickDeceleration value
|
// Used to get default flickDeceleration value
|
||||||
readonly property Flickable dummy: Flickable {}
|
readonly property Flickable dummy: Flickable {}
|
||||||
|
@ -32,7 +34,10 @@ MouseArea {
|
||||||
// When higher pixelDelta, more scroll will be applied
|
// When higher pixelDelta, more scroll will be applied
|
||||||
const pixelDelta =
|
const pixelDelta =
|
||||||
wheel.pixelDelta.y ||
|
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
|
// Return current position if there was not any movement
|
||||||
if (flickable.contentHeight < flickable.height || !pixelDelta)
|
if (flickable.contentHeight < flickable.height || !pixelDelta)
|
||||||
|
@ -53,9 +58,15 @@ MouseArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Binding {
|
||||||
|
target: flickable
|
||||||
|
property: "maximumFlickVelocity"
|
||||||
|
value: mouseArea.enabled ? scrollFactor : 4000.0
|
||||||
|
}
|
||||||
|
|
||||||
Binding {
|
Binding {
|
||||||
target: flickable
|
target: flickable
|
||||||
property: "flickDeceleration"
|
property: "flickDeceleration"
|
||||||
value: mouseArea.enabled ? 8000.0 : dummy.flickDeceleration
|
value: mouseArea.enabled ? scrollFactor * 3 : dummy.flickDeceleration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user