From 07f637c854f24647c4c6ea9e1b98f8b00454f099 Mon Sep 17 00:00:00 2001 From: Carson Black Date: Wed, 2 Dec 2020 15:54:45 -0500 Subject: [PATCH] Improve appearance of room listing This ports the room list delegates to Kirigami.BasicListItem leading/trailing for a more consistent appearance with other applications, and adjusts how their context menus look and behave --- CMakeLists.txt | 2 +- imports/NeoChat/Menu/RoomListContextMenu.qml | 8 +- imports/NeoChat/Page/RoomListPage.qml | 99 +++++++------------- 3 files changed, 39 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7b748a41..ab3a8029d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1) project(Neochat) -set(KF5_MIN_VERSION "5.76.0") +set(KF5_MIN_VERSION "5.77.0") set(QT_MIN_VERSION "5.15.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) diff --git a/imports/NeoChat/Menu/RoomListContextMenu.qml b/imports/NeoChat/Menu/RoomListContextMenu.qml index f6d5063e2..4d2263e6d 100644 --- a/imports/NeoChat/Menu/RoomListContextMenu.qml +++ b/imports/NeoChat/Menu/RoomListContextMenu.qml @@ -16,17 +16,13 @@ Menu { property var room MenuItem { - text: i18n("Favourite") - checkable: true - checked: room.isFavourite + text: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites") onTriggered: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0) } MenuItem { - text: i18n("Deprioritize") - checkable: true - checked: room.isLowPriority + text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize") onTriggered: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0) } diff --git a/imports/NeoChat/Page/RoomListPage.qml b/imports/NeoChat/Page/RoomListPage.qml index e615433e8..9a38a4263 100644 --- a/imports/NeoChat/Page/RoomListPage.qml +++ b/imports/NeoChat/Page/RoomListPage.qml @@ -88,12 +88,11 @@ Kirigami.ScrollablePage { } } - delegate: Kirigami.AbstractListItem { + delegate: Kirigami.BasicListItem { id: roomListItem - property bool itemVisible: model.categoryVisible || sortFilterRoomListModel.filterText.length > 0 || Config.mergeRoomList - visible: itemVisible - highlighted: roomManager.currentRoom && roomManager.currentRoom.displayName === displayName + visible: model.categoryVisible || sortFilterRoomListModel.filterText.length > 0 || Config.mergeRoomList focus: true + icon: undefined action: Kirigami.Action { id: enterRoomAction onTriggered: { @@ -107,68 +106,22 @@ Kirigami.ScrollablePage { } } - - contentItem: RowLayout { - id: roomLayout - spacing: Kirigami.Units.largeSpacing - width: listView.width - - TapHandler { - acceptedButtons: Qt.RightButton - gesturePolicy: TapHandler.ReleaseWithinBounds - onTapped: roomListContextMenu.createObject(roomLayout, {"room": currentRoom}).popup() + label: name ?? "" + subtitle: { + let txt = (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ") + if (txt.length) { + return txt } + return " " + } - TapHandler { - onTapped: enterRoomAction.trigger() - onLongPressed: roomListContextMenu.createObject(roomLayout, {"room": currentRoom}).popup() - } + leading: Kirigami.Avatar { + source: avatar ? "image://mxc/" + avatar : "" + name: model.name || i18n("No Name") + implicitWidth: height + } - Kirigami.Avatar { - id: roomAvatar - property int size: Kirigami.Units.gridUnit * 2 + Kirigami.Units.smallSpacing - Layout.minimumHeight: size - Layout.maximumHeight: size - Layout.minimumWidth: size - Layout.maximumWidth: size - - source: avatar ? ("image://mxc/" + avatar) : "" - name: model.name || i18n("No Name") - } - - ColumnLayout { - id: roomitemcolumn - Layout.fillWidth: true - Layout.fillHeight: true - Layout.minimumHeight: Kirigami.Units.gridUnit * 2 - Layout.maximumHeight: Kirigami.Units.gridUnit * 2 - Layout.topMargin: Kirigami.Units.smallSpacing - Layout.bottomMargin: Kirigami.Units.smallSpacing - Layout.alignment: Qt.AlignHCenter - - spacing: Kirigami.Units.smallSpacing - - QQC2.Label { - Layout.fillWidth: true - Layout.fillHeight: true - text: displayName ?? "" - elide: Text.ElideRight - font.bold: unreadCount >= 0 || highlightCount > 0 || notificationCount > 0 - wrapMode: Text.NoWrap - } - - QQC2.Label { - Layout.fillWidth: true - Layout.fillHeight: true - Layout.alignment: Qt.AlignHCenter - - text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ") - visible: text.length > 0 - elide: Text.ElideRight - wrapMode: Text.NoWrap - color: Qt.rgba(Kirigami.Theme.textColor.r, Kirigami.Theme.textColor.g, Kirigami.Theme.textColor.b, 0.7) - } - } + trailing: RowLayout { QQC2.Label { text: notificationCount visible: notificationCount > 0 @@ -182,6 +135,26 @@ Kirigami.ScrollablePage { radius: height / 2 } } + QQC2.Button { + id: configButton + visible: roomListItem.hovered || Kirigami.Settings.isMobile + Accessible.name: i18n("Configure room") + + action: Kirigami.Action { + id: optionAction + icon.name: "configure" + onTriggered: { + const menu = roomListContextMenu.createObject(page, {"room": currentRoom}) + configButton.visible = true + configButton.down = true + menu.closed.connect(function() { + configButton.down = undefined + configButton.visible = Qt.binding(function() { return roomListItem.hovered || Kirigami.Settings.isMobile }) + }) + menu.popup() + } + } + } } } Component {