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

View File

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

View File

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