2019-12-02 16:29:29 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import ".."
|
|
|
|
import "../Base"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: mainPaneList
|
|
|
|
model: ModelStore.get("accounts")
|
2020-03-12 23:17:23 -04:00
|
|
|
spacing: mainPane.small ? theme.spacing : 0
|
2019-12-02 16:29:29 -04:00
|
|
|
|
|
|
|
delegate: AccountRoomsDelegate {
|
|
|
|
width: mainPaneList.width
|
|
|
|
height: childrenRect.height
|
|
|
|
}
|
|
|
|
|
2020-02-13 05:36:28 -04:00
|
|
|
// Must handle the highlight's position and size manually because
|
|
|
|
// of our nested lists
|
2020-02-12 17:58:24 -04:00
|
|
|
highlightFollowsCurrentItem: false
|
2020-02-13 05:36:28 -04:00
|
|
|
highlightRangeMode: ListView.NoHighlightRange
|
2020-02-12 17:58:24 -04:00
|
|
|
|
|
|
|
highlight: Rectangle {
|
2020-02-13 05:36:28 -04:00
|
|
|
id: highlightRectangle
|
2020-02-12 17:58:24 -04:00
|
|
|
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
|
|
|
|
|
2020-03-12 23:17:23 -04:00
|
|
|
color:
|
|
|
|
mainPane.small ?
|
|
|
|
theme.controls.listView.smallPaneHighlight :
|
|
|
|
theme.controls.listView.highlight
|
2020-02-12 17:58:24 -04:00
|
|
|
|
2020-02-14 10:24:42 -04:00
|
|
|
Behavior on y { HNumberAnimation { id: yAnimation } }
|
2020-02-12 17:58:24 -04:00
|
|
|
Behavior on height { HNumberAnimation {} }
|
2020-03-12 23:17:23 -04:00
|
|
|
Behavior on color { HColorAnimation {} }
|
2020-02-13 05:36:28 -04:00
|
|
|
|
|
|
|
Binding {
|
|
|
|
target: mainPaneList
|
|
|
|
property: "contentY"
|
2020-03-07 12:37:39 -04:00
|
|
|
value: highlightRectangle.y + highlightRectangle.height / 2 -
|
|
|
|
mainPaneList.height / 2
|
2020-02-13 05:36:28 -04:00
|
|
|
delayed: true
|
2020-02-14 10:24:42 -04:00
|
|
|
when: yAnimation.running
|
2020-02-13 05:36:28 -04:00
|
|
|
}
|
2020-03-07 09:32:56 -04:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: mainPaneList
|
|
|
|
enabled: yAnimation.running
|
|
|
|
onContentYChanged: mainPaneList.returnToBounds()
|
|
|
|
}
|
2020-02-12 17:58:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 05:38:28 -04:00
|
|
|
property bool detachedCurrentIndex: false
|
|
|
|
|
2020-02-12 17:58:24 -04:00
|
|
|
readonly property Room selectedRoom:
|
|
|
|
currentItem ? currentItem.roomList.currentItem : null
|
|
|
|
|
2020-03-10 06:07:09 -04:00
|
|
|
readonly property bool hasActiveAccount:
|
|
|
|
window.uiState.page === "Pages/Chat/Chat.qml" ||
|
|
|
|
window.uiState.page === "Pages/AddChat/AddChat.qml" ||
|
|
|
|
window.uiState.page === "Pages/AccountSettings/AccountSettings.qml"
|
|
|
|
|
|
|
|
readonly property var activeAccountIndex:
|
|
|
|
hasActiveAccount ?
|
|
|
|
model.findIndex(window.uiState.pageProperties.userId) : null
|
|
|
|
|
2020-03-10 05:38:28 -04:00
|
|
|
|
2020-03-12 23:17:23 -04:00
|
|
|
|
2020-03-07 10:15:54 -04:00
|
|
|
function previous() {
|
2020-03-10 05:38:28 -04:00
|
|
|
detachedCurrentIndex = true
|
|
|
|
|
2020-03-07 10:15:54 -04:00
|
|
|
if (! mainPane.filter) {
|
|
|
|
_previous()
|
|
|
|
return
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
|
2020-03-07 10:15:54 -04:00
|
|
|
let reachedStart = false
|
|
|
|
do {
|
|
|
|
if (currentIndex === count - 1 && reachedStart) break
|
|
|
|
_previous()
|
|
|
|
if (currentIndex === 0) reachedStart = true
|
|
|
|
} while (! currentItem.roomList.currentItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
function _previous() {
|
2020-03-08 04:46:20 -04:00
|
|
|
const currentAccount = currentItem
|
2020-02-12 17:58:24 -04:00
|
|
|
|
|
|
|
// Nothing is selected
|
|
|
|
if (! currentAccount) {
|
|
|
|
decrementCurrentIndex()
|
|
|
|
}
|
|
|
|
|
2020-03-08 04:46:20 -04:00
|
|
|
const roomList = currentAccount.roomList
|
2020-02-12 17:58:24 -04:00
|
|
|
|
|
|
|
// 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
|
2020-03-10 05:38:28 -04:00
|
|
|
roomList.currentIndex = -1 // XXX
|
2020-02-12 17:58:24 -04:00
|
|
|
} else {
|
|
|
|
roomList.decrementCurrentIndex()
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2020-03-07 10:15:54 -04:00
|
|
|
function next() {
|
2020-03-10 05:38:28 -04:00
|
|
|
detachedCurrentIndex = true
|
|
|
|
|
2020-03-07 10:15:54 -04:00
|
|
|
if (! mainPane.filter) {
|
|
|
|
_next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let reachedEnd = false
|
|
|
|
do {
|
|
|
|
if (currentIndex === 0 && reachedEnd) break
|
|
|
|
_next()
|
|
|
|
if (currentIndex === count - 1) reachedEnd = true
|
|
|
|
} while (! currentItem.roomList.currentItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
function _next() {
|
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) {
|
2020-03-10 05:38:28 -04:00
|
|
|
roomList.currentIndex = -1 // XXX
|
2020-02-12 17:58:24 -04:00
|
|
|
mainPaneList.incrementCurrentIndex()
|
|
|
|
} else {
|
|
|
|
roomList.incrementCurrentIndex()
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2020-02-13 05:56:10 -04:00
|
|
|
function requestActivate() {
|
|
|
|
activateLimiter.restart()
|
|
|
|
}
|
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
function activate() {
|
2020-03-07 11:28:51 -04:00
|
|
|
if (! currentItem) next()
|
|
|
|
|
2020-02-13 05:56:10 -04:00
|
|
|
selectedRoom ?
|
|
|
|
currentItem.roomList.currentItem.activated() :
|
|
|
|
currentItem.account.activated()
|
2020-03-10 05:38:28 -04:00
|
|
|
|
|
|
|
detachedCurrentIndex = false
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function accountSettings() {
|
2020-03-07 11:28:51 -04:00
|
|
|
if (! currentItem) next()
|
2020-02-12 17:58:24 -04:00
|
|
|
currentItem.account.activated()
|
2020-03-10 05:38:28 -04:00
|
|
|
|
|
|
|
detachedCurrentIndex = false
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function addNewChat() {
|
2020-03-07 11:28:51 -04:00
|
|
|
if (! currentItem) next()
|
2020-02-13 05:56:10 -04:00
|
|
|
currentItem.account.addChat.clicked()
|
2020-03-10 05:38:28 -04:00
|
|
|
|
|
|
|
detachedCurrentIndex = false
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2020-03-07 11:28:51 -04:00
|
|
|
function setCollapseAccount(collapse) {
|
|
|
|
if (! currentItem) return
|
|
|
|
currentItem.account.setCollapse(collapse)
|
|
|
|
}
|
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
function toggleCollapseAccount() {
|
2020-02-03 16:19:42 -04:00
|
|
|
if (mainPane.filter) return
|
2020-03-07 11:28:51 -04:00
|
|
|
if (! currentItem) next()
|
|
|
|
|
2020-02-12 17:58:24 -04:00
|
|
|
currentItem.account.toggleCollapse()
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2020-02-13 05:56:10 -04:00
|
|
|
|
2020-03-10 05:38:28 -04:00
|
|
|
Binding on currentIndex {
|
|
|
|
value:
|
2020-03-10 06:07:09 -04:00
|
|
|
hasActiveAccount ?
|
|
|
|
(activeAccountIndex === null ? -1 : activeAccountIndex) : -1
|
2020-02-13 06:58:13 -04:00
|
|
|
|
2020-03-10 05:38:28 -04:00
|
|
|
when: ! detachedCurrentIndex
|
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: activateLimiter
|
2020-03-11 12:56:11 -04:00
|
|
|
interval: 200
|
2019-12-02 16:29:29 -04:00
|
|
|
onTriggered: activate()
|
|
|
|
}
|
|
|
|
}
|