From a9f05a7f634e31ab25bc0f91d2113051dcc96f07 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 22 Apr 2024 23:12:12 +0200 Subject: [PATCH] Remove search bar; Use QuickSwitcher instead (cherry picked from commit 69b6f16ec1c81d9999e7fb8cae671522ba393b4c) --- src/enums/neochatroomtype.h | 5 -- src/models/roomtreemodel.cpp | 3 - src/models/sortfilterroomtreemodel.cpp | 4 -- src/qml/ExploreComponent.qml | 30 ++++++-- src/qml/Main.qml | 11 ++- src/qml/QuickSwitcher.qml | 96 ++++++++++++++------------ src/qml/RoomDelegate.qml | 4 +- src/qml/RoomListPage.qml | 20 ++---- 8 files changed, 87 insertions(+), 86 deletions(-) diff --git a/src/enums/neochatroomtype.h b/src/enums/neochatroomtype.h index 368532168..6d33757fb 100644 --- a/src/enums/neochatroomtype.h +++ b/src/enums/neochatroomtype.h @@ -21,7 +21,6 @@ public: * @brief Defines the room list categories a room can be assigned. */ enum Types { - Search = 0, /**< So we can show a search delegate if needed, e.g. collapsed mode. */ Invited, /**< The user has been invited to the room. */ Favorite, /**< The room is set as a favourite. */ Direct, /**< The room is a direct chat. */ @@ -68,8 +67,6 @@ public: return i18n("Low priority"); case NeoChatRoomType::Space: return i18n("Spaces"); - case NeoChatRoomType::Search: - return i18n("Search"); default: return {}; } @@ -89,8 +86,6 @@ public: return QStringLiteral("object-order-lower"); case NeoChatRoomType::Space: return QStringLiteral("group"); - case NeoChatRoomType::Search: - return QStringLiteral("search"); default: return QStringLiteral("tools-report-bug"); } diff --git a/src/models/roomtreemodel.cpp b/src/models/roomtreemodel.cpp index 3693414bf..709ebff11 100644 --- a/src/models/roomtreemodel.cpp +++ b/src/models/roomtreemodel.cpp @@ -300,9 +300,6 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const return NeoChatRoomType::typeName(index.row()); } if (role == DelegateTypeRole) { - if (index.row() == NeoChatRoomType::Search) { - return QStringLiteral("search"); - } if (index.row() == NeoChatRoomType::AddDirect) { return QStringLiteral("addDirect"); } diff --git a/src/models/sortfilterroomtreemodel.cpp b/src/models/sortfilterroomtreemodel.cpp index 77f150280..e3c3339d1 100644 --- a/src/models/sortfilterroomtreemodel.cpp +++ b/src/models/sortfilterroomtreemodel.cpp @@ -129,10 +129,6 @@ QString SortFilterRoomTreeModel::filterText() const bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!source_parent.isValid()) { - if (sourceModel()->data(sourceModel()->index(source_row, 0), RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::Search - && NeoChatConfig::collapsed()) { - return true; - } if (sourceModel()->data(sourceModel()->index(source_row, 0), RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::AddDirect && m_mode == DirectChats) { return true; diff --git a/src/qml/ExploreComponent.qml b/src/qml/ExploreComponent.qml index 6cf7c170f..646d6926a 100644 --- a/src/qml/ExploreComponent.qml +++ b/src/qml/ExploreComponent.qml @@ -17,7 +17,7 @@ RowLayout { property bool collapsed: false required property NeoChatConnection connection - property alias roomSearchFieldFocussed: roomSearchField.activeFocus + signal search property Kirigami.Action exploreAction: Kirigami.Action { text: i18n("Explore rooms") @@ -83,14 +83,30 @@ RowLayout { */ signal textChanged(string newText) - Kirigami.SearchField { - id: roomSearchField - Layout.topMargin: Kirigami.Units.smallSpacing - Layout.bottomMargin: Kirigami.Units.smallSpacing + Item { + Layout.preferredWidth: Kirigami.Units.largeSpacing + } + + Kirigami.Heading { Layout.fillWidth: true - Layout.preferredWidth: root.desiredWidth ? root.desiredWidth - menuButton.width - root.spacing : -1 visible: !root.collapsed - onTextChanged: root.textChanged(text) + text: i18nc("@title", "Rooms") + } + Item { + Layout.fillWidth: true + visible: root.collapsed + } + + QQC2.ToolButton { + id: searchButton + display: QQC2.AbstractButton.IconOnly + onClicked: root.search(); + icon.name: "search" + text: i18nc("@action", "Search Room") + Shortcut { + sequence: "Ctrl+F" + onActivated: searchButton.clicked() + } } QQC2.ToolButton { diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 0d536fd02..8fecdb9a1 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -98,12 +98,9 @@ Kirigami.ApplicationWindow { } } - Loader { - id: quickView - active: !Kirigami.Settings.isMobile - sourceComponent: QuickSwitcher { - connection: root.connection - } + QuickSwitcher { + id: quickSwitcher + connection: root.connection } Connections { @@ -226,6 +223,8 @@ Kirigami.ApplicationWindow { RoomListPage { id: roomList + onSearch: quickSwitcher.open() + connection: root.connection Shortcut { diff --git a/src/qml/QuickSwitcher.qml b/src/qml/QuickSwitcher.qml index 6f49e8f7b..02f18f589 100644 --- a/src/qml/QuickSwitcher.qml +++ b/src/qml/QuickSwitcher.qml @@ -6,6 +6,7 @@ import QtQuick.Controls as QQC2 import QtQuick.Layouts import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.components import org.kde.kitemmodels import org.kde.neochat @@ -19,10 +20,10 @@ QQC2.Dialog { width: Math.min(700, parent.width) height: 400 - leftPadding: 0 - rightPadding: 0 - bottomPadding: 1 - topPadding: 0 + leftPadding: Kirigami.Units.smallSpacing + rightPadding: Kirigami.Units.smallSpacing + bottomPadding: Kirigami.Units.smallSpacing + topPadding: Kirigami.Units.smallSpacing anchors.centerIn: applicationWindow().overlay @@ -40,53 +41,60 @@ QQC2.Dialog { roomList.currentIndex = 0; } - header: Kirigami.SearchField { - id: searchField - Keys.onDownPressed: { - roomList.forceActiveFocus(); - if (roomList.currentIndex < roomList.count - 1) { - roomList.currentIndex++; - } else { - roomList.currentIndex = 0; + background: DialogRoundedBackground {} + + contentItem: ColumnLayout { + Kirigami.SearchField { + id: searchField + Layout.fillWidth: true + Keys.onDownPressed: { + roomList.forceActiveFocus(); + if (roomList.currentIndex < roomList.count - 1) { + roomList.currentIndex++; + } else { + roomList.currentIndex = 0; + } } - } - Keys.onUpPressed: { - if (roomList.currentIndex === 0) { - roomList.currentIndex = roomList.count - 1; - } else { - roomList.currentIndex--; + Keys.onUpPressed: { + if (roomList.currentIndex === 0) { + roomList.currentIndex = roomList.count - 1; + } else { + roomList.currentIndex--; + } } + Keys.onEnterPressed: { + RoomManager.resolveResource(roomList.currentItem.currentRoom.id); + root.close(); + } + Keys.onReturnPressed: { + RoomManager.resolveResource(roomList.currentItem.currentRoom.id); + root.close(); + } + focusSequence: "" + onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text } - Keys.onEnterPressed: { - RoomManager.resolveResource(roomList.currentItem.currentRoom.id); - root.close(); - } - Keys.onReturnPressed: { - RoomManager.resolveResource(roomList.currentItem.currentRoom.id); - root.close(); - } - focusSequence: "" - onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text - } - QQC2.ScrollView { - anchors.fill: parent - clip: true + QQC2.ScrollView { + clip: true - Keys.forwardTo: searchField - - ListView { - id: roomList - - currentIndex: 0 - highlightMoveDuration: 200 + Layout.fillWidth: true + Layout.fillHeight: true Keys.forwardTo: searchField - keyNavigationEnabled: true - model: RoomManager.sortFilterRoomListModel - delegate: RoomDelegate { - connection: root.connection - onClicked: root.close() + ListView { + id: roomList + + currentIndex: 0 + highlightMoveDuration: 200 + Keys.forwardTo: searchField + keyNavigationEnabled: true + model: RoomManager.sortFilterRoomListModel + + delegate: RoomDelegate { + connection: root.connection + onClicked: root.close() + showConfigure: false + } } } } diff --git a/src/qml/RoomDelegate.qml b/src/qml/RoomDelegate.qml index 127bad0bb..f132117d5 100644 --- a/src/qml/RoomDelegate.qml +++ b/src/qml/RoomDelegate.qml @@ -25,6 +25,8 @@ Delegates.RoundedItemDelegate { required property string subtitleText required property string displayName + property bool showConfigure: true + property bool collapsed: false readonly property bool hasNotifications: contextNotificationCount > 0 @@ -130,7 +132,7 @@ Delegates.RoundedItemDelegate { QQC2.Button { id: configButton - visible: root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList && !root.collapsed + visible: root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList && !root.collapsed && root.showConfigure text: i18n("Configure room") display: QQC2.Button.IconOnly diff --git a/src/qml/RoomListPage.qml b/src/qml/RoomListPage.qml index e373d2235..0fbe291af 100644 --- a/src/qml/RoomListPage.qml +++ b/src/qml/RoomListPage.qml @@ -29,6 +29,8 @@ Kirigami.Page { readonly property bool collapsed: Config.collapsed + signal search + onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth Component.onCompleted: pageStack.defaultColumnWidth = root.currentWidth @@ -164,22 +166,6 @@ Kirigami.Page { } } - DelegateChoice { - roleValue: "search" - delegate: Delegates.RoundedItemDelegate { - required property TreeView treeView - - implicitWidth: treeView.width - onClicked: quickView.item.open() - - contentItem: Kirigami.Icon { - width: Kirigami.Units.iconSizes.smallMedium - height: Kirigami.Units.iconSizes.smallMedium - source: "search" - } - } - } - DelegateChoice { roleValue: "addDirect" delegate: Delegates.RoundedItemDelegate { @@ -312,6 +298,8 @@ Kirigami.Page { collapsed: root.collapsed connection: root.connection + onSearch: root.search() + onTextChanged: newText => { RoomManager.sortFilterRoomTreeModel.filterText = newText; treeView.expandRecursively();