2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
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
|
2020-02-13 08:58:24 +11:00
|
|
|
highlightResizeDuration: 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
|
2020-02-13 08:58:24 +11:00
|
|
|
preferredHighlightBegin: height / 2 - currentItemHeight / 2
|
|
|
|
preferredHighlightEnd: height / 2 + currentItemHeight / 2
|
2019-08-21 19:02:37 +10:00
|
|
|
|
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-03 07:29:29 +11:00
|
|
|
// property bool debug: false
|
|
|
|
|
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-03 07:29:29 +11:00
|
|
|
// ScriptAction { script: if (listView.debug) 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-03 07:29:29 +11:00
|
|
|
// ScriptAction { script: if (listView.debug) 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-03 07:29:29 +11:00
|
|
|
// ScriptAction { script: if (listView.debug) 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: Transition {
|
|
|
|
ParallelAnimation {
|
2019-12-03 07:29:29 +11:00
|
|
|
// ScriptAction { script: if (listView.debug) print("displaced") }
|
2019-12-16 05:36:24 +11:00
|
|
|
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
|
2020-02-13 08:58:24 +11:00
|
|
|
property int currentItemHeight: currentItem ? currentItem.height : 0
|
2020-03-26 14:06:51 +11:00
|
|
|
property var checkedDelegates: ({})
|
|
|
|
property int selectedCount: Object.keys(checkedDelegates).length
|
|
|
|
|
|
|
|
|
|
|
|
function delegatesChecked(...indices) {
|
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
|
|
|
checkedDelegates[model.id] = model
|
|
|
|
}
|
|
|
|
checkedDelegatesChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
function delegatesUnchecked(...indices) {
|
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
|
|
|
delete checkedDelegates[model.id]
|
|
|
|
}
|
|
|
|
checkedDelegatesChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSortedCheckedDelegates() {
|
|
|
|
return Object.values(checkedDelegates).sort(
|
|
|
|
(a, b) => a.date > b.date ? 1 : -1
|
|
|
|
)
|
|
|
|
}
|
2019-12-11 02:49:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|