AccountRoomList keyboard up/down

Item activation or proper scrolling not reimplemented yet
This commit is contained in:
miruka 2020-02-12 17:58:24 -04:00
parent ce0a868579
commit a78f5506b8
3 changed files with 101 additions and 37 deletions

View File

@ -9,11 +9,12 @@ ListView {
currentIndex: -1
keyNavigationWraps: true
highlightMoveDuration: theme.animationDuration
highlightResizeDuration: theme.animationDuration
// Keep highlighted delegate at the center
highlightRangeMode: ListView.ApplyRange
preferredHighlightBegin: height / 2 - currentItemHeight
preferredHighlightEnd: height / 2 + currentItemHeight
preferredHighlightBegin: height / 2 - currentItemHeight / 2
preferredHighlightEnd: height / 2 + currentItemHeight / 2
maximumFlickVelocity: 4000
@ -65,11 +66,8 @@ ListView {
property bool allowDragging: true
property alias cursorShape: mouseArea.cursorShape
readonly property int currentItemHeight:
currentItem ? currentItem.height : 0
property int currentItemHeight: currentItem ? currentItem.height : 0
Connections {

View File

@ -17,6 +17,10 @@ Column {
roomList.model.count < 1 &&
! utils.filterMatches(mainPane.filter, model.display_name)
readonly property alias account: account
readonly property alias collapsed: account.collapsed
readonly property alias roomList: roomList
Account {
id: account
@ -63,6 +67,8 @@ Column {
userId: delegate.userId
}
highlight: null // managed by the AccountRoomsList
Behavior on height { HNumberAnimation {} }
}
}

View File

@ -14,15 +14,97 @@ HListView {
height: childrenRect.height
}
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
function previous(activate=true) {
let currentAccount = currentItem
// Nothing is selected
if (! currentAccount) {
decrementCurrentIndex()
if (activate) activateLimiter.restart()
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()
}
}
function next(activate=true) {
const currentAccount = currentItem
// Nothing is selected
if (! currentAccount) {
incrementCurrentIndex()
if (activate) activateLimiter.restart()
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()
}
}
function activate() {
@ -31,42 +113,20 @@ HListView {
function accountSettings() {
if (! currentItem) incrementCurrentIndex()
pageLoader.showPage(
"AccountSettings/AccountSettings",
{userId: currentItem.item.delegateModel.user_id},
)
currentItem.roomList.currentIndex = -1
currentItem.account.activated()
}
function addNewChat() {
if (! currentItem) incrementCurrentIndex()
pageLoader.showPage(
"AddChat/AddChat",
{userId: currentItem.item.delegateModel.user_id},
)
currentItem.roomList.currentIndex = -1
currentItem.account.activated()
}
function toggleCollapseAccount() {
if (mainPane.filter) return
if (! currentItem) incrementCurrentIndex()
if (currentItem.item.delegateModel.type === "Account") {
currentItem.item.toggleCollapse()
return
}
for (let i = 0; i < model.source.length; i++) {
let item = model.source[i]
if (item.type === "Account" && item.user_id ==
currentItem.item.delegateModel.user_id)
{
currentIndex = i
currentItem.item.toggleCollapse()
}
}
currentItem.account.toggleCollapse()
}