2019-12-02 16:29:29 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
2020-02-03 16:19:42 -04:00
|
|
|
import SortFilterProxyModel 0.2
|
2019-12-02 16:29:29 -04:00
|
|
|
import ".."
|
|
|
|
import "../Base"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: mainPaneList
|
|
|
|
model: ModelStore.get("accounts")
|
|
|
|
|
|
|
|
delegate: AccountRoomsDelegate {
|
|
|
|
width: mainPaneList.width
|
|
|
|
height: childrenRect.height
|
|
|
|
}
|
|
|
|
|
2020-02-12 17:58:24 -04:00
|
|
|
highlightFollowsCurrentItem: false
|
|
|
|
currentItemHeight:
|
|
|
|
selectedRoom ? selectedRoom.height :
|
|
|
|
currentItem ? currentItem.account.height : 0
|
|
|
|
|
|
|
|
highlight: Rectangle {
|
|
|
|
y:
|
|
|
|
selectedRoom ?
|
|
|
|
currentItem.y + currentItem.account.height +
|
|
|
|
currentItem.roomList.currentItem.y :
|
|
|
|
currentItem.y
|
|
|
|
|
|
|
|
width: mainPaneList.width
|
|
|
|
height:
|
|
|
|
selectedRoom ?
|
|
|
|
currentItem.roomList.currentItem.height :
|
|
|
|
currentItem.account.height
|
|
|
|
|
|
|
|
color: theme.controls.listView.highlight
|
|
|
|
|
|
|
|
Behavior on y { HNumberAnimation {} }
|
|
|
|
Behavior on height { HNumberAnimation {} }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
readonly property Room selectedRoom:
|
|
|
|
currentItem ? currentItem.roomList.currentItem : null
|
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
|
|
|
|
function previous(activate=true) {
|
2020-02-12 17:58:24 -04:00
|
|
|
let currentAccount = currentItem
|
|
|
|
|
|
|
|
// Nothing is selected
|
|
|
|
if (! currentAccount) {
|
|
|
|
decrementCurrentIndex()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let roomList = currentAccount.roomList
|
|
|
|
|
|
|
|
// An account is selected
|
|
|
|
if (! roomList.currentItem) {
|
|
|
|
decrementCurrentIndex()
|
|
|
|
// Select the last room of the previous account that's now selected
|
|
|
|
currentItem.roomList.decrementCurrentIndex()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// A room is selected
|
|
|
|
const selectedIsFirst = roomList.currentIndex === 0
|
|
|
|
const noRooms = roomList.count === 0
|
|
|
|
|
|
|
|
if (currentAccount.collapsed || selectedIsFirst || noRooms) {
|
|
|
|
// Have the account itself be selected
|
|
|
|
roomList.currentIndex = -1
|
|
|
|
} else {
|
|
|
|
roomList.decrementCurrentIndex()
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function next(activate=true) {
|
2020-02-12 17:58:24 -04:00
|
|
|
const currentAccount = currentItem
|
|
|
|
|
|
|
|
// Nothing is selected
|
|
|
|
if (! currentAccount) {
|
|
|
|
incrementCurrentIndex()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const roomList = currentAccount.roomList
|
|
|
|
|
|
|
|
// An account is selected
|
|
|
|
if (! roomList.currentItem) {
|
|
|
|
if (currentAccount.collapsed || roomList.count === 0) {
|
|
|
|
incrementCurrentIndex()
|
|
|
|
} else {
|
|
|
|
roomList.incrementCurrentIndex()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// A room is selected
|
|
|
|
const selectedIsLast = roomList.currentIndex >= roomList.count - 1
|
|
|
|
const noRooms = roomList.count === 0
|
|
|
|
|
|
|
|
if (currentAccount.collapsed || selectedIsLast || noRooms) {
|
|
|
|
roomList.currentIndex = -1
|
|
|
|
mainPaneList.incrementCurrentIndex()
|
|
|
|
} else {
|
|
|
|
roomList.incrementCurrentIndex()
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function activate() {
|
|
|
|
currentItem.item.activated()
|
|
|
|
}
|
|
|
|
|
|
|
|
function accountSettings() {
|
|
|
|
if (! currentItem) incrementCurrentIndex()
|
2020-02-12 17:58:24 -04:00
|
|
|
currentItem.roomList.currentIndex = -1
|
|
|
|
currentItem.account.activated()
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function addNewChat() {
|
|
|
|
if (! currentItem) incrementCurrentIndex()
|
2020-02-12 17:58:24 -04:00
|
|
|
currentItem.roomList.currentIndex = -1
|
|
|
|
currentItem.account.activated()
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleCollapseAccount() {
|
2020-02-03 16:19:42 -04:00
|
|
|
if (mainPane.filter) return
|
2019-12-02 16:29:29 -04:00
|
|
|
if (! currentItem) incrementCurrentIndex()
|
2020-02-12 17:58:24 -04:00
|
|
|
currentItem.account.toggleCollapse()
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: activateLimiter
|
|
|
|
interval: 300
|
|
|
|
onTriggered: activate()
|
|
|
|
}
|
|
|
|
}
|