-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchatwindow.cpp
More file actions
executable file
·65 lines (57 loc) · 1.71 KB
/
chatwindow.cpp
File metadata and controls
executable file
·65 lines (57 loc) · 1.71 KB
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
65
#include "chatwindow.h"
#include "ui_chatwindow.h"
#include<QDebug>
/*
ChatWindow::ChatWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ChatWindow)
{
ui->setupUi(this);
}
*/
ChatWindow::ChatWindow(MainWindow*mainWins,UsrInfo*myInfo,UsrInfo*otherInfo,UdpServer*udpServer,QWidget *parent):
QMainWindow(parent),
ui(new Ui::ChatWindow),
myInfo(myInfo),
otherInfo(otherInfo),
udpServer(udpServer)
{
ui->setupUi(this);
this->mainWins=mainWins;
ui->label->setText(otherInfo->getNick()+'('+QString::number(otherInfo->getId())+')');
}
ChatWindow::ChatWindow(MainWindow*mainWins,unsigned int myId, unsigned int otherId,UdpServer*udpServer, QWidget *parent):
QMainWindow(parent),
ui(new Ui::ChatWindow),
udpServer(udpServer)
{
ui->setupUi(this);
this->mainWins=mainWins;
myInfo = mainWins->infoMap[myId];
otherInfo = mainWins->infoMap[otherId];
ui->label->setText(otherInfo->getNick()+'('+QString::number(otherInfo->getId())+')');
//setStyleSheet("background-image: url(/home/lu/code/QtProject/MyChat/images/chatWinBackGround.jpg)");
}
ChatWindow::~ChatWindow()
{
delete ui;
}
void ChatWindow::showMsg(const QString &msg){
ui->textBrowser->insertPlainText(msg);
}
void ChatWindow::close(){
this->setVisible(false);
}
void ChatWindow::on_sendButton_clicked()
{
if(ui->textEdit->toPlainText().isEmpty()){
return;
}
QString msg=ui->textEdit->toPlainText();
ui->textEdit->clear();
unsigned int myId = myInfo->getId();
unsigned int otherId = otherInfo->getId();
ui->textBrowser->insertPlainText(QString::number(myId)+":\n"+msg+"\n");
msg="*"+QString::number(myId)+"*"+msg+"\n";
udpServer->sendMessage(otherId,msg);
}