From a0eaf69c0e92601a035111ab170c3ce988c3e204 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 11 Dec 2018 21:03:05 +0100 Subject: [PATCH] Created conversation widget. --- ComunicMessages.pro | 9 +++-- widgets/conversationwidget.cpp | 36 +++++++++++++++++++ widgets/conversationwidget.h | 51 ++++++++++++++++++++++++++ widgets/conversationwidget.ui | 65 ++++++++++++++++++++++++++++++++++ widgets/mainwindow.cpp | 14 +++++++- widgets/mainwindow.h | 14 ++++++++ widgets/mainwindow.ui | 5 ++- 7 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 widgets/conversationwidget.cpp create mode 100644 widgets/conversationwidget.h create mode 100644 widgets/conversationwidget.ui diff --git a/ComunicMessages.pro b/ComunicMessages.pro index 7fc6188..5723ac6 100644 --- a/ComunicMessages.pro +++ b/ComunicMessages.pro @@ -25,7 +25,8 @@ SOURCES += \ data/conversationslist.cpp \ utils/uiutils.cpp \ data/userslist.cpp \ - utils/timeutils.cpp + utils/timeutils.cpp \ + widgets/conversationwidget.cpp HEADERS += \ helpers/accounthelper.h \ @@ -52,13 +53,15 @@ HEADERS += \ data/conversationslist.h \ utils/uiutils.h \ data/userslist.h \ - utils/timeutils.h + utils/timeutils.h \ + widgets/conversationwidget.h FORMS += \ widgets/loginwidget.ui \ widgets/mainwindow.ui \ widgets/aboutthisappdialog.ui \ - widgets/conversationitemwidget.ui + widgets/conversationitemwidget.ui \ + widgets/conversationwidget.ui RESOURCES += \ res/ressources.qrc diff --git a/widgets/conversationwidget.cpp b/widgets/conversationwidget.cpp new file mode 100644 index 0000000..148864a --- /dev/null +++ b/widgets/conversationwidget.cpp @@ -0,0 +1,36 @@ +#include "conversationwidget.h" +#include "ui_conversationwidget.h" +#include "../helpers/conversationslisthelper.h" + +ConversationWidget::ConversationWidget(const Conversation &conversation, const UsersList &list, QWidget *parent) : + QWidget(parent), + ui(new Ui::ConversationWidget), + mConversation(conversation), + mUsersList(list) +{ + ui->setupUi(this); + + //Initialize UI + QString convTitle = ConversationsListHelper::getConversationDisplayName(conversation, list); + ui->convName->setText(convTitle); +} + +ConversationWidget::~ConversationWidget() +{ + delete ui; +} + +void ConversationWidget::sendMessage() +{ + qWarning("Send a new message"); +} + +void ConversationWidget::on_sendMessageButton_clicked() +{ + sendMessage(); +} + +void ConversationWidget::on_messageContentInput_returnPressed() +{ + sendMessage(); +} diff --git a/widgets/conversationwidget.h b/widgets/conversationwidget.h new file mode 100644 index 0000000..a75209d --- /dev/null +++ b/widgets/conversationwidget.h @@ -0,0 +1,51 @@ +/** + * Conversation widget + * + * Allows to display all the components + * of a single conversation + * + * @author Pierre HUBERT + */ +#ifndef CONVERSATIONWIDGET_H +#define CONVERSATIONWIDGET_H + +#include + +#include "../data/conversation.h" +#include "../data/userslist.h" + +namespace Ui { +class ConversationWidget; +} + +class ConversationWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ConversationWidget(const Conversation &conversation, const UsersList &list, QWidget *parent = nullptr); + ~ConversationWidget(); + +public slots: + + /** + * Send the message entered by the user in the form + */ + void sendMessage(); + + + +private slots: + void on_sendMessageButton_clicked(); + + void on_messageContentInput_returnPressed(); + +private: + + //Private fields + Ui::ConversationWidget *ui; + Conversation mConversation; + UsersList mUsersList; +}; + +#endif // CONVERSATIONWIDGET_H diff --git a/widgets/conversationwidget.ui b/widgets/conversationwidget.ui new file mode 100644 index 0000000..91f4e76 --- /dev/null +++ b/widgets/conversationwidget.ui @@ -0,0 +1,65 @@ + + + ConversationWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + 75 + true + + + + Conversation name + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 200 + + + + + + + Send + + + + + + + + + + diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index ec15ba8..eeddfe1 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -1,11 +1,13 @@ #include +#include #include "mainwindow.h" #include "ui_mainwindow.h" #include "aboutthisappdialog.h" #include "loginwidget.h" #include "conversationslistwidget.h" - +#include "conversationwidget.h" +#include "../utils/uiutils.h" #include "../helpers/accounthelper.h" MainWindow::MainWindow(QWidget *parent) : @@ -18,6 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : mConversationsListWidget = new ConversationsListWidget; mConversationsListWidget->refresh(); ui->conversationsListArea->setWidget(mConversationsListWidget); + connect(mConversationsListWidget, &ConversationsListWidget::openConversation, this, &MainWindow::openConversation); } MainWindow::~MainWindow() @@ -25,6 +28,15 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::openConversation(Conversation conversation, UsersList list) +{ + //Remove any previous conversation + UiUtils::emptyLayout(ui->conversationsContainerLayout); + qWarning("Open conversation"); + ConversationWidget *widget = new ConversationWidget(conversation, list); + ui->conversationsContainerLayout->addWidget(widget); +} + void MainWindow::on_actionAbout_Qt_triggered() { QApplication::aboutQt(); diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h index 4d626d7..ff2654b 100644 --- a/widgets/mainwindow.h +++ b/widgets/mainwindow.h @@ -9,12 +9,16 @@ #include +#include "../data/conversation.h" +#include "../data/userslist.h" + namespace Ui { class MainWindow; } class ConversationsListWidget; + class MainWindow : public QMainWindow { Q_OBJECT @@ -24,6 +28,16 @@ public: ~MainWindow(); private slots: + + /** + * Request a conversation to be opened + * + * @param conversation Information about the conversation + * to open + * @param list Information about the users + */ + void openConversation(Conversation conversation, UsersList list); + void on_actionAbout_Qt_triggered(); void on_actionAbout_this_App_triggered(); diff --git a/widgets/mainwindow.ui b/widgets/mainwindow.ui index 31284c2..861df58 100644 --- a/widgets/mainwindow.ui +++ b/widgets/mainwindow.ui @@ -25,13 +25,16 @@ 0 0 - 780 + 772 536 + + +