Add HKineticScrollingDisabler to HFlickable
Also make horizontal scrolling available when kinetic scrolling is disabled
This commit is contained in:
parent
5dbcf9c825
commit
6b9077816e
|
@ -4,6 +4,7 @@ import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.12
|
import QtQuick.Controls 2.12
|
||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
|
id: flickable
|
||||||
maximumFlickVelocity: window.settings.kineticScrollingMaxSpeed
|
maximumFlickVelocity: window.settings.kineticScrollingMaxSpeed
|
||||||
flickDeceleration: window.settings.kineticScrollingDeceleration
|
flickDeceleration: window.settings.kineticScrollingDeceleration
|
||||||
|
|
||||||
|
@ -11,4 +12,16 @@ Flickable {
|
||||||
visible: parent.interactive
|
visible: parent.interactive
|
||||||
z: 999
|
z: 999
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
kineticScrollingDisabler = Qt.createComponent(
|
||||||
|
"HKineticScrollingDisabler.qml"
|
||||||
|
).createObject(flickable, {
|
||||||
|
flickable: flickable,
|
||||||
|
width: enabled ? flickable.width : 0,
|
||||||
|
height: enabled ? flickable.height : 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
property var kineticScrollingDisabler
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,26 +12,51 @@ MouseArea {
|
||||||
// Otherwise use wheel.angleDelta, which is available from mouses and
|
// Otherwise use wheel.angleDelta, which is available from mouses and
|
||||||
// low resolution trackpads.
|
// low resolution trackpads.
|
||||||
// When higher pixelDelta, more scroll will be applied
|
// When higher pixelDelta, more scroll will be applied
|
||||||
const pixelDelta =
|
const pixelDelta = {
|
||||||
wheel.pixelDelta.y ||
|
x: wheel.pixelDelta.x ||
|
||||||
wheel.angleDelta.y / 8 * Qt.styleHints.wheelScrollLines
|
wheel.angleDelta.x / 8 * Qt.styleHints.wheelScrollLines,
|
||||||
|
y: wheel.pixelDelta.y ||
|
||||||
|
wheel.angleDelta.y / 8 * Qt.styleHints.wheelScrollLines,
|
||||||
|
}
|
||||||
|
|
||||||
// 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 (
|
||||||
return flickable.contentY
|
flickable.contentHeight < flickable.height ||
|
||||||
|
(! pixelDelta.x && ! pixelDelta.y)
|
||||||
|
)
|
||||||
|
return {x: flickable.contentX, y: flickable.contentY}
|
||||||
|
|
||||||
const maxScroll =
|
// Rotate the direction if shift is pressed
|
||||||
flickable.contentHeight +
|
if (wheel.modifiers === Qt.ShiftModifier)
|
||||||
flickable.originY +
|
[pixelDelta.x, pixelDelta.y] = [pixelDelta.y, pixelDelta.x]
|
||||||
flickable.bottomMargin -
|
|
||||||
flickable.height
|
const maxScroll = {
|
||||||
const minScroll = flickable.topMargin + flickable.originY
|
x: flickable.contentWidth +
|
||||||
|
flickable.originX - // Why subtract?
|
||||||
|
flickable.rightMargin -
|
||||||
|
flickable.width,
|
||||||
|
y: flickable.contentHeight +
|
||||||
|
flickable.originY +
|
||||||
|
flickable.bottomMargin -
|
||||||
|
flickable.height,
|
||||||
|
}
|
||||||
|
|
||||||
|
const minScroll = {
|
||||||
|
x: flickable.originX - flickable.leftMargin,
|
||||||
|
y: flickable.originY - flickable.topMargin,
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid overscrolling
|
// Avoid overscrolling
|
||||||
return Math.max(
|
return {
|
||||||
minScroll,
|
x: Math.max(
|
||||||
Math.min(maxScroll, flickable.contentY - pixelDelta)
|
minScroll.x,
|
||||||
)
|
Math.min(maxScroll.x, flickable.contentX - pixelDelta.x)
|
||||||
|
),
|
||||||
|
y: Math.max(
|
||||||
|
minScroll.y,
|
||||||
|
Math.min(maxScroll.y, flickable.contentY - pixelDelta.y)
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,9 +68,13 @@ MouseArea {
|
||||||
// Make components below the stack notice the wheel event
|
// Make components below the stack notice the wheel event
|
||||||
wheel.accepted = false
|
wheel.accepted = false
|
||||||
|
|
||||||
|
if (wheel.modifiers === Qt.ControlModifier)
|
||||||
|
return
|
||||||
|
|
||||||
const pos = getNewPosition(flickable, wheel)
|
const pos = getNewPosition(flickable, wheel)
|
||||||
flickable.flick(0, 0)
|
flickable.flick(0, 0)
|
||||||
flickable.contentY = pos
|
flickable.contentX = pos.x
|
||||||
|
flickable.contentY = pos.y
|
||||||
}
|
}
|
||||||
|
|
||||||
Binding {
|
Binding {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user