diff --git a/imports/NeoChat/Component/QuickSwitcher.qml b/imports/NeoChat/Component/QuickSwitcher.qml new file mode 100644 index 0000000000000000000000000000000000000000..444c3f9b6b6c0134971f120854688fc63a38572a --- /dev/null +++ b/imports/NeoChat/Component/QuickSwitcher.qml @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: 2021 Carson Black +// SPDX-License-Identifier: GPL-3.0-only + +import QtQuick 2.15 +import QtQuick.Layouts 1.10 +import QtQuick.Controls 2.12 as QQC2 +import org.kde.kirigami 2.14 as Kirigami +import org.kde.kitemmodels 1.0 +import org.kde.neochat 1.0 + +QQC2.Popup { + id: _popup + + onVisibleChanged: { + if (!visible) { + return + } + quickSearch.forceActiveFocus() + quickSearch.text = "" + } + anchors.centerIn: QQC2.Overlay.overlay + background: Kirigami.Card {} + height: 2 * Math.round(implicitHeight / 2) + padding: Kirigami.Units.largeSpacing * 2 + contentItem: ColumnLayout { + spacing: Kirigami.Units.largeSpacing * 2 + + Kirigami.SearchField { + id: quickSearch + + // TODO: get this broken property removed/disabled by default in Kirigami, + // we used to be able to expect that the text field wouldn't attempt to + // perform a mini-DDOS attack using signals. + autoAccept: false + + Layout.preferredWidth: Kirigami.Units.gridUnit * 21 // 3 * 7 = 21, roughly 7 avatars on screen + Keys.onLeftPressed: cView.decrementCurrentIndex() + Keys.onRightPressed: cView.incrementCurrentIndex() + onAccepted: { + const item = cView.itemAtIndex(cView.currentIndex) + + RoomManager.enterRoom(item.currentRoom) + + _popup.close() + } + } + ListView { + id: cView + + orientation: Qt.Horizontal + spacing: Kirigami.Units.largeSpacing + + model: SortFilterRoomListModel { + id: sortFilterRoomListModel + sourceModel: RoomListModel { + id: roomListModel + connection: Controller.activeConnection + } + filterText: quickSearch.text + roomSortOrder: SortFilterRoomListModel.LastActivity + } + + Layout.preferredHeight: Kirigami.Units.gridUnit * 3 + Layout.fillWidth: true + + delegate: Kirigami.Avatar { + id: del + + implicitHeight: Kirigami.Units.gridUnit * 3 + implicitWidth: Kirigami.Units.gridUnit * 3 + + required property string avatar + required property var currentRoom + + source: avatar != "" ? "image://mxc/" + avatar : "" + } + } + } + modal: true + focus: true +} diff --git a/imports/NeoChat/Component/qmldir b/imports/NeoChat/Component/qmldir index b5697c802ef0301ec944bfa391ec78110180b051..eca83c0cc8ad8941aa6e0974a7d66527ed938f85 100644 --- a/imports/NeoChat/Component/qmldir +++ b/imports/NeoChat/Component/qmldir @@ -3,3 +3,4 @@ FullScreenImage 1.0 FullScreenImage.qml ChatTextInput 1.0 ChatTextInput.qml FancyEffectsContainer 1.0 FancyEffectsContainer.qml TypingPane 1.0 TypingPane.qml +QuickSwitcher 1.0 QuickSwitcher.qml diff --git a/qml/main.qml b/qml/main.qml index e3557bfa0adf4fed9ad123601cea7436b74d826a..321ec6b8c4a83769314f86960ad1c92f93334f48 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -52,6 +52,19 @@ Kirigami.ApplicationWindow { onXChanged: saveWindowGeometryTimer.restart() onYChanged: saveWindowGeometryTimer.restart() + Shortcut { + sequence: "Ctrl+K" + onActivated: { + quickView.item.open() + } + } + + Loader { + id: quickView + + active: !Kirigami.Settings.isMobile + sourceComponent: QuickSwitcher { } + } /// Setup keyboard navigation to the room page. function connectRoomToSignal(item) { diff --git a/res.qrc b/res.qrc index 11e76d59242576ae8bf7ede600b1da436358eb4b..bcd7524439615a942333e69f8cab8ec0c6d1ec85 100644 --- a/res.qrc +++ b/res.qrc @@ -18,6 +18,7 @@ imports/NeoChat/Component/FullScreenImage.qml imports/NeoChat/Component/FancyEffectsContainer.qml imports/NeoChat/Component/TypingPane.qml + imports/NeoChat/Component/QuickSwitcher.qml imports/NeoChat/Component/ChatBox imports/NeoChat/Component/ChatBox/ChatBox.qml imports/NeoChat/Component/ChatBox/ChatBar.qml