#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::fromUtf8(str.c_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(); }