chatwidget.cpp
1.12 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
#include "chatwidget.h"
ChatWidget::ChatWidget(QWidget *parent) :
QTextEdit(parent)
{
}
void ChatWidget::printMsg(const string &str)
{
this->setFontWeight(QFont::Normal);
this->setFontItalic(false);
this->setTextColor(Qt::black);
this->append(QString::fromStdString(str));
}
void ChatWidget::printServerMsg(const string &str)
{
this->setFontWeight(QFont::Normal);
this->setFontItalic(true);
this->setTextColor(Qt::gray);
this->append(QString::fromStdString(str));
}
void ChatWidget::printStatusMsg(const string &str)
{
this->setFontWeight(QFont::Bold);
this->setFontItalic(false);
this->setTextColor(Qt::black);
this->append(QString::fromStdString(str));
}
void ChatWidget::saveChatToFile()
{
QFileDialog fileDialog;
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.exec();
QString filename = fileDialog.selectedFiles().front();
QFile file(filename);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream fileOut(&file);
fileOut << this->toPlainText() << endl;
file.close();
}