-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Force-quit/rc/v1.0.0
Rc/v1.0.0
- Loading branch information
Showing
19 changed files
with
351 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "QChatWidget.h" | ||
#include <QVBoxLayout> | ||
#include <QHBoxLayout> | ||
#include <QPushButton> | ||
#include <QGroupBox> | ||
#include <QLineEdit> | ||
|
||
QChatWidget::QChatWidget(QWidget *parent, const QClientInfo& clientInfo) | ||
: QWidget(parent), chatBox{ new QChatbox(this) }, textInput{ new QLineEdit(this) }, clientInfo(clientInfo) | ||
{ | ||
QSizePolicy modifiedPolicy{ sizePolicy() }; | ||
modifiedPolicy.setHorizontalStretch(2); | ||
setSizePolicy(modifiedPolicy); | ||
|
||
QVBoxLayout* mainLayout{ new QVBoxLayout }; | ||
|
||
QGroupBox* chatBoxGroupBox{ new QGroupBox("Chat") }; | ||
QVBoxLayout* chatBoxGroupBoxLayout{ new QVBoxLayout }; | ||
chatBoxGroupBoxLayout->addWidget(chatBox); | ||
chatBoxGroupBox->setLayout(chatBoxGroupBoxLayout); | ||
|
||
QHBoxLayout* textInputLayout{ new QHBoxLayout }; | ||
QPushButton* sendMessageButton{ new QPushButton("Send", this) }; | ||
textInputLayout->addWidget(textInput); | ||
textInputLayout->addWidget(sendMessageButton); | ||
|
||
mainLayout->addWidget(chatBoxGroupBox); | ||
mainLayout->addLayout(textInputLayout); | ||
setLayout(mainLayout); | ||
|
||
connect(this, &QChatWidget::appendSystemMessage, chatBox, &QChatbox::appendSystemMessage); | ||
connect(this, &QChatWidget::appendUserMessage, chatBox, &QChatbox::appendUserMessage); | ||
connect(this, &QChatWidget::appendServerMessage, chatBox, &QChatbox::appendServerMessage); | ||
|
||
connect(sendMessageButton, &QPushButton::clicked, textInput, &QLineEdit::returnPressed); | ||
connect(textInput, &QLineEdit::returnPressed, this, &QChatWidget::handleReturnPressed); | ||
} | ||
|
||
void QChatWidget::handleReturnPressed() | ||
{ | ||
QString currentText(textInput->text().simplified()); | ||
if (!currentText.isEmpty()) | ||
{ | ||
appendUserMessage(clientInfo.getUsername(), currentText); | ||
emit sendMessage(currentText); | ||
} | ||
textInput->clear(); | ||
} | ||
|
||
void QChatWidget::clearMessages() | ||
{ | ||
chatBox->clear(); | ||
} | ||
|
||
QChatWidget::~QChatWidget() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <QWidget> | ||
#include "QChatbox.h" | ||
#include <QLineEdit> | ||
#include "../QClientInfo.h" | ||
|
||
class QChatWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QChatWidget(QWidget* parent, const QClientInfo& clientInfo); | ||
~QChatWidget(); | ||
|
||
void clearMessages(); | ||
|
||
signals: | ||
void appendUserMessage(const QString& from, const QString& message); | ||
void appendSystemMessage(const QString message); | ||
void appendServerMessage(const QString message); | ||
void sendMessage(const QString& message); | ||
|
||
private slots: | ||
void handleReturnPressed(); | ||
|
||
private: | ||
QChatbox* chatBox; | ||
QLineEdit* textInput; | ||
const QClientInfo& clientInfo; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.