Rename HListView checking-related functions

This commit is contained in:
miruka 2020-03-27 05:05:25 -04:00
parent 3f69710813
commit af6cdc9013
6 changed files with 31 additions and 32 deletions

View File

@ -1,5 +1,6 @@
# TODO # TODO
- focus color
- Long-press-drag to select multiple messages on touch - Long-press-drag to select multiple messages on touch
- Drag to select multiple messages on non-touch - Drag to select multiple messages on non-touch

View File

@ -71,33 +71,33 @@ ListView {
property alias cursorShape: mouseArea.cursorShape property alias cursorShape: mouseArea.cursorShape
property int currentItemHeight: currentItem ? currentItem.height : 0 property int currentItemHeight: currentItem ? currentItem.height : 0
property var checkedDelegates: ({}) property var checked: ({})
property int lastCheckedDelegateIndex: 0 property int lastCheckedDelegateIndex: 0
property int selectedCount: Object.keys(checkedDelegates).length property int selectedCount: Object.keys(checked).length
function delegatesChecked(...indices) { function check(...indices) {
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
checkedDelegates[model.id] = model checked[model.id] = model
} }
lastCheckedDelegateIndex = indices.slice(-1)[0] lastCheckedDelegateIndex = indices.slice(-1)[0]
checkedDelegatesChanged() checkedChanged()
} }
function delegatesFromLastToHereChecked(here) { function checkFromLastToHere(here) {
const indices = utils.range(lastCheckedDelegateIndex, here) const indices = utils.range(lastCheckedDelegateIndex, here)
eventList.delegatesChecked(...indices) eventList.check(...indices)
} }
function delegatesUnchecked(...indices) { function uncheck(...indices) {
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
delete checkedDelegates[model.id] delete checked[model.id]
} }
checkedDelegatesChanged() checkedChanged()
} }
function toggleCheck(...indices) { function toggleCheck(...indices) {
@ -106,10 +106,10 @@ ListView {
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
if (model.id in checkedDelegates) { if (model.id in checked) {
delete checkedDelegates[model.id] delete checked[model.id]
} else { } else {
checkedDelegates[model.id] = model checked[model.id] = model
checkedIndices.push(i) checkedIndices.push(i)
} }
} }
@ -117,11 +117,11 @@ ListView {
if (checkedIndices.length > 0) if (checkedIndices.length > 0)
lastCheckedDelegateIndex = checkedIndices.slice(-1)[0] lastCheckedDelegateIndex = checkedIndices.slice(-1)[0]
checkedDelegatesChanged() checkedChanged()
} }
function getSortedCheckedDelegates() { function getSortedChecked() {
return Object.values(checkedDelegates).sort( return Object.values(checked).sort(
(a, b) => a.date > b.date ? 1 : -1 (a, b) => a.date > b.date ? 1 : -1
) )
} }

View File

@ -172,7 +172,7 @@ HRowLayout {
Connections { Connections {
target: eventList target: eventList
onCheckedDelegatesChanged: contentLabel.deselect() onCheckedChanged: contentLabel.deselect()
onDelegateWithSelectedTextChanged: onDelegateWithSelectedTextChanged:
if (eventList.delegateWithSelectedText !== model.id) if (eventList.delegateWithSelectedText !== model.id)
contentLabel.deselect() contentLabel.deselect()
@ -193,14 +193,14 @@ HRowLayout {
(! parent.hoveredLink || (! parent.hoveredLink ||
! parent.enableLinkActivation)) { ! parent.enableLinkActivation)) {
eventList.delegatesChecked(model.index) eventList.check(model.index)
checkedNow = true checkedNow = true
} }
if (! active && eventDelegate.checked) { if (! active && eventDelegate.checked) {
checkedNow ? checkedNow ?
checkedNow = false : checkedNow = false :
eventList.delegatesUnchecked(model.index) eventList.uncheck(model.index)
} }
} }
@ -220,7 +220,7 @@ HRowLayout {
(! parent.hoveredLink || (! parent.hoveredLink ||
! parent.enableLinkActivation)) { ! parent.enableLinkActivation)) {
eventList.delegatesFromLastToHereChecked(model.index) eventList.checkFromLastToHere(model.index)
} }
} }
} }

View File

@ -10,7 +10,7 @@ HColumnLayout {
id: eventDelegate id: eventDelegate
width: eventList.width width: eventList.width
ListView.onRemove: eventList.delegatesUnchecked(model.id) ListView.onRemove: eventList.uncheck(model.id)
enum Media { Page, File, Image, Video, Audio } enum Media { Page, File, Image, Video, Audio }
@ -22,7 +22,7 @@ HColumnLayout {
readonly property var nextModel: eventList.model.get(model.index - 1) readonly property var nextModel: eventList.model.get(model.index - 1)
readonly property QtObject currentModel: model readonly property QtObject currentModel: model
property bool checked: model.id in eventList.checkedDelegates property bool checked: model.id in eventList.checked
property bool compact: window.settings.compactMode property bool compact: window.settings.compactMode
property bool isOwn: chat.userId === model.sender_id property bool isOwn: chat.userId === model.sender_id
property bool onRight: eventList.ownEventsOnRight && isOwn property bool onRight: eventList.ownEventsOnRight && isOwn
@ -79,9 +79,7 @@ HColumnLayout {
} }
function toggleChecked() { function toggleChecked() {
eventDelegate.checked ? eventList.toggleCheck(model.index)
eventList.delegatesUnchecked(model.index) :
eventList.delegatesChecked(model.index)
} }
@ -122,7 +120,7 @@ HColumnLayout {
TapHandler { TapHandler {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
acceptedModifiers: Qt.ShiftModifier acceptedModifiers: Qt.ShiftModifier
onTapped: eventList.delegatesFromLastToHereChecked(model.index) onTapped: eventList.checkFromLastToHere(model.index)
} }
TapHandler { TapHandler {
@ -154,14 +152,14 @@ HColumnLayout {
visible: eventList.selectedCount >= 2 visible: eventList.selectedCount >= 2
icon.name: "unselect-all-messages" icon.name: "unselect-all-messages"
text: qsTr("Unselect all") text: qsTr("Unselect all")
onTriggered: eventList.checkedDelegates = {} onTriggered: eventList.checked = {}
} }
HMenuItem { HMenuItem {
visible: model.index !== 0 visible: model.index !== 0
icon.name: "select-until-here" icon.name: "select-until-here"
text: qsTr("Select until here") text: qsTr("Select until here")
onTriggered: eventList.delegatesFromLastToHereChecked(model.index) onTriggered: eventList.checkFromLastToHere(model.index)
} }
HMenuItem { HMenuItem {

View File

@ -94,7 +94,7 @@ HMxcImage {
TapHandler { TapHandler {
acceptedModifiers: Qt.ShiftModifier acceptedModifiers: Qt.ShiftModifier
onTapped: onTapped:
eventList.delegatesFromLastToHereChecked(singleMediaInfo.index) eventList.checkFromLastToHere(singleMediaInfo.index)
gesturePolicy: TapHandler.ReleaseWithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds
} }

View File

@ -19,7 +19,7 @@ Rectangle {
onActivated: { onActivated: {
eventList.currentIndex !== -1 ? eventList.currentIndex !== -1 ?
eventList.currentIndex = -1 : eventList.currentIndex = -1 :
eventList.checkedDelegates = {} eventList.checked = {}
} }
} }
@ -46,7 +46,7 @@ Rectangle {
enabled: eventList.currentItem enabled: eventList.currentItem
sequences: window.settings.keys.selectMessagesUntilHere sequences: window.settings.keys.selectMessagesUntilHere
onActivated: onActivated:
eventList.delegatesFromLastToHereChecked(eventList.currentIndex) eventList.checkFromLastToHere(eventList.currentIndex)
} }
HShortcut { HShortcut {
@ -139,7 +139,7 @@ Rectangle {
const contents = [] const contents = []
for (const model of eventList.getSortedCheckedDelegates()) { for (const model of eventList.getSortedChecked()) {
contents.push(JSON.parse(model.source).body) contents.push(JSON.parse(model.source).body)
} }