-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlgchatwindow.cpp
84 lines (74 loc) · 2.63 KB
/
lgchatwindow.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "lgchatwindow.h"
#include "ui_lgchatwindow.h"
#include <iostream>
LGChatWindow::LGChatWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::LGChatWindow)
{
ui->setupUi(this);
this->setAttribute(Qt::WA_QuitOnClose,false);
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(sendMessage()));
}
LGChatWindow::~LGChatWindow()
{
delete ui;
}
void LGChatWindow::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void LGChatWindow::setUserData(QString name, int number = 0) {
contactName = name;
contactNumber = number;
setWindowTitle("Rozmowa z " + name + " (" + QString::number(number) + ")");
}
int LGChatWindow::getNumber() {
return contactNumber;
}
QString LGChatWindow::enableEmoticons(QString message) {
message.replace(":)","<img src=\"emots/smile.png\">");
message.replace(":(","<img src=\"emots/frown.png\">");
message.replace(":P","<img src=\"emots/tongue.png\">");
message.replace(":p","<img src=\"emots/tongue.png\">");
message.replace(";P","<img src=\"emots/tongue.png\">");
message.replace(";p","<img src=\"emots/tongue.png\">");
message.replace(":*","<img src=\"emots/kiss.png\">");
message.replace(":-*","<img src=\"emots/kiss.png\">");
message.replace(":D","<img src=\"emots/grin.png\">");
message.replace(":-D","<img src=\"emots/grin.png\">");
message.replace("<3","<img src=\"emots/heart.png\">");
message.replace(";)","<img src=\"emots/wink.png\">");
message.replace(";-)","<img src=\"emots/wink.png\">");
message.replace(":o","<img src=\"emots/gasp.png\">");
message.replace(":O","<img src=\"emots/gasp.png\">");
return message;
}
void LGChatWindow::sendMessage() {
QString message = enableEmoticons(ui->plainTextEdit->toPlainText());
if(!ui->textBrowser->toPlainText().isEmpty()) {
ui->textBrowser->setHtml(ui->textBrowser->toHtml() + "\n<b><font color=\"blue\">Ja: </font></b>" + message);
}
else {
ui->textBrowser->setHtml("<b><font color=\"blue\">Ja:</font></b> " + message);
}
emit msgSent(contactNumber,ui->plainTextEdit->toPlainText().toStdString());
ui->plainTextEdit->clear();
}
void LGChatWindow::displayMessage(QString message) {
message = enableEmoticons(message);
ui->textBrowser->setHtml(ui->textBrowser->toHtml() + "\n<b><font color=\"red\">" + contactName + ":</font></b> " + message);
}
void LGChatWindow::closeEvent(QCloseEvent *a) {
emit closed(this);
delete this;
}
QString LGChatWindow::getName() {
return contactName;
}