Blame view

QChatClient/chatwidget.cpp 1.12 KB
1
2
3
4
5
6
7
8
#include "chatwidget.h"

ChatWidget::ChatWidget(QWidget *parent) :
    QTextEdit(parent)
{

}
Imanol-Mikel Barba Sabariego authored
9
void ChatWidget::printMsg(const string &str)
10
{
Imanol-Mikel Barba Sabariego authored
11
12
13
    this->setFontWeight(QFont::Normal);
    this->setFontItalic(false);
    this->setTextColor(Qt::black);
14
    this->append(QString::fromUtf8(str.c_str()));
15
16
}
Imanol-Mikel Barba Sabariego authored
17
void ChatWidget::printServerMsg(const string &str)
18
{
Imanol-Mikel Barba Sabariego authored
19
20
21
    this->setFontWeight(QFont::Normal);
    this->setFontItalic(true);
    this->setTextColor(Qt::gray);
22
    this->append(QString::fromStdString(str));
23
24
}
25
void ChatWidget::printStatusMsg(const string &str)
26
{
Imanol-Mikel Barba Sabariego authored
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    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();
45
}