From 3cc39210b40fedbc00fa3e00e41ad7b3b06b0f86 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 17 Aug 2019 20:29:56 -0400 Subject: [PATCH] Work in progress keybard sidepane navigation --- src/qml/Base/HListView.qml | 3 ++ src/qml/Shortcuts.qml | 5 ++ src/qml/SidePane/AccountDelegate.qml | 23 ++++++---- src/qml/SidePane/RoomDelegate.qml | 7 ++- src/qml/SidePane/RoomList.qml | 1 + src/qml/SidePane/SidePane.qml | 69 ++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 10 deletions(-) diff --git a/src/qml/Base/HListView.qml b/src/qml/Base/HListView.qml index 6de1c1e3..bafe7d7d 100644 --- a/src/qml/Base/HListView.qml +++ b/src/qml/Base/HListView.qml @@ -5,5 +5,8 @@ HFixedListView { interactive: true keyNavigationWraps: true + // This is used to smooth scroll when currentIndex is changed + highlightMoveDuration: theme.animationDuration * 4 + ScrollBar.vertical: ScrollBar {} } diff --git a/src/qml/Shortcuts.qml b/src/qml/Shortcuts.qml index 73f5d2f6..0664b98f 100644 --- a/src/qml/Shortcuts.qml +++ b/src/qml/Shortcuts.qml @@ -39,6 +39,11 @@ Item { onActivated: if (debugMode) { py.call("APP.pdb") } } + Shortcut { + sequences: ["Ctrl+N"] + onActivated: mainUI.sidePane.activateNext() + } + /* Shortcut { sequence: "Ctrl+-" diff --git a/src/qml/SidePane/AccountDelegate.qml b/src/qml/SidePane/AccountDelegate.qml index d7db3613..6d4afa0e 100644 --- a/src/qml/SidePane/AccountDelegate.qml +++ b/src/qml/SidePane/AccountDelegate.qml @@ -11,10 +11,16 @@ Column { paneToolBar.roomFilter && roomList.model.count < 1 ? 0.3 : 1 Behavior on opacity { HNumberAnimation {} } + property alias roomList: roomList + property bool forceExpand: paneToolBar.roomFilter && roomList.model.count property bool expanded: true readonly property var modelItem: model + readonly property bool isCurrent: + window.uiState.page == "Pages/EditAccount/EditAccount.qml" && + window.uiState.pageProperties.userId == model.user_id + Component.onCompleted: expanded = ! window.uiState.collapseAccounts[model.user_id] @@ -23,20 +29,21 @@ Column { window.uiStateChanged() } + function activate() { + pageStack.showPage( + "EditAccount/EditAccount", { "userId": model.user_id } + ) + } + HInteractiveRectangle { + id: rectangle width: parent.width height: childrenRect.height color: theme.sidePane.account.background - checked: - window.uiState.page == "Pages/EditAccount/EditAccount.qml" && - window.uiState.pageProperties.userId == model.user_id + checked: accountDelegate.isCurrent - TapHandler { - onTapped: pageStack.showPage( - "EditAccount/EditAccount", { "userId": model.user_id } - ) - } + TapHandler { onTapped: accountDelegate.activate() } HRowLayout { id: row diff --git a/src/qml/SidePane/RoomDelegate.qml b/src/qml/SidePane/RoomDelegate.qml index 78ba9b18..ef5f992f 100644 --- a/src/qml/SidePane/RoomDelegate.qml +++ b/src/qml/SidePane/RoomDelegate.qml @@ -12,12 +12,15 @@ HInteractiveRectangle { opacity: model.left ? theme.sidePane.room.leftRoomOpacity : 1 Behavior on opacity { HNumberAnimation {} } - checked: + checked: isCurrent + readonly property bool isCurrent: window.uiState.page == "Chat/Chat.qml" && window.uiState.pageProperties.userId == userId && window.uiState.pageProperties.roomId == model.room_id - TapHandler { onTapped: pageStack.showRoom(userId, model.room_id) } + function activate() { pageStack.showRoom(userId, model.room_id) } + + TapHandler { onTapped: activate() } HRowLayout { id: rowLayout diff --git a/src/qml/SidePane/RoomList.qml b/src/qml/SidePane/RoomList.qml index 7084ce0a..d84671cd 100644 --- a/src/qml/SidePane/RoomList.qml +++ b/src/qml/SidePane/RoomList.qml @@ -4,6 +4,7 @@ import "../utils.js" as Utils HFixedListView { id: roomList + property string userId: "" model: HListModel { diff --git a/src/qml/SidePane/SidePane.qml b/src/qml/SidePane/SidePane.qml index 82c9e8c0..bba0cd2c 100644 --- a/src/qml/SidePane/SidePane.qml +++ b/src/qml/SidePane/SidePane.qml @@ -1,6 +1,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 import "../Base" +import "../utils.js" as Utils HRectangle { id: sidePane @@ -70,6 +71,74 @@ HRectangle { } + function _getRoomModelSource(accountUserId) { + return Utils.filterModelSource( + modelSources[["Room", accountUserId]] || [], + paneToolBar.roomFilter, + ) + } + + function _activateNextAccount(i) { + let nextIndex = i + 1 > accountList.model.count - 1 ? 0 : i + 1 + if (nextIndex == i) return + + pageStack.showPage( + "EditAccount/EditAccount", + {userId: accountList.model.get(nextIndex).user_id} + ) + + accountList.currentIndex = nextIndex + } + + function activateNext() { + if (accountList.model.count < 1) return + + for (let i = 0; i < accountList.model.count; i++) { + let account = accountList.model.get(i) + + if (window.uiState.page == "Pages/EditAccount/EditAccount.qml" && + window.uiState.pageProperties.userId == account.user_id) + { + let room = _getRoomModelSource(account.user_id)[0] + + if (room) { pageStack.showRoom(account.user_id, room.room_id) } + else { _activateNextAccount(i) } + return + } + + if (window.uiState.page == "Chat/Chat.qml" && + window.uiState.pageProperties.userId == account.user_id) + { + let rooms = _getRoomModelSource(account.user_id) + + if (! rooms) { _activateNextAccount(i); return } + + for (let ri = 0; ri < rooms.length; ri++) { + let room = rooms[ri] + + if (room.room_id != window.uiState.pageProperties.roomId) { + continue + } + + if (ri + 1 > rooms.length -1) { + _activateNextAccount(i) + return + } + + pageStack.showRoom(account.user_id, rooms[ri + 1].room_id) + + let currentRoomItem = + accountList.itemAtIndex(i).roomList.itemAtIndex(ri) + + print(currentRoomItem.visible) + + return + } + } + } + } + + HColumnLayout { anchors.fill: parent