From 3c4eff0759a43de0879a9ed850e851327f0d1945 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 2 Nov 2020 21:31:11 +0100 Subject: [PATCH] Move major pages to the qml directory --- .../ChatTextInput.qml | 0 qml/RoomListPage.qml | 114 ++++++++++++++++++ .../Panel/RoomPanel.qml => qml/RoomPage.qml | 20 +-- qml/main.qml | 13 +- res.qrc | 6 +- 5 files changed, 137 insertions(+), 16 deletions(-) rename imports/Spectral/Panel/RoomPanelInput.qml => qml/ChatTextInput.qml (100%) create mode 100644 qml/RoomListPage.qml rename imports/Spectral/Panel/RoomPanel.qml => qml/RoomPage.qml (96%) diff --git a/imports/Spectral/Panel/RoomPanelInput.qml b/qml/ChatTextInput.qml similarity index 100% rename from imports/Spectral/Panel/RoomPanelInput.qml rename to qml/ChatTextInput.qml diff --git a/qml/RoomListPage.qml b/qml/RoomListPage.qml new file mode 100644 index 000000000..3631ef8db --- /dev/null +++ b/qml/RoomListPage.qml @@ -0,0 +1,114 @@ +/** + * 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 as QQC2 +import QtQuick.Layouts 1.12 + +import org.kde.kirigami 2.13 as Kirigami + +import org.kde.kitemmodels 1.0 +import Spectral.Component 2.0 +import Spectral 0.1 + +Kirigami.ScrollablePage { + id: page + + property var roomListModel + property var enteredRoom + property var searchText: "" + + onSearchTextChanged: sortedFilteredRoomListModel.invalidateFilter() + + signal enterRoom(var room) + signal leaveRoom(var room) + + title: i18n("Rooms") + + titleDelegate: Kirigami.SearchField { + Layout.topMargin: Kirigami.Units.smallSpacing + Layout.bottomMargin: Kirigami.Units.smallSpacing + Layout.fillHeight: true + Layout.fillWidth: true + onTextChanged: page.searchText = text + } + + ListView { + id: messageListView + + model: KSortFilterProxyModel { + id: sortedFilteredRoomListModel + sourceModel: roomListModel + + sortRole: "name" + sortOrder: Qt.AscendingOrder + filterRowCallback: function(row, parent) { + return (roomListModel.data(roomListModel.index(row, 0), RoomListModel.JoinStateRole) !== "upgraded") && roomListModel.data(roomListModel.index(row, 0), RoomListModel.NameRole).toLowerCase().includes(page.searchText.toLowerCase()) + } + } + + section.property: "categoryName" + section.delegate: Kirigami.ListSectionHeader { + label: section + } + + delegate: Kirigami.AbstractListItem { + topPadding: Kirigami.Units.largeSpacing + bottomPadding: Kirigami.Units.largeSpacing + + contentItem: RowLayout { + spacing: Kirigami.Units.largeSpacing + + 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 + 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 + } + } + } + + onClicked: { + if (enteredRoom) { + leaveRoom(enteredRoom) + } + + enteredRoom = currentRoom + + enterRoom(enteredRoom) + } + } + } +} diff --git a/imports/Spectral/Panel/RoomPanel.qml b/qml/RoomPage.qml similarity index 96% rename from imports/Spectral/Panel/RoomPanel.qml rename to qml/RoomPage.qml index 4440e309f..36d0b3d14 100644 --- a/imports/Spectral/Panel/RoomPanel.qml +++ b/qml/RoomPage.qml @@ -15,18 +15,18 @@ import Spectral.Effect 2.0 import Spectral 0.1 Kirigami.ScrollablePage { - property var currentRoom - id: page - title: "Messages" + property var currentRoom + + title: i18n("Messages") MessageEventModel { id: messageEventModel room: currentRoom } - + ImageClipboard { id: imageClipboard } @@ -45,7 +45,7 @@ Kirigami.ScrollablePage { icon.name: 'mail-attachment' - text: "Choose local file" + text: i18n("Choose local file") onClicked: { attachDialog.close() @@ -55,7 +55,7 @@ Kirigami.ScrollablePage { fileDialog.chosen.connect(function(path) { if (!path) return - roomPanelInput.attach(path) + chatTextInput.attach(path) }) fileDialog.open() @@ -71,11 +71,11 @@ Kirigami.ScrollablePage { padding: 16 icon.name: 'insert-image' - text: "Clipboard image" + text: i18n("Clipboard image") onClicked: { var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png" if (!imageClipboard.saveImage(localPath)) return - roomPanelInput.attach(localPath) + chatTextInput.attach(localPath) attachDialog.close() } } @@ -289,8 +289,8 @@ Kirigami.ScrollablePage { } } - footer: RoomPanelInput { - id: roomPanelInput + footer: ChatTextInput { + id: chatTextInput Layout.fillWidth: true } diff --git a/qml/main.qml b/qml/main.qml index 73004f4ba..e3f47d052 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -1,3 +1,9 @@ +/** + * SPDX-FileCopyrightText: 2019 Black Hat + * SPDX-FileCopyrightText: 2020 Carl Schwan + * + * SPDX-LicenseIdentifier: GPL-3.0-only + */ import QtQuick 2.14 import QtQuick.Controls 2.14 as Controls import QtQuick.Layouts 1.14 @@ -17,20 +23,20 @@ Kirigami.ApplicationWindow { id: contextDrawer enabled: roomList.enteredRoom !== null room: root.currentRoom + handleVisible: enabled && (pageStack.currentItem instanceof RoomPage) } pageStack.initialPage: LoadingPage {} Component { id: roomListComponent - RoomListPanel { + RoomListPage { id: roomList roomListModel: spectralRoomListModel onEnterRoom: { applicationWindow().pageStack.push(roomPanelComponent, {"currentRoom": room}); root.currentRoom = room; - } onLeaveRoom: { var stack = applicationWindow().pageStack; @@ -49,6 +55,7 @@ Kirigami.ApplicationWindow { onErrorOccured: showPassiveNotification(error + ": " + detail) onInitiated: { + if (spectralController.accountCount === 0) { pageStack.replace("qrc:/qml/LoginPage.qml", { 'spectralController': spectralController @@ -81,7 +88,7 @@ Kirigami.ApplicationWindow { Component { id: roomPanelComponent - RoomPanel { + RoomPage { currentRoom: root.currentRoom } } diff --git a/res.qrc b/res.qrc index f05e9f989..4ba5baf01 100644 --- a/res.qrc +++ b/res.qrc @@ -3,6 +3,9 @@ qml/main.qml qml/LoginPage.qml qml/LoadingPage.qml + qml/RoomListPage.qml + qml/RoomPage.qml + qml/ChatTextInput.qml imports/Spectral/Component/Emoji/EmojiPicker.qml imports/Spectral/Component/Emoji/qmldir imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -20,14 +23,11 @@ imports/Spectral/Setting/qmldir imports/Spectral/Panel/qmldir imports/Spectral/Panel/RoomDrawer.qml - imports/Spectral/Panel/RoomListPanel.qml - imports/Spectral/Panel/RoomPanel.qml imports/Spectral/Panel/RoomHeader.qml imports/Spectral/Panel/SpectralSidebar.qml imports/Spectral/Component/ScrollHelper.qml imports/Spectral/Component/AutoListView.qml imports/Spectral/Component/AutoTextField.qml - imports/Spectral/Panel/RoomPanelInput.qml imports/Spectral/Component/Timeline/SectionDelegate.qml assets/img/matrix.svg imports/Spectral/Effect/RippleEffect.qml