Created conversation widget.

This commit is contained in:
Pierre HUBERT 2018-12-11 21:03:05 +01:00 committed by Pierre HUBERT
parent 2b5cd7d86b
commit a0eaf69c0e
7 changed files with 189 additions and 5 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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 <QWidget>
#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

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConversationWidget</class>
<widget class="QWidget" name="ConversationWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="convName">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Conversation name</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="messageContentInput">
<property name="maxLength">
<number>200</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="sendMessageButton">
<property name="text">
<string>Send</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,11 +1,13 @@
#include <QMessageBox>
#include <QPushButton>
#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();

View File

@ -9,12 +9,16 @@
#include <QMainWindow>
#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();

View File

@ -25,13 +25,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<width>772</width>
<height>536</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="conversationsContainerLayout"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">