Use Shortcut for keyboard room switching

This allows to use the room switching shortcuts like Ctrl+PgUp/PgDn even
when the RoomPage doesn't currently have the focus. It's also a nice
code simplification.
This commit is contained in:
Kevin Wolf
2023-02-20 21:52:05 +01:00
committed by Tobias Fella
parent 33c9edc9a3
commit d7bd9f4609
2 changed files with 9 additions and 26 deletions

View File

@@ -44,9 +44,6 @@ Kirigami.ScrollablePage {
}
}
signal switchRoomUp()
signal switchRoomDown()
onCurrentRoomChanged: {
applicationWindow().hoverLinkIndicator.text = "";
messageListView.positionViewAtBeginning();
@@ -120,26 +117,8 @@ Kirigami.ScrollablePage {
focus: true
Keys.onTabPressed: {
if (event.modifiers & Qt.ControlModifier) {
switchRoomDown();
}
}
Keys.onBacktabPressed: {
if (event.modifiers & Qt.ControlModifier) {
switchRoomUp();
}
}
Keys.onPressed: {
if (event.key === Qt.Key_PageDown && (event.modifiers & Qt.ControlModifier)) {
event.accepted = true;
switchRoomDown();
} else if (event.key === Qt.Key_PageUp && (event.modifiers & Qt.ControlModifier)) {
event.accepted = true;
switchRoomUp();
} else if (!(event.modifiers & Qt.ControlModifier) && event.key < Qt.Key_Escape) {
if (!(event.modifiers & Qt.ControlModifier) && event.key < Qt.Key_Escape) {
event.accepted = true;
chatBox.chatBar.insertText(event.text);
chatBox.chatBar.forceActiveFocus();

View File

@@ -317,12 +317,16 @@ Kirigami.ApplicationWindow {
RoomListPage {
id: roomList
Connections {
target: root.roomPage
function onSwitchRoomUp() {
Shortcut {
sequences: ["Ctrl+PgUp", "Ctrl+Backtab"]
onActivated: {
roomList.goToPreviousRoom();
}
function onSwitchRoomDown() {
}
Shortcut {
sequences: ["Ctrl+PgDown", "Ctrl+Tab"]
onActivated: {
roomList.goToNextRoom();
}
}