From edf8530e5786162a20dcdc93501c565089ab8fd1 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 3 Nov 2020 14:44:58 +0100 Subject: [PATCH] Add minimal room management --- .../Menu => qml}/RoomListContextMenu.qml | 23 +++-- qml/RoomListPage.qml | 97 +++++++++++-------- qml/main.qml | 3 +- res.qrc | 2 +- 4 files changed, 72 insertions(+), 53 deletions(-) rename {imports/Spectral/Menu => qml}/RoomListContextMenu.qml (63%) diff --git a/imports/Spectral/Menu/RoomListContextMenu.qml b/qml/RoomListContextMenu.qml similarity index 63% rename from imports/Spectral/Menu/RoomListContextMenu.qml rename to qml/RoomListContextMenu.qml index b44903e86..79a6226e7 100644 --- a/imports/Spectral/Menu/RoomListContextMenu.qml +++ b/qml/RoomListContextMenu.qml @@ -1,14 +1,21 @@ +/** + * SPDX-FileCopyrightText: 2019 Black Hat + * SPDX-FileCopyrightText: 2020 Carl Schwan + * + * SPDX-LicenseIdentifier: GPL-3.0-only + */ import QtQuick 2.12 import QtQuick.Controls 2.12 -import QtQuick.Controls.Material 2.12 +/** + * Context menu when clicking on a room in the room list + */ Menu { + id: root property var room - id: root - MenuItem { - text: "Favourite" + text: i18n("Favourite") checkable: true checked: room.isFavourite @@ -16,7 +23,7 @@ Menu { } MenuItem { - text: "Deprioritize" + text: i18n("Deprioritize") checkable: true checked: room.isLowPriority @@ -26,15 +33,13 @@ Menu { MenuSeparator {} MenuItem { - text: "Mark as Read" + text: i18n("Mark as Read") onTriggered: room.markAllMessagesAsRead() } MenuItem { - text: "Leave Room" - Material.foreground: Material.Red - + text: i18n("Leave Room") onTriggered: room.forget() } diff --git a/qml/RoomListPage.qml b/qml/RoomListPage.qml index 3631ef8db..2de9a1cdf 100644 --- a/qml/RoomListPage.qml +++ b/qml/RoomListPage.qml @@ -37,8 +37,6 @@ Kirigami.ScrollablePage { } ListView { - id: messageListView - model: KSortFilterProxyModel { id: sortedFilteredRoomListModel sourceModel: roomListModel @@ -59,56 +57,73 @@ Kirigami.ScrollablePage { topPadding: Kirigami.Units.largeSpacing bottomPadding: Kirigami.Units.largeSpacing - contentItem: RowLayout { - spacing: Kirigami.Units.largeSpacing + contentItem: Item { + implicitHeight: roomLayout.implicitHeight + RowLayout { + id: roomLayout + spacing: Kirigami.Units.largeSpacing + anchors.fill: parent - Kirigami.Avatar { - Layout.preferredWidth: height - Layout.fillHeight: true - - source: avatar ? "image://mxc/" + avatar : "" - name: model.name || "No Name" - } - - ColumnLayout { - Layout.fillWidth: true - Layout.fillHeight: true - Layout.alignment: Qt.AlignHCenter - - spacing: Kirigami.Units.smallSpacing - - QQC2.Label { - Layout.fillWidth: true + Kirigami.Avatar { + Layout.preferredWidth: height Layout.fillHeight: true - text: name ?? "" - font.pixelSize: 15 - font.bold: unreadCount >= 0 - elide: Text.ElideRight - wrapMode: Text.NoWrap + + source: avatar ? "image://mxc/" + avatar : "" + name: model.name || i18n("No Name") } - QQC2.Label { + ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true Layout.alignment: Qt.AlignHCenter - text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ") - font.pixelSize: 12 - elide: Text.ElideRight - wrapMode: Text.NoWrap + spacing: Kirigami.Units.smallSpacing + + QQC2.Label { + Layout.fillWidth: true + Layout.fillHeight: true + text: name ?? "" + font.pixelSize: 15 + font.bold: unreadCount >= 0 + elide: Text.ElideRight + 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," ") + font.pixelSize: 12 + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + } + } + MouseArea { + acceptedButtons: Qt.LeftButton | Qt.RightButton + anchors.fill: parent + onClicked: { + console.log(mouse.button) + if (mouse.button == Qt.RightButton) { + roomListContextMenu.createObject(parent, {"room": currentRoom}).popup() + } else { + if (enteredRoom) { + leaveRoom(enteredRoom) + } + + enteredRoom = currentRoom + + enterRoom(enteredRoom) + } } } } - - onClicked: { - if (enteredRoom) { - leaveRoom(enteredRoom) - } - - enteredRoom = currentRoom - - enterRoom(enteredRoom) - } + } + Component { + id: roomListContextMenu + RoomListContextMenu {} } } } diff --git a/qml/main.qml b/qml/main.qml index e3f47d052..acfad5010 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -12,7 +12,6 @@ import org.kde.kirigami 2.12 as Kirigami import Spectral 0.1 import Spectral.Component 2.0 -import Spectral.Dialog 2.0 import Spectral.Panel 2.0 Kirigami.ApplicationWindow { @@ -21,7 +20,7 @@ Kirigami.ApplicationWindow { contextDrawer: RoomDrawer { id: contextDrawer - enabled: roomList.enteredRoom !== null + enabled: root.currentRoomm !== null room: root.currentRoom handleVisible: enabled && (pageStack.currentItem instanceof RoomPage) } diff --git a/res.qrc b/res.qrc index 4ba5baf01..37269067f 100644 --- a/res.qrc +++ b/res.qrc @@ -6,6 +6,7 @@ qml/RoomListPage.qml qml/RoomPage.qml qml/ChatTextInput.qml + qml/RoomListContextMenu.qml imports/Spectral/Component/Emoji/EmojiPicker.qml imports/Spectral/Component/Emoji/qmldir imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -45,7 +46,6 @@ imports/Spectral/Dialog/InviteUserDialog.qml imports/Spectral/Dialog/AcceptInvitationDialog.qml imports/Spectral/Menu/qmldir - imports/Spectral/Menu/RoomListContextMenu.qml imports/Spectral/Menu/Timeline/qmldir imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml