Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import QtQuick 2.7
Item {
id: root
property Flickable flickable: parent
anchors.fill: parent
property MouseArea mouseArea
readonly property bool active: flickable && (mouseArea ? mouseArea.drag.active : false)
readonly property real mouseY: active ? mouseArea.mapToItem(root, 0, mouseArea.mouseY).y : 0
readonly property real mousex: active ? mouseArea.mapToItem(root, mouseArea.mouseX, 0).x : 0
property real maxVelocity: 600
property real velocityPerDistance: 10
property int interval: 5
readonly property real maxStep: maxVelocity / (1000 / interval)
readonly property real stepPerDistance: velocityPerDistance / (1000 / interval)
Timer {
running: root.active && root.mouseY < 0 && !root.flickable.atYBeginning
triggeredOnStart: true
repeat: true
interval: root.interval
onTriggered: flickable.contentY -= Math.min(root.maxStep, -root.mouseY * root.stepPerDistance)
}
Timer {
running: root.active && root.mouseY > root.height && !root.flickable.atYEnd
triggeredOnStart: true
repeat: true
interval: root.interval
onTriggered: root.flickable.contentY += Math.min(root.maxStep, (root.mouseY - root.height) * root.stepPerDistance)
}
Connections {
enabled: active
target: listView
onContentYChanged: fakeDraggedMove()
}
function fakeDraggedMove() {
var dragged = mouseArea.drag.target;
--dragged.y;
++dragged.y;
}
Text {
anchors.right: parent.right
text: active ? mouseArea.drag.target.y : ''
}
DropArea {
parent: flickable
anchors.fill: parent
onEntered: {
drag.accepted = false;
var source = drag.source;
if (!source)
return;
var mouseArea;
if (source.drag)
mouseArea = source;
else if (source.parent.drag)
mouseArea = source.parent;
else if (source.mouseArea)
mouseArea = source.mouseArea;
if (ancestorOf(flickable, mouseArea))
root.mouseArea = mouseArea;
}
}
function ancestorOf(ancestor, item) {
if (!item)
return false;
while (item.parent) {
if (item.parent === ancestor)
return true;
item = item.parent;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment