From 5e5a658173344de9077714ca602d37b90645a85e Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 19 Aug 2019 13:09:05 -0400 Subject: [PATCH] Add keybinds to go to previous/next room --- src/python/config_files.py | 12 +++-- src/qml/Base/HFixedListView.qml | 6 +++ src/qml/Base/HListView.qml | 3 -- src/qml/Shortcuts.qml | 9 +++- src/qml/SidePane/AccountRoomList.qml | 13 ++++++ src/qml/SidePane/DelegateAccount.qml | 17 ++++++- src/qml/SidePane/DelegateRoom.qml | 16 ++++++- src/qml/SidePane/SidePane.qml | 68 ---------------------------- 8 files changed, 64 insertions(+), 80 deletions(-) diff --git a/src/python/config_files.py b/src/python/config_files.py index a0b6b6ba..dc27b97b 100644 --- a/src/python/config_files.py +++ b/src/python/config_files.py @@ -115,11 +115,13 @@ class UISettings(JSONConfigFile): "theme": "Default.qpl", "writeAliases": {}, "keys": { - "reloadConfig": ["Alt+Shift+R"], - "scrollUp": ["Alt+Up", "Alt+K"], - "scrollDown": ["Alt+Down", "Alt+J"], - "filterRooms": ["Alt+R", "Ctrl+R"], - "startDebugger": ["Alt+Shift+D"], + "reloadConfig": ["Alt+Shift+R"], + "scrollUp": ["Alt+Up", "Alt+K"], + "scrollDown": ["Alt+Down", "Alt+J"], + "filterRooms": ["Alt+R", "Ctrl+R"], + "goToPreviousRoom": ["Alt+Shift+Up", "Alt+Shift+K"], + "goToNextRoom": ["Alt+Shift+Down", "Alt+Shift+J"], + "startDebugger": ["Alt+Shift+D"], }, } diff --git a/src/qml/Base/HFixedListView.qml b/src/qml/Base/HFixedListView.qml index 3174c596..276db818 100644 --- a/src/qml/Base/HFixedListView.qml +++ b/src/qml/Base/HFixedListView.qml @@ -4,6 +4,12 @@ import QtQuick.Controls 2.12 ListView { interactive: false currentIndex: -1 + highlightMoveDuration: theme.animationDuration + + highlight: HRectangle { + color: theme.controls.interactiveRectangle.checkedOverlay + opacity: theme.controls.interactiveRectangle.checkedOpacity + } add: Transition { HNumberAnimation { properties: "x,y"; from: 100 } diff --git a/src/qml/Base/HListView.qml b/src/qml/Base/HListView.qml index bafe7d7d..6de1c1e3 100644 --- a/src/qml/Base/HListView.qml +++ b/src/qml/Base/HListView.qml @@ -5,8 +5,5 @@ 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 0664b98f..49f4dc99 100644 --- a/src/qml/Shortcuts.qml +++ b/src/qml/Shortcuts.qml @@ -40,8 +40,13 @@ Item { } Shortcut { - sequences: ["Ctrl+N"] - onActivated: mainUI.sidePane.activateNext() + sequences: settings.keys ? settings.keys.goToPreviousRoom : [] + onActivated: mainUI.sidePane.accountRoomList.previous() + } + + Shortcut { + sequences: settings.keys ? settings.keys.goToNextRoom : [] + onActivated: mainUI.sidePane.accountRoomList.next() } /* diff --git a/src/qml/SidePane/AccountRoomList.qml b/src/qml/SidePane/AccountRoomList.qml index 6548fa88..942df962 100644 --- a/src/qml/SidePane/AccountRoomList.qml +++ b/src/qml/SidePane/AccountRoomList.qml @@ -19,6 +19,9 @@ HListView { function filterSource() { let show = [] + // Hide a harmless error when activating a DelegateRoom + try { window.sidePaneModelSource } catch (err) { return } + for (let i = 0; i < window.sidePaneModelSource.length; i++) { let item = window.sidePaneModelSource[i] @@ -47,6 +50,16 @@ HListView { model.source = show } + function previous() { + accountRoomList.decrementCurrentIndex() + accountRoomList.currentItem.item.activate() + } + + function next() { + accountRoomList.incrementCurrentIndex() + accountRoomList.currentItem.item.activate() + } + model: HListModel { keyField: "id" diff --git a/src/qml/SidePane/DelegateAccount.qml b/src/qml/SidePane/DelegateAccount.qml index 8a24c64d..996ef014 100644 --- a/src/qml/SidePane/DelegateAccount.qml +++ b/src/qml/SidePane/DelegateAccount.qml @@ -5,7 +5,7 @@ import "../Base" HInteractiveRectangle { id: accountDelegate color: theme.sidePane.account.background - checked: isCurrent + // checked: isCurrent height: row.height @@ -20,6 +20,13 @@ HInteractiveRectangle { accountRoomList.collapseAccounts[model.data.user_id] || false + onIsCurrentChanged: if (isCurrent) beHighlighted() + + + function beHighlighted() { + accountRoomList.currentIndex = model.index + } + function toggleCollapse() { window.uiState.collapseAccounts[model.data.user_id] = ! collapsed window.uiStateChanged() @@ -32,6 +39,14 @@ HInteractiveRectangle { } + // Component.onCompleted won't work for this + Timer { + interval: 100 + repeat: true + running: accountRoomList.currentIndex == -1 + onTriggered: if (isCurrent) beHighlighted() + } + TapHandler { onTapped: accountDelegate.activate() } HRowLayout { diff --git a/src/qml/SidePane/DelegateRoom.qml b/src/qml/SidePane/DelegateRoom.qml index b13269ad..c4636883 100644 --- a/src/qml/SidePane/DelegateRoom.qml +++ b/src/qml/SidePane/DelegateRoom.qml @@ -9,7 +9,6 @@ HInteractiveRectangle { visible: height > 0 height: rowLayout.height opacity: model.data.left ? theme.sidePane.room.leftRoomOpacity : 1 - checked: isCurrent Behavior on opacity { HNumberAnimation {} } @@ -24,11 +23,26 @@ HInteractiveRectangle { window.uiState.pageProperties.roomId == model.data.room_id + onIsCurrentChanged: if (isCurrent) beHighlighted() + + + function beHighlighted() { + accountRoomList.currentIndex = model.index + } + function activate() { pageStack.showRoom(model.user_id, model.data.room_id) } + // Component.onCompleted won't work for this + Timer { + interval: 100 + repeat: true + running: accountRoomList.currentIndex == -1 + onTriggered: if (isCurrent) beHighlighted() + } + TapHandler { onTapped: activate() } HRowLayout { diff --git a/src/qml/SidePane/SidePane.qml b/src/qml/SidePane/SidePane.qml index 621ae65e..4047693d 100644 --- a/src/qml/SidePane/SidePane.qml +++ b/src/qml/SidePane/SidePane.qml @@ -71,74 +71,6 @@ 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