Created
September 20, 2018 10:21
-
-
Save oKcerG/5016483a589496b9aadff04928fcc709 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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