Remove search bar; Use QuickSwitcher instead

(cherry picked from commit 69b6f16ec1)
This commit is contained in:
Tobias Fella
2024-04-22 23:12:12 +02:00
parent 4dfd4b68eb
commit a9f05a7f63
8 changed files with 87 additions and 86 deletions

View File

@@ -21,7 +21,6 @@ public:
* @brief Defines the room list categories a room can be assigned. * @brief Defines the room list categories a room can be assigned.
*/ */
enum Types { 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. */ Invited, /**< The user has been invited to the room. */
Favorite, /**< The room is set as a favourite. */ Favorite, /**< The room is set as a favourite. */
Direct, /**< The room is a direct chat. */ Direct, /**< The room is a direct chat. */
@@ -68,8 +67,6 @@ public:
return i18n("Low priority"); return i18n("Low priority");
case NeoChatRoomType::Space: case NeoChatRoomType::Space:
return i18n("Spaces"); return i18n("Spaces");
case NeoChatRoomType::Search:
return i18n("Search");
default: default:
return {}; return {};
} }
@@ -89,8 +86,6 @@ public:
return QStringLiteral("object-order-lower"); return QStringLiteral("object-order-lower");
case NeoChatRoomType::Space: case NeoChatRoomType::Space:
return QStringLiteral("group"); return QStringLiteral("group");
case NeoChatRoomType::Search:
return QStringLiteral("search");
default: default:
return QStringLiteral("tools-report-bug"); return QStringLiteral("tools-report-bug");
} }

View File

@@ -300,9 +300,6 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
return NeoChatRoomType::typeName(index.row()); return NeoChatRoomType::typeName(index.row());
} }
if (role == DelegateTypeRole) { if (role == DelegateTypeRole) {
if (index.row() == NeoChatRoomType::Search) {
return QStringLiteral("search");
}
if (index.row() == NeoChatRoomType::AddDirect) { if (index.row() == NeoChatRoomType::AddDirect) {
return QStringLiteral("addDirect"); return QStringLiteral("addDirect");
} }

View File

@@ -129,10 +129,6 @@ QString SortFilterRoomTreeModel::filterText() const
bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{ {
if (!source_parent.isValid()) { 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 if (sourceModel()->data(sourceModel()->index(source_row, 0), RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::AddDirect
&& m_mode == DirectChats) { && m_mode == DirectChats) {
return true; return true;

View File

@@ -17,7 +17,7 @@ RowLayout {
property bool collapsed: false property bool collapsed: false
required property NeoChatConnection connection required property NeoChatConnection connection
property alias roomSearchFieldFocussed: roomSearchField.activeFocus signal search
property Kirigami.Action exploreAction: Kirigami.Action { property Kirigami.Action exploreAction: Kirigami.Action {
text: i18n("Explore rooms") text: i18n("Explore rooms")
@@ -83,14 +83,30 @@ RowLayout {
*/ */
signal textChanged(string newText) signal textChanged(string newText)
Kirigami.SearchField { Item {
id: roomSearchField Layout.preferredWidth: Kirigami.Units.largeSpacing
Layout.topMargin: Kirigami.Units.smallSpacing }
Layout.bottomMargin: Kirigami.Units.smallSpacing
Kirigami.Heading {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredWidth: root.desiredWidth ? root.desiredWidth - menuButton.width - root.spacing : -1
visible: !root.collapsed 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 { QQC2.ToolButton {

View File

@@ -98,12 +98,9 @@ Kirigami.ApplicationWindow {
} }
} }
Loader { QuickSwitcher {
id: quickView id: quickSwitcher
active: !Kirigami.Settings.isMobile connection: root.connection
sourceComponent: QuickSwitcher {
connection: root.connection
}
} }
Connections { Connections {
@@ -226,6 +223,8 @@ Kirigami.ApplicationWindow {
RoomListPage { RoomListPage {
id: roomList id: roomList
onSearch: quickSwitcher.open()
connection: root.connection connection: root.connection
Shortcut { Shortcut {

View File

@@ -6,6 +6,7 @@ import QtQuick.Controls as QQC2
import QtQuick.Layouts import QtQuick.Layouts
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components
import org.kde.kitemmodels import org.kde.kitemmodels
import org.kde.neochat import org.kde.neochat
@@ -19,10 +20,10 @@ QQC2.Dialog {
width: Math.min(700, parent.width) width: Math.min(700, parent.width)
height: 400 height: 400
leftPadding: 0 leftPadding: Kirigami.Units.smallSpacing
rightPadding: 0 rightPadding: Kirigami.Units.smallSpacing
bottomPadding: 1 bottomPadding: Kirigami.Units.smallSpacing
topPadding: 0 topPadding: Kirigami.Units.smallSpacing
anchors.centerIn: applicationWindow().overlay anchors.centerIn: applicationWindow().overlay
@@ -40,53 +41,60 @@ QQC2.Dialog {
roomList.currentIndex = 0; roomList.currentIndex = 0;
} }
header: Kirigami.SearchField { background: DialogRoundedBackground {}
id: searchField
Keys.onDownPressed: { contentItem: ColumnLayout {
roomList.forceActiveFocus(); Kirigami.SearchField {
if (roomList.currentIndex < roomList.count - 1) { id: searchField
roomList.currentIndex++; Layout.fillWidth: true
} else { Keys.onDownPressed: {
roomList.currentIndex = 0; roomList.forceActiveFocus();
if (roomList.currentIndex < roomList.count - 1) {
roomList.currentIndex++;
} else {
roomList.currentIndex = 0;
}
} }
} Keys.onUpPressed: {
Keys.onUpPressed: { if (roomList.currentIndex === 0) {
if (roomList.currentIndex === 0) { roomList.currentIndex = roomList.count - 1;
roomList.currentIndex = roomList.count - 1; } else {
} else { roomList.currentIndex--;
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 { QQC2.ScrollView {
anchors.fill: parent clip: true
clip: true
Keys.forwardTo: searchField Layout.fillWidth: true
Layout.fillHeight: true
ListView {
id: roomList
currentIndex: 0
highlightMoveDuration: 200
Keys.forwardTo: searchField Keys.forwardTo: searchField
keyNavigationEnabled: true
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate { ListView {
connection: root.connection id: roomList
onClicked: root.close()
currentIndex: 0
highlightMoveDuration: 200
Keys.forwardTo: searchField
keyNavigationEnabled: true
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate {
connection: root.connection
onClicked: root.close()
showConfigure: false
}
} }
} }
} }

View File

@@ -25,6 +25,8 @@ Delegates.RoundedItemDelegate {
required property string subtitleText required property string subtitleText
required property string displayName required property string displayName
property bool showConfigure: true
property bool collapsed: false property bool collapsed: false
readonly property bool hasNotifications: contextNotificationCount > 0 readonly property bool hasNotifications: contextNotificationCount > 0
@@ -130,7 +132,7 @@ Delegates.RoundedItemDelegate {
QQC2.Button { QQC2.Button {
id: configButton 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") text: i18n("Configure room")
display: QQC2.Button.IconOnly display: QQC2.Button.IconOnly

View File

@@ -29,6 +29,8 @@ Kirigami.Page {
readonly property bool collapsed: Config.collapsed readonly property bool collapsed: Config.collapsed
signal search
onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth
Component.onCompleted: 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 { DelegateChoice {
roleValue: "addDirect" roleValue: "addDirect"
delegate: Delegates.RoundedItemDelegate { delegate: Delegates.RoundedItemDelegate {
@@ -312,6 +298,8 @@ Kirigami.Page {
collapsed: root.collapsed collapsed: root.collapsed
connection: root.connection connection: root.connection
onSearch: root.search()
onTextChanged: newText => { onTextChanged: newText => {
RoomManager.sortFilterRoomTreeModel.filterText = newText; RoomManager.sortFilterRoomTreeModel.filterText = newText;
treeView.expandRecursively(); treeView.expandRecursively();