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.
*/
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");
}

View File

@@ -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");
}

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
}
}
}
}

View File

@@ -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

View File

@@ -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();