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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-06-20 02:03:04 +10:00
|
|
|
ScrollBar.vertical: HScrollBar {
|
2020-05-16 09:23:20 +10:00
|
|
|
visible: listView.interactive
|
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 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-06-26 17:47:55 +10:00
|
|
|
property var checkedIndice: new Set()
|
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) {
|
2020-06-26 17:47:55 +10:00
|
|
|
const model = listView.model.get(i)
|
2020-03-27 20:05:25 +11:00
|
|
|
checked[model.id] = model
|
2020-06-26 17:47:55 +10:00
|
|
|
checkedIndice.add(i)
|
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-06-26 17:47:55 +10:00
|
|
|
checkedIndiceChanged()
|
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-06-26 17:47:55 +10:00
|
|
|
checkedIndice.delete(i)
|
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-06-26 17:47:55 +10:00
|
|
|
checkedIndiceChanged()
|
2020-03-27 19:49:01 +11:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:09:20 +10:00
|
|
|
function uncheckAll() {
|
|
|
|
checked = {}
|
|
|
|
checkedIndice = new Set()
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:49:01 +11:00
|
|
|
function toggleCheck(...indices) {
|
2020-06-26 17:47:55 +10:00
|
|
|
const checkedNow = []
|
2020-03-27 19:49:01 +11:00
|
|
|
|
|
|
|
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-06-26 17:47:55 +10:00
|
|
|
checkedIndice.delete(i)
|
2020-03-27 19:49:01 +11:00
|
|
|
} else {
|
2020-06-26 17:47:55 +10:00
|
|
|
checked[model.id] = model
|
|
|
|
checkedNow.push(i)
|
|
|
|
checkedIndice.add(i)
|
2020-03-27 19:49:01 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:47:55 +10:00
|
|
|
if (checkedNow.length > 0)
|
|
|
|
lastCheckedDelegateIndex = checkedNow.slice(-1)[0]
|
2020-03-27 19:49:01 +11:00
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
checkedChanged()
|
2020-06-26 17:47:55 +10:00
|
|
|
checkedIndiceChanged()
|
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
|
|
|
|
|
|
|
|
2020-05-21 12:03:36 +10:00
|
|
|
HKineticScrollingDisabler {
|
2019-12-11 02:49:46 +11:00
|
|
|
id: mouseArea
|
2020-06-05 15:54:42 +10:00
|
|
|
width: enabled ? parent.width : 0
|
|
|
|
height: enabled ? parent.height : 0
|
2019-12-11 02:49:46 +11:00
|
|
|
}
|
2019-05-14 03:15:03 +10:00
|
|
|
}
|