2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
2019-07-21 05:06:38 +10:00
|
|
|
import QtQuick.Controls 2.12
|
2019-05-14 03:15:03 +10:00
|
|
|
|
2019-08-21 19:02:37 +10:00
|
|
|
ListView {
|
|
|
|
id: listView
|
2019-12-11 02:49:46 +11:00
|
|
|
interactive: allowDragging
|
2019-08-21 19:02:37 +10:00
|
|
|
currentIndex: -1
|
2019-08-18 06:59:13 +10:00
|
|
|
keyNavigationWraps: true
|
2019-08-21 19:02:37 +10:00
|
|
|
highlightMoveDuration: theme.animationDuration
|
2019-08-18 06:59:13 +10:00
|
|
|
|
2019-08-21 19:02:37 +10:00
|
|
|
// Keep highlighted delegate at the center
|
|
|
|
highlightRangeMode: ListView.ApplyRange
|
|
|
|
preferredHighlightBegin: height / 2 - currentItemHeight
|
|
|
|
preferredHighlightEnd: height / 2 + currentItemHeight
|
|
|
|
|
2019-09-07 07:03:52 +10:00
|
|
|
maximumFlickVelocity: 4000
|
2019-08-21 19:02:37 +10:00
|
|
|
|
|
|
|
|
2019-08-28 12:46:31 +10:00
|
|
|
highlight: Rectangle {
|
2019-08-21 19:02:37 +10:00
|
|
|
color: theme.controls.listView.highlight
|
|
|
|
}
|
|
|
|
|
2019-09-07 06:46:04 +10:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
2019-12-11 02:49:46 +11:00
|
|
|
visible: listView.interactive || ! listView.allowDragging
|
2019-09-07 06:46:04 +10:00
|
|
|
}
|
2019-08-21 19:02:37 +10:00
|
|
|
|
2019-12-16 05:36:24 +11:00
|
|
|
// Make sure to handle when a previous transition gets interrupted
|
2019-08-21 19:02:37 +10:00
|
|
|
add: Transition {
|
|
|
|
ParallelAnimation {
|
2019-12-16 05:36:24 +11:00
|
|
|
ScriptAction { script: print("add") }
|
2019-12-02 02:24:20 +11:00
|
|
|
HNumberAnimation { property: "opacity"; from: 0; to: 1 }
|
2019-12-16 05:36:24 +11:00
|
|
|
HNumberAnimation { property: "scale"; from: 0; to: 1 }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
move: Transition {
|
|
|
|
ParallelAnimation {
|
2019-12-16 05:36:24 +11:00
|
|
|
ScriptAction { script: print("move") }
|
2019-12-02 02:24:20 +11:00
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
2019-12-16 05:36:24 +11:00
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
2019-12-02 02:24:20 +11:00
|
|
|
HNumberAnimation { properties: "x,y" }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remove: Transition {
|
|
|
|
ParallelAnimation {
|
2019-12-16 05:36:24 +11:00
|
|
|
ScriptAction { script: print("remove") }
|
2019-12-02 02:24:20 +11:00
|
|
|
HNumberAnimation { property: "opacity"; to: 0 }
|
2019-12-16 05:36:24 +11:00
|
|
|
HNumberAnimation { property: "scale"; to: 0 }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 05:36:24 +11:00
|
|
|
// displaced: move
|
|
|
|
displaced: Transition {
|
|
|
|
ParallelAnimation {
|
|
|
|
ScriptAction { script: print("displaced") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
|
|
|
HNumberAnimation { properties: "x,y" }
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 02:49:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
property bool allowDragging: true
|
|
|
|
|
|
|
|
property alias cursorShape: mouseArea.cursorShape
|
|
|
|
|
|
|
|
readonly property int currentItemHeight:
|
|
|
|
currentItem ? currentItem.height : 0
|
|
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: listView
|
|
|
|
enabled: ! listView.allowDragging
|
|
|
|
// interactive gets temporarily set to true below to allow wheel scroll
|
|
|
|
onDraggingChanged: listView.interactive = false
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: ! parent.allowDragging || cursorShape !== Qt.ArrowCursor
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
onWheel: {
|
|
|
|
// Allow wheel usage, will be back to false on any drag attempt
|
|
|
|
parent.interactive = true
|
|
|
|
wheel.accepted = false
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 03:15:03 +10:00
|
|
|
}
|