#include "dialogchat.h" #include "ui_dialogchat.h" #include DialogChat::DialogChat(QWidget *parent) : QWidget(parent), ui(new Ui::DialogChat) { ui->setupUi(this); QShortcut* quit = new QShortcut(QKeySequence("Ctrl+W"), this); connect(quit, SIGNAL(activated()), this, SLOT(hide())); quit = new QShortcut(QKeySequence("Escape"), this); connect(quit, SIGNAL(activated()), this, SLOT(hide())); } DialogChat::~DialogChat() { delete ui; } NetSoul::User DialogChat::getUser() { return m_user; } bool DialogChat::match(NetSoul::User usr) { return usr.login == m_user.login && usr.location == m_user.location; } void DialogChat::closeEvent(QCloseEvent* e) { e->ignore(); hide(); } void DialogChat::setUser(NetSoul::User user) { m_user = user; setWindowTitle(user.login + "@" + user.location); } void DialogChat::newMessage(NetSoul::Message msg) { append(msg.from, msg.message); } void DialogChat::setMe(NetSoul::User usr) { m_me = usr; } void DialogChat::on_lineChat_returnPressed() { emit sendMessageRequested(m_user, ui->lineChat->text()); append(m_me, ui->lineChat->text()); ui->lineChat->clear(); } void DialogChat::append(NetSoul::User usr, QString msg) { ui->textChat->append(usr.login + "@" + usr.location + ": " + msg); }