2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
2019-07-20 15:06:38 -04:00
|
|
|
import QtQuick.Controls 2.12
|
2019-05-13 13:15:03 -04:00
|
|
|
|
2019-08-21 05:02:37 -04:00
|
|
|
ListView {
|
|
|
|
id: listView
|
2019-12-10 11:49:46 -04:00
|
|
|
|
2020-09-02 14:40:06 -04:00
|
|
|
property int defaultCurrentIndex: -1
|
|
|
|
|
2020-02-12 17:58:24 -04:00
|
|
|
property int currentItemHeight: currentItem ? currentItem.height : 0
|
2020-03-26 23:24:37 -04:00
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
property var checked: ({})
|
2020-06-26 03:47:55 -04:00
|
|
|
property var checkedIndice: new Set()
|
2020-03-26 23:24:37 -04:00
|
|
|
property int lastCheckedDelegateIndex: 0
|
2020-03-27 05:05:25 -04:00
|
|
|
property int selectedCount: Object.keys(checked).length
|
2020-03-25 23:06:51 -04:00
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
function check(...indices) {
|
2020-03-25 23:06:51 -04:00
|
|
|
for (const i of indices) {
|
2020-06-26 03:47:55 -04:00
|
|
|
const model = listView.model.get(i)
|
2020-03-27 05:05:25 -04:00
|
|
|
checked[model.id] = model
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndice.add(i)
|
2020-03-25 23:06:51 -04:00
|
|
|
}
|
2020-03-26 23:24:37 -04:00
|
|
|
|
|
|
|
lastCheckedDelegateIndex = indices.slice(-1)[0]
|
2020-03-27 05:05:25 -04:00
|
|
|
checkedChanged()
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndiceChanged()
|
2020-03-25 23:06:51 -04:00
|
|
|
}
|
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
function checkFromLastToHere(here) {
|
2020-03-26 23:24:37 -04:00
|
|
|
const indices = utils.range(lastCheckedDelegateIndex, here)
|
2020-03-27 05:05:25 -04:00
|
|
|
eventList.check(...indices)
|
2020-03-26 23:24:37 -04:00
|
|
|
}
|
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
function uncheck(...indices) {
|
2020-03-25 23:06:51 -04:00
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
2020-03-27 05:05:25 -04:00
|
|
|
delete checked[model.id]
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndice.delete(i)
|
2020-03-25 23:06:51 -04:00
|
|
|
}
|
2020-03-27 04:49:01 -04:00
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
checkedChanged()
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndiceChanged()
|
2020-03-27 04:49:01 -04:00
|
|
|
}
|
|
|
|
|
2020-06-26 06:09:20 -04:00
|
|
|
function uncheckAll() {
|
|
|
|
checked = {}
|
|
|
|
checkedIndice = new Set()
|
|
|
|
}
|
|
|
|
|
2020-03-27 04:49:01 -04:00
|
|
|
function toggleCheck(...indices) {
|
2020-06-26 03:47:55 -04:00
|
|
|
const checkedNow = []
|
2020-03-27 04:49:01 -04:00
|
|
|
|
|
|
|
for (const i of indices) {
|
|
|
|
const model = listView.model.get(i)
|
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
if (model.id in checked) {
|
|
|
|
delete checked[model.id]
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndice.delete(i)
|
2020-03-27 04:49:01 -04:00
|
|
|
} else {
|
2020-06-26 03:47:55 -04:00
|
|
|
checked[model.id] = model
|
|
|
|
checkedNow.push(i)
|
|
|
|
checkedIndice.add(i)
|
2020-03-27 04:49:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 03:47:55 -04:00
|
|
|
if (checkedNow.length > 0)
|
|
|
|
lastCheckedDelegateIndex = checkedNow.slice(-1)[0]
|
2020-03-27 04:49:01 -04:00
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
checkedChanged()
|
2020-06-26 03:47:55 -04:00
|
|
|
checkedIndiceChanged()
|
2020-03-25 23:06:51 -04:00
|
|
|
}
|
|
|
|
|
2020-03-27 05:05:25 -04:00
|
|
|
function getSortedChecked() {
|
|
|
|
return Object.values(checked).sort(
|
2020-03-25 23:06:51 -04:00
|
|
|
(a, b) => a.date > b.date ? 1 : -1
|
|
|
|
)
|
|
|
|
}
|
2019-12-10 11:49:46 -04:00
|
|
|
|
|
|
|
|
2020-09-02 14:40:06 -04:00
|
|
|
currentIndex: defaultCurrentIndex
|
2020-07-12 00:25:57 -04:00
|
|
|
keyNavigationWraps: true
|
|
|
|
highlightMoveDuration: theme.animationDuration
|
|
|
|
highlightResizeDuration: theme.animationDuration
|
|
|
|
|
|
|
|
// Keep highlighted delegate at the center
|
|
|
|
highlightRangeMode: ListView.ApplyRange
|
|
|
|
preferredHighlightBegin: height / 2 - currentItemHeight / 2
|
|
|
|
preferredHighlightEnd: height / 2 + currentItemHeight / 2
|
|
|
|
|
|
|
|
maximumFlickVelocity: window.settings.kineticScrollingMaxSpeed
|
2020-07-14 05:46:48 -04:00
|
|
|
flickDeceleration: window.settings.kineticScrollingDeceleration
|
2020-07-12 00:25:57 -04:00
|
|
|
|
|
|
|
highlight: Rectangle {
|
|
|
|
color: theme.controls.listView.highlight
|
2020-08-19 07:17:21 -04:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
width: theme.controls.listView.highlightBorderThickness
|
|
|
|
height: parent.height
|
|
|
|
color: theme.controls.listView.highlightBorder
|
|
|
|
}
|
2020-07-12 00:25:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBar.vertical: HScrollBar {
|
2020-08-19 09:36:52 -04:00
|
|
|
flickableMoving: listView.moving
|
2020-07-12 00:25:57 -04:00
|
|
|
visible: listView.interactive
|
|
|
|
}
|
|
|
|
|
|
|
|
// property bool debug: false
|
|
|
|
|
|
|
|
// https://doc.qt.io/qt-5/qml-qtquick-viewtransition.html
|
|
|
|
// #handling-interrupted-animations
|
|
|
|
add: Transition {
|
|
|
|
// ScriptAction { script: if (listView.debug) print("add") }
|
|
|
|
HNumberAnimation { property: "opacity"; from: 0; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; from: 0; to: 1 }
|
|
|
|
}
|
|
|
|
|
|
|
|
move: Transition {
|
|
|
|
// ScriptAction { script: if (listView.debug) print("move") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
|
|
|
HNumberAnimation { properties: "x,y" }
|
|
|
|
}
|
|
|
|
|
|
|
|
remove: Transition {
|
|
|
|
// ScriptAction { script: if (listView.debug) print("remove") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 0 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
displaced: Transition {
|
|
|
|
// ScriptAction { script: if (listView.debug) print("displaced") }
|
|
|
|
HNumberAnimation { property: "opacity"; to: 1 }
|
|
|
|
HNumberAnimation { property: "scale"; to: 1 }
|
|
|
|
HNumberAnimation { properties: "x,y" }
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0
|
2020-09-02 14:40:06 -04:00
|
|
|
onModelChanged: currentIndex = defaultCurrentIndex
|
2020-07-12 00:25:57 -04:00
|
|
|
|
2020-05-20 23:03:36 -03:00
|
|
|
HKineticScrollingDisabler {
|
2020-06-05 01:54:42 -04:00
|
|
|
width: enabled ? parent.width : 0
|
|
|
|
height: enabled ? parent.height : 0
|
2019-12-10 11:49:46 -04:00
|
|
|
}
|
2019-05-13 13:15:03 -04:00
|
|
|
}
|