-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
64 lines (48 loc) · 1.53 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mainwindow.h"
#include "client.h"
#include <QTextEdit>
#include <QLineEdit>
#include <QString>
#include <QPushButton>
#include <QBoxLayout>
MainWindow::MainWindow()
{
chatBox = new QTextEdit();
chatBox->setReadOnly(true);
input = new QLineEdit();
connect(input, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
submitButton = new QPushButton("Send...");
connect(submitButton, SIGNAL(clicked()),
this, SLOT(sendMessage()));
ipField = new QLineEdit("127.0.0.1");
connect(ipField, SIGNAL(textChanged(QString)), this, SLOT(connectionChange()));
portField = new QLineEdit("12349");
connect(portField, SIGNAL(textChanged(QString)), this, SLOT(connectionChange()));
setWindowTitle("simpleQtChat");
QVBoxLayout *mainLayout = new QVBoxLayout();
QHBoxLayout *testLayout = new QHBoxLayout();
testLayout->addWidget(ipField);
testLayout->addWidget(portField);
mainLayout->addLayout(testLayout);
mainLayout->addWidget(chatBox);
mainLayout->addWidget(input);
mainLayout->addWidget(submitButton);
setLayout(mainLayout);
}
void MainWindow::sendMessage()
{
QString message(input->text());
emit sendMessage(message);
chatBox->append("Me: " + message);
}
void MainWindow::displayNewMessage(QString message, QString sender) {
QString msg("<b>" + sender + ":</b> ");
msg.append(message);
chatBox->append(msg);
}
void MainWindow::connectionChange() {
emit connectToChanged(ipField->text(), portField->text());
}
MainWindow::~MainWindow()
{
}