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
|
|
|
|
|
2020-05-01 16:12:58 +10:00
|
|
|
// https://doc.qt.io/qt-5/qml-qtquick-viewtransition.html
|
|
|
|
// #handling-interrupted-animations
|
2019-08-21 19:02:37 +10:00
|
|
|
add: Transition {
|
2020-05-01 16:12:58 +10:00
|
|
|
// ScriptAction { script: if (listView.debug) print("add") }
|
|
|
|
HNumberAnimation { property: "opacity"; from: 0; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; from: 0; to: 1 }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
move: Transition {
|
2020-05-01 16:12:58 +10:00
|
|
|
// ScriptAction { script: if (listView.debug) print("move") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
|
|
|
HNumberAnimation { properties: "x,y" }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
remove: Transition {
|
2020-05-01 16:12:58 +10:00
|
|
|
// ScriptAction { script: if (listView.debug) print("remove") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 0 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 0 }
|
2019-08-21 19:02:37 +10:00
|
|
|
}
|
|
|
|
|
2019-12-16 05:36:24 +11:00
|
|
|
displaced: Transition {
|
2020-05-01 16:12:58 +10:00
|
|
|
// ScriptAction { script: if (listView.debug) print("displaced") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
|
|
|
HNumberAnimation { properties: "x,y" }
|
2019-12-16 05:36:24 +11:00
|
|
|
}
|
2019-12-11 02:49:46 +11:00
|
|
|
|
2020-03-27 14:24:37 +11:00
|
|
|
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
|
|
|
|
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-27 14:24:37 +11:00
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
property var checked: ({})
|
2020-03-27 14:24:37 +11:00
|
|
|
property int lastCheckedDelegateIndex: 0
|
2020-03-27 20:05:25 +11:00
|
|
|
property int selectedCount: Object.keys(checked).length
|
2020-03-26 14:06:51 +11:00
|
|
|
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
function check(...indices) {
|
2020-03-26 14:06:51 +11:00
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
2020-03-27 20:05:25 +11:00
|
|
|
checked[model.id] = model
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
2020-03-27 14:24:37 +11:00
|
|
|
|
|
|
|
lastCheckedDelegateIndex = indices.slice(-1)[0]
|
2020-03-27 20:05:25 +11:00
|
|
|
checkedChanged()
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
function checkFromLastToHere(here) {
|
2020-03-27 14:24:37 +11:00
|
|
|
const indices = utils.range(lastCheckedDelegateIndex, here)
|
2020-03-27 20:05:25 +11:00
|
|
|
eventList.check(...indices)
|
2020-03-27 14:24:37 +11:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
function uncheck(...indices) {
|
2020-03-26 14:06:51 +11:00
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
2020-03-27 20:05:25 +11:00
|
|
|
delete checked[model.id]
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
2020-03-27 19:49:01 +11:00
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
checkedChanged()
|
2020-03-27 19:49:01 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleCheck(...indices) {
|
|
|
|
const checkedIndices = []
|
|
|
|
|
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
if (model.id in checked) {
|
|
|
|
delete checked[model.id]
|
2020-03-27 19:49:01 +11:00
|
|
|
} else {
|
2020-03-27 20:05:25 +11:00
|
|
|
checked[model.id] = model
|
2020-03-27 19:49:01 +11:00
|
|
|
checkedIndices.push(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkedIndices.length > 0)
|
|
|
|
lastCheckedDelegateIndex = checkedIndices.slice(-1)[0]
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
checkedChanged()
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
function getSortedChecked() {
|
|
|
|
return Object.values(checked).sort(
|
2020-03-26 14:06:51 +11:00
|
|
|
(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
|
|
|
}
|