From 28c965a40d4dc31a2e46a1970d275851b387746e Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 16 Nov 2020 22:45:41 +0000 Subject: [PATCH] Use a page for invitation instead of popup This generally work better on a mobile device --- imports/NeoChat/Dialog/InviteUserDialog.qml | 175 -------------------- imports/NeoChat/Page/InviteUserPage.qml | 134 +++++++++++++++ imports/NeoChat/Page/qmldir | 2 + imports/NeoChat/Panel/RoomDrawer.qml | 11 +- res.qrc | 2 +- 5 files changed, 141 insertions(+), 183 deletions(-) delete mode 100644 imports/NeoChat/Dialog/InviteUserDialog.qml create mode 100644 imports/NeoChat/Page/InviteUserPage.qml diff --git a/imports/NeoChat/Dialog/InviteUserDialog.qml b/imports/NeoChat/Dialog/InviteUserDialog.qml deleted file mode 100644 index c6d34e4e5..000000000 --- a/imports/NeoChat/Dialog/InviteUserDialog.qml +++ /dev/null @@ -1,175 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2019 Black Hat - * - * SPDX-License-Identifier: GPL-3.0-only - */ -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.12 -import org.kde.kirigami 2.13 as Kirigami - -import NeoChat.Component 1.0 -import NeoChat.Effect 1.0 -import NeoChat.Setting 1.0 - -import org.kde.neochat 1.0 - -Dialog { - property var room - - anchors.centerIn: parent - width: 360 - height: Math.min(window.height - 100, 640) - - id: root - - title: "Invite a User" - - contentItem: ColumnLayout { - spacing: 0 - - RowLayout { - Layout.fillWidth: true - - AutoTextField { - property bool isUserID: text.match(/@(.+):(.+)/g) - - Layout.fillWidth: true - - id: identifierField - - placeholderText: "Find a user..." - - onAccepted: { - userDictListModel.search() - } - } - - Button { - visible: identifierField.isUserID - - text: "Add" - highlighted: true - - onClicked: { - room.inviteToRoom(identifierField.text) - } - } - } - - MenuSeparator { - Layout.fillWidth: true - } - - AutoListView { - Layout.fillWidth: true - Layout.fillHeight: true - - id: userDictListView - - clip: true - - spacing: 4 - - model: UserDirectoryListModel { - id: userDictListModel - - connection: root.room.connection - keyword: identifierField.text - } - - delegate: Control { - property bool inRoom: room && room.containsUser(userID) - - width: userDictListView.width - height: 48 - - id: delegate - - padding: 8 - - contentItem: RowLayout { - spacing: 8 - - Kirigami.Avatar { - Layout.preferredWidth: height - Layout.fillHeight: true - - source: author.avatarMediaId ? "image://mxc/" + author.avatarMediaId : "" - name: name - } - - ColumnLayout { - Layout.fillWidth: true - Layout.fillHeight: true - - spacing: 0 - - Label { - Layout.fillWidth: true - Layout.fillHeight: true - - text: name - color: MPalette.foreground - font.pixelSize: 13 - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - - Label { - Layout.fillWidth: true - Layout.fillHeight: true - - text: userID - color: MPalette.lighter - font.pixelSize: 10 - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - } - - Control { - Layout.preferredWidth: 32 - Layout.preferredHeight: 32 - - visible: inRoom - - background: RippleEffect { - circular: true - } - } - - Control { - Layout.preferredWidth: 32 - Layout.preferredHeight: 32 - - visible: !inRoom - - background: RippleEffect { - circular: true - - onClicked: { - room.inviteToRoom(userID) - } - } - } - } - } - - ScrollBar.vertical: ScrollBar {} - - Label { - anchors.centerIn: parent - - visible: userDictListView.count < 1 - - text: "No users available" - color: MPalette.foreground - } - } - } - - onClosed: destroy() -} diff --git a/imports/NeoChat/Page/InviteUserPage.qml b/imports/NeoChat/Page/InviteUserPage.qml new file mode 100644 index 000000000..cb3c9a131 --- /dev/null +++ b/imports/NeoChat/Page/InviteUserPage.qml @@ -0,0 +1,134 @@ +/** + * SPDX-FileCopyrightText: 2019 Black Hat + * + * SPDX-License-Identifier: GPL-3.0-only + */ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import org.kde.kirigami 2.14 as Kirigami + +import org.kde.neochat 1.0 + +Kirigami.ScrollablePage { + id: root + + property var room + + parent: applicationWindow().overlay + + title: i18n("Invite a User") + + actions { + main: Kirigami.Action { + icon.name: "dialog-close" + text: i18nc("@action", "Cancel") + onTriggered: applicationWindow().pageStack.pop() + } + } + header: RowLayout { + Layout.fillWidth: true + Layout.margins: Kirigami.Units.largeSpacing + + Kirigami.SearchField { + id: identifierField + property bool isUserID: text.match(/@(.+):(.+)/g) + Layout.fillWidth: true + + placeholderText: i18n("Find a user...") + onAccepted: userDictListModel.search() + } + + Button { + visible: identifierField.isUserID + + text: i18n("Add") + highlighted: true + + onClicked: { + room.inviteToRoom(identifierField.text) + } + } + } + + ListView { + Layout.fillWidth: true + Layout.fillHeight: true + + id: userDictListView + + clip: true + + model: UserDirectoryListModel { + id: userDictListModel + + connection: root.room.connection + keyword: identifierField.text + } + + Kirigami.PlaceholderMessage { + anchors.centerIn: parent + + visible: userDictListView.count < 1 + + text: i18n("No users available") + } + + delegate: Kirigami.AbstractListItem { + id: delegate + property bool inRoom: room && room.containsUser(userID) + + topPadding: Kirigami.Units.largeSpacing + bottomPadding: Kirigami.Units.largeSpacing + + contentItem: RowLayout { + Kirigami.Avatar { + Layout.preferredWidth: height + Layout.fillHeight: true + + source: avatar ? "image://mxc/" + avatar : "" + name: name + } + + ColumnLayout { + Layout.fillWidth: true + Layout.fillHeight: true + + spacing: 0 + + Kirigami.Heading { + Layout.fillWidth: true + Layout.fillHeight: true + level: 3 + + text: name + textFormat: Text.PlainText + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + + Label { + Layout.fillWidth: true + Layout.fillHeight: true + + text: userID + textFormat: Text.PlainText + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + } + + ToolButton { + visible: !inRoom + icon.name: "document-send" + text: i18n("Send invitation") + + onClicked: { + room.inviteToRoom(userID); + applicationWindow().pageStack.pop(); + } + } + } + } + } +} diff --git a/imports/NeoChat/Page/qmldir b/imports/NeoChat/Page/qmldir index 903053ea7..922a35e79 100644 --- a/imports/NeoChat/Page/qmldir +++ b/imports/NeoChat/Page/qmldir @@ -4,3 +4,5 @@ LoginPage 1.0 LoginPage.qml RoomListPage 1.0 RoomListPage.qml RoomPage 1.0 RoomPage.qml JoinRoomPage 1.0 JoinRoomPage.qml +InviteUserPage 1.0 InviteUserPage.qml + diff --git a/imports/NeoChat/Panel/RoomDrawer.qml b/imports/NeoChat/Panel/RoomDrawer.qml index ad0fb0fa6..554e2726d 100644 --- a/imports/NeoChat/Panel/RoomDrawer.qml +++ b/imports/NeoChat/Panel/RoomDrawer.qml @@ -130,7 +130,10 @@ Kirigami.OverlayDrawer { ToolButton { icon.name: "list-add-user" text: i18n("Invite") - onClicked: inviteUserDialog.createObject(ApplicationWindow.overlay, {"room": room}).open() + onClicked: { + applicationWindow().pageStack.push("qrc:/imports/NeoChat/Page/InviteUserPage.qml", {"room": room}) + roomDrawer.close(); + } } } } @@ -222,10 +225,4 @@ Kirigami.OverlayDrawer { UserDetailDialog {} } - - Component { - id: inviteUserDialog - - InviteUserDialog {} - } } diff --git a/res.qrc b/res.qrc index b0257bf42..485496246 100644 --- a/res.qrc +++ b/res.qrc @@ -10,6 +10,7 @@ imports/NeoChat/Page/RoomPage.qml imports/NeoChat/Page/AccountsPage.qml imports/NeoChat/Page/JoinRoomPage.qml + imports/NeoChat/Page/InviteUserPage.qml imports/NeoChat/Component/qmldir imports/NeoChat/Component/ChatTextInput.qml imports/NeoChat/Component/AutoMouseArea.qml @@ -47,7 +48,6 @@ imports/NeoChat/Dialog/UserDetailDialog.qml imports/NeoChat/Dialog/MessageSourceDialog.qml imports/NeoChat/Dialog/CreateRoomDialog.qml - imports/NeoChat/Dialog/InviteUserDialog.qml imports/NeoChat/Dialog/AcceptInvitationDialog.qml imports/NeoChat/Dialog/StartChatDialog.qml imports/NeoChat/Dialog/FontFamilyDialog.qml