From da8227931faec5fde8962182f7044e0a303633b8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 12 Jul 2023 13:26:25 +0200 Subject: [PATCH] Remove duplicated code in QuickSwitcher for RoomDelegate --- src/qml/Component/QuickSwitcher.qml | 43 ++++++-------------------- src/qml/Page/RoomList/Page.qml | 9 ++++++ src/qml/Page/RoomList/RoomDelegate.qml | 8 ----- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/qml/Component/QuickSwitcher.qml b/src/qml/Component/QuickSwitcher.qml index 95367e535..f6fb556c3 100644 --- a/src/qml/Component/QuickSwitcher.qml +++ b/src/qml/Component/QuickSwitcher.qml @@ -6,9 +6,11 @@ import QtQuick.Controls 2.15 as QQC2 import QtQuick.Layouts 1.15 import org.kde.kirigami 2.20 as Kirigami +import org.kde.kirigamiaddons.delegates 1.0 as Delegates import org.kde.kitemmodels 1.0 import org.kde.neochat 1.0 +import './RoomList' as RoomList QQC2.Dialog { id: root @@ -86,48 +88,23 @@ QQC2.Dialog { connection: Controller.activeConnection } } - delegate: Kirigami.BasicListItem { - id: roomListItem - required property NeoChatRoom currentRoom - required property string displayName - required property int index - required property int notificationCount - required property string subtitleText - required property string avatar + delegate: RoomList.RoomDelegate { + filterText: searchField.text - topPadding: Kirigami.Units.largeSpacing - bottomPadding: Kirigami.Units.largeSpacing - highlighted: roomList.currentIndex === roomListItem.index - focus: true - icon: undefined onClicked: { - RoomManager.enterRoom(roomListItem.currentRoom); + RoomManager.enterRoom(currentRoom); root.close() } + Keys.onEnterPressed: { - RoomManager.enterRoom(roomListItem.currentRoom); + RoomManager.enterRoom(currentRoom); root.close(); } - Keys.onReturnPressed: { - RoomManager.enterRoom(roomListItem.currentRoom); - root.close(); - } - @BASICLISTITEM_BOLD@: roomListItem.notificationCount > 0 - label: roomListItem.displayName ?? "" - labelItem.textFormat: Text.PlainText - subtitle: roomListItem.subtitleText - subtitleItem.textFormat: Text.PlainText - onPressAndHold: { - createRoomListContextMenu() - } - leading: Kirigami.Avatar { - source: roomListItem.avatar ? "image://mxc/" + roomListItem.avatar : "" - name: roomListItem.displayName - implicitWidth: height - sourceSize.width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2 - sourceSize.height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2 + Keys.onReturnPressed: { + RoomManager.enterRoom(currentRoom); + root.close(); } } } diff --git a/src/qml/Page/RoomList/Page.qml b/src/qml/Page/RoomList/Page.qml index 7c33a350c..a73dbc2b2 100644 --- a/src/qml/Page/RoomList/Page.qml +++ b/src/qml/Page/RoomList/Page.qml @@ -240,6 +240,15 @@ Kirigami.Page { RoomList.RoomDelegate { filterText: sortFilterRoomListModel.filterText + + height: visible ? implicitHeight : 0 + + visible: categoryVisible || filterText.length > 0 || Config.mergeRoomList + + onClicked: RoomManager.enterRoom(currentRoom) + + Keys.onEnterPressed: RoomManager.enterRoom(currentRoom) + Keys.onReturnPressed: RoomManager.enterRoom(currentRoom) } } } diff --git a/src/qml/Page/RoomList/RoomDelegate.qml b/src/qml/Page/RoomList/RoomDelegate.qml index b26a5a1c6..dab851d80 100644 --- a/src/qml/Page/RoomList/RoomDelegate.qml +++ b/src/qml/Page/RoomList/RoomDelegate.qml @@ -30,16 +30,8 @@ Delegates.RoundedItemDelegate { readonly property bool hasNotifications: notificationCount > 0 - height: visible ? implicitHeight : 0 - - visible: root.categoryVisible || root.filterText.length > 0 || Config.mergeRoomList - - onClicked: RoomManager.enterRoom(root.currentRoom) onPressAndHold: createRoomListContextMenu() - Keys.onEnterPressed: RoomManager.enterRoom(root.currentRoom) - Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom) - TapHandler { acceptedButtons: Qt.RightButton acceptedDevices: PointerDevice.Mouse