From ce15a8d6976dfdb2643644a15ed45f6f36ae0626 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Wed, 2 Jun 2021 13:47:29 -0400 Subject: [PATCH] Add quick switcher --- imports/NeoChat/Component/QuickSwitcher.qml | 81 +++++++++++++++++++++ imports/NeoChat/Component/qmldir | 1 + qml/main.qml | 13 ++++ res.qrc | 1 + 4 files changed, 96 insertions(+) create mode 100644 imports/NeoChat/Component/QuickSwitcher.qml diff --git a/imports/NeoChat/Component/QuickSwitcher.qml b/imports/NeoChat/Component/QuickSwitcher.qml new file mode 100644 index 00000000..444c3f9b --- /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 b5697c80..eca83c0c 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 e3557bfa..321ec6b8 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 11e76d59..bcd75244 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 -- GitLab