From b0bbd3631f6a22357e4bb67e5a5cd5e95bc73df2 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 27 Nov 2020 14:35:21 +0100 Subject: [PATCH] Add Start a chat page --- imports/NeoChat/Component/qmldir | 1 - imports/NeoChat/Dialog/StartChatDialog.qml | 163 --------------------- imports/NeoChat/Page/StartChatPage.qml | 133 +++++++++++++++++ qml/main.qml | 15 +- res.qrc | 2 +- 5 files changed, 145 insertions(+), 169 deletions(-) delete mode 100644 imports/NeoChat/Dialog/StartChatDialog.qml create mode 100644 imports/NeoChat/Page/StartChatPage.qml diff --git a/imports/NeoChat/Component/qmldir b/imports/NeoChat/Component/qmldir index f3ad2e3cd..acb10bad8 100644 --- a/imports/NeoChat/Component/qmldir +++ b/imports/NeoChat/Component/qmldir @@ -1,5 +1,4 @@ module NeoChat.Component AutoMouseArea 1.0 AutoMouseArea.qml -AutoListView 1.0 AutoListView.qml FullScreenImage 1.0 FullScreenImage.qml ChatTextInput 1.0 ChatTextInput.qml diff --git a/imports/NeoChat/Dialog/StartChatDialog.qml b/imports/NeoChat/Dialog/StartChatDialog.qml deleted file mode 100644 index 87d651276..000000000 --- a/imports/NeoChat/Dialog/StartChatDialog.qml +++ /dev/null @@ -1,163 +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.0 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 connection - - anchors.centerIn: parent - width: 360 - height: Math.min(window.height - 100, 640) - - id: root - - title: i18n("Start a Chat") - - contentItem: ColumnLayout { - spacing: 0 - - RowLayout { - Layout.fillWidth: true - - AutoTextField { - property bool isUserID: text.match(/@(.+):(.+)/g) - - Layout.fillWidth: true - - id: identifierField - - placeholderText: i18n("Find a user...") - - onAccepted: { - userDictListModel.search() - } - } - - Button { - visible: identifierField.isUserID - - text: i18n("Chat") - highlighted: true - - onClicked: { - Controller.createDirectChat(connection, 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.connection - keyword: identifierField.text - } - - delegate: Control { - width: userDictListView.width - height: 48 - - padding: 8 - - contentItem: RowLayout { - spacing: 8 - - Kirigami.Avatar { - Layout.preferredWidth: height - Layout.fillHeight: true - - source: avatar - name: name - } - - ColumnLayout { - Layout.fillWidth: true - Layout.fillHeight: true - - spacing: 0 - - Kirigami.Heading { - Layout.fillWidth: true - Layout.fillHeight: true - - text: name - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - - Label { - Layout.fillWidth: true - Layout.fillHeight: true - - text: userID - color: Kirigami.Theme.disabledColor - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - } - - Button { - Layout.preferredWidth: 32 - Layout.preferredHeight: 32 - - visible: directChats != null - - icon.name: "document-send" - onClicked: { - roomListForm.joinRoom(connection.room(directChats[0])) - root.close() - } - } - - Button { - icon.name: "irc-join-channel" - - onClicked: { - Controller.createDirectChat(connection, userID) - root.close() - } - } - } - } - - ScrollBar.vertical: ScrollBar {} - - Label { - anchors.centerIn: parent - - visible: userDictListView.count < 1 - - text: i18n("No users available") - } - } - } - - onClosed: destroy() -} diff --git a/imports/NeoChat/Page/StartChatPage.qml b/imports/NeoChat/Page/StartChatPage.qml new file mode 100644 index 000000000..eb902ac8c --- /dev/null +++ b/imports/NeoChat/Page/StartChatPage.qml @@ -0,0 +1,133 @@ +/** + * SPDX-FileCopyrightText: 2019 Black Hat + * SPDX-FileCopyrightText: 2020 Carl Schwan + * + * 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 NeoChat.Component 1.0 +import NeoChat.Effect 1.0 +import NeoChat.Setting 1.0 + +import org.kde.neochat 1.0 + +Kirigami.ScrollablePage { + id: root + + property var connection + + title: i18n("Start a Chat") + + header: RowLayout { + Layout.fillWidth: true + 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("Chat") + highlighted: true + + onClicked: Controller.createDirectChat(connection, identifierField.text) + } + } + + ListView { + id: userDictListView + + clip: true + + spacing: Kirigami.Units.smallSpacing + + model: UserDirectoryListModel { + id: userDictListModel + + connection: root.connection + keyword: identifierField.text + } + + delegate: Kirigami.AbstractListItem { + width: userDictListView.width + contentItem: RowLayout { + spacing: Kirigami.Units.largeSpacing + + Kirigami.Avatar { + Layout.preferredWidth: height + Layout.fillHeight: true + + source: avatar + name: name + } + + ColumnLayout { + Layout.fillWidth: true + Layout.fillHeight: true + + spacing: 0 + + Kirigami.Heading { + Layout.fillWidth: true + Layout.fillHeight: true + + text: name + textFormat: Text.PlainText + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + + Label { + Layout.fillWidth: true + Layout.fillHeight: true + + text: userID + color: Kirigami.Theme.disabledColor + textFormat: Text.PlainText + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + } + + Button { + Layout.alignment: Qt.AlignRight + visible: directChats != null + + icon.name: "document-send" + onClicked: { + roomListForm.joinRoom(connection.room(directChats[0])) + root.close() + } + } + + Button { + Layout.alignment: Qt.AlignRight + icon.name: "irc-join-channel" + + onClicked: { + Controller.createDirectChat(connection, userID) + root.close() + } + } + } + } + + Kirigami.PlaceholderMessage { + anchors.centerIn: parent + visible: userDictListView.count < 1 + text: i18n("No users available") + } + } +} diff --git a/qml/main.qml b/qml/main.qml index 236497340..f1a4acfb6 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -100,25 +100,32 @@ Kirigami.ApplicationWindow { actions: [ Kirigami.Action { text: i18n("Explore rooms") - iconName: "compass" + icon.name: "compass" onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/JoinRoomPage.qml", {"connection": Controller.activeConnection}) enabled: pageStack.layers.currentItem.title !== i18n("Explore Rooms") }, + Kirigami.Action { + text: i18n("Start a Chat") + icon.name: "irc-join-channel" + onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/StartChatPage.qml", {"connection": Controller.activeConnection}) + + enabled: pageStack.layers.currentItem.title !== i18n("Start a Chat") + }, Kirigami.Action { text: i18n("Accounts") - iconName: "im-user" + icon.name: "im-user" onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/AccountsPage.qml") enabled: pageStack.layers.currentItem.title !== i18n("Accounts") }, Kirigami.Action { text: i18n("Settings") - iconName: "settings-configure" + icon.name: "settings-configure" onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/SettingsPage.qml") enabled: pageStack.layers.currentItem.title !== i18n("Settings") }, Kirigami.Action { text: i18n("About Neochat") - iconName: "help-about" + icon.name: "help-about" onTriggered: pushReplaceLayer(aboutPage) enabled: pageStack.layers.currentItem.title !== i18n("About") } diff --git a/res.qrc b/res.qrc index 8680b7963..bb33381e9 100644 --- a/res.qrc +++ b/res.qrc @@ -13,6 +13,7 @@ imports/NeoChat/Page/InviteUserPage.qml imports/NeoChat/Page/SettingsPage.qml imports/NeoChat/Page/InvitationPage.qml + imports/NeoChat/Page/StartChatPage.qml imports/NeoChat/Component/qmldir imports/NeoChat/Component/ChatTextInput.qml imports/NeoChat/Component/AutoMouseArea.qml @@ -44,7 +45,6 @@ imports/NeoChat/Dialog/RoomSettingsDialog.qml imports/NeoChat/Dialog/UserDetailDialog.qml imports/NeoChat/Dialog/CreateRoomDialog.qml - imports/NeoChat/Dialog/StartChatDialog.qml imports/NeoChat/Dialog/EmojiDialog.qml imports/NeoChat/Dialog/OpenFileDialog.qml imports/NeoChat/Dialog/OpenFolderDialog.qml