diff --git a/src/models/sortfilterroomlistmodel.h b/src/models/sortfilterroomlistmodel.h index 7e86b1f4c..98847181f 100644 --- a/src/models/sortfilterroomlistmodel.h +++ b/src/models/sortfilterroomlistmodel.h @@ -38,6 +38,9 @@ class SortFilterRoomListModel : public QSortFilterProxyModel */ Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) + // This is a lazy hack to make this model compatible with SearchPage. TODO: rename the property entirely + Q_PROPERTY(QString searchText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) + public: explicit SortFilterRoomListModel(RoomListModel *sourceModel, QObject *parent = nullptr); diff --git a/src/qml/ChooseRoomDialog.qml b/src/qml/ChooseRoomDialog.qml index 9f2be0816..fff4a6fdf 100644 --- a/src/qml/ChooseRoomDialog.qml +++ b/src/qml/ChooseRoomDialog.qml @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Tobias Fella // SPDX-License-Identifier: GPL-2.0-or-later +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls @@ -8,29 +10,20 @@ import org.kde.kirigami as Kirigami import org.kde.neochat -Kirigami.ScrollablePage { +SearchPage { id: root title: i18nc("@title", "Choose a Room") + showSearchButton: false + signal chosen(string roomId) required property NeoChatConnection connection - header: Kirigami.SearchField { - onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text + model: RoomManager.sortFilterRoomListModel + modelDelegate: RoomDelegate { + onClicked: root.chosen(currentRoom.id) + connection: root.connection } - - ListView { - model: RoomManager.sortFilterRoomListModel - delegate: RoomDelegate { - id: roomDelegate - onClicked: { - root.chosen(roomDelegate.currentRoom.id); - } - connection: root.connection - } - } - - Component.onCompleted: Qt.callLater(() => header.forceActiveFocus()) } diff --git a/src/qml/SearchPage.qml b/src/qml/SearchPage.qml index 5232f07f2..3d9d29933 100644 --- a/src/qml/SearchPage.qml +++ b/src/qml/SearchPage.qml @@ -75,6 +75,11 @@ Kirigami.ScrollablePage { */ property alias listVerticalLayoutDirection: listView.verticalLayoutDirection + /** + * @brief Set the visibility of the search button. + */ + property bool showSearchButton: true + /** * @brief Force the search field to be focussed. */ @@ -127,6 +132,7 @@ Kirigami.ScrollablePage { id: searchButton icon.name: "search" display: QQC2.Button.IconOnly + visible: root.showSearchButton text: i18nc("@action:button", "Search") onClicked: {