moment/src/gui/Base/HListView.qml

140 lines
3.8 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.12
2019-05-14 03:15:03 +10:00
ListView {
id: listView
currentIndex: -1
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
2019-09-07 07:03:52 +10:00
maximumFlickVelocity: 4000
2019-08-28 12:46:31 +10:00
highlight: Rectangle {
color: theme.controls.listView.highlight
}
2020-06-20 02:03:04 +10:00
ScrollBar.vertical: HScrollBar {
visible: listView.interactive
2019-09-07 06:46:04 +10:00
}
// 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
property alias cursorShape: mouseArea.cursorShape
property int currentItemHeight: currentItem ? currentItem.height : 0
property var checked: ({})
2020-06-26 17:47:55 +10:00
property var checkedIndice: new Set()
property int lastCheckedDelegateIndex: 0
property int selectedCount: Object.keys(checked).length
function check(...indices) {
for (const i of indices) {
2020-06-26 17:47:55 +10:00
const model = listView.model.get(i)
checked[model.id] = model
2020-06-26 17:47:55 +10:00
checkedIndice.add(i)
}
lastCheckedDelegateIndex = indices.slice(-1)[0]
checkedChanged()
2020-06-26 17:47:55 +10:00
checkedIndiceChanged()
}
function checkFromLastToHere(here) {
const indices = utils.range(lastCheckedDelegateIndex, here)
eventList.check(...indices)
}
function uncheck(...indices) {
for (const i of indices) {
const model = listView.model.get(i)
delete checked[model.id]
2020-06-26 17:47:55 +10:00
checkedIndice.delete(i)
}
checkedChanged()
2020-06-26 17:47:55 +10:00
checkedIndiceChanged()
}
function uncheckAll() {
checked = {}
checkedIndice = new Set()
}
function toggleCheck(...indices) {
2020-06-26 17:47:55 +10:00
const checkedNow = []
for (const i of indices) {
const model = listView.model.get(i)
if (model.id in checked) {
delete checked[model.id]
2020-06-26 17:47:55 +10:00
checkedIndice.delete(i)
} else {
2020-06-26 17:47:55 +10:00
checked[model.id] = model
checkedNow.push(i)
checkedIndice.add(i)
}
}
2020-06-26 17:47:55 +10:00
if (checkedNow.length > 0)
lastCheckedDelegateIndex = checkedNow.slice(-1)[0]
checkedChanged()
2020-06-26 17:47:55 +10:00
checkedIndiceChanged()
}
function getSortedChecked() {
return Object.values(checked).sort(
(a, b) => a.date > b.date ? 1 : -1
)
}
HKineticScrollingDisabler {
id: mouseArea
width: enabled ? parent.width : 0
height: enabled ? parent.height : 0
}
2019-05-14 03:15:03 +10:00
}