You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dialogchat.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "dialogchat.h"
  2. #include "ui_dialogchat.h"
  3. #include <QShortcut>
  4. DialogChat::DialogChat(QWidget *parent) : QWidget(parent), ui(new Ui::DialogChat)
  5. {
  6. ui->setupUi(this);
  7. QShortcut* quit = new QShortcut(QKeySequence("Ctrl+W"), this);
  8. connect(quit, SIGNAL(activated()), this, SLOT(hide()));
  9. quit = new QShortcut(QKeySequence("Escape"), this);
  10. connect(quit, SIGNAL(activated()), this, SLOT(hide()));
  11. }
  12. DialogChat::~DialogChat()
  13. {
  14. delete ui;
  15. }
  16. NetSoul::User DialogChat::getUser()
  17. {
  18. return m_user;
  19. }
  20. bool DialogChat::match(NetSoul::User usr)
  21. {
  22. return usr.login == m_user.login && usr.location == m_user.location;
  23. }
  24. void DialogChat::closeEvent(QCloseEvent* e)
  25. {
  26. e->ignore();
  27. hide();
  28. }
  29. void DialogChat::setUser(NetSoul::User user)
  30. {
  31. m_user = user;
  32. setWindowTitle(user.login + "@" + user.location);
  33. }
  34. void DialogChat::newMessage(NetSoul::Message msg)
  35. {
  36. append(msg.from, msg.message);
  37. }
  38. void DialogChat::setMe(NetSoul::User usr)
  39. {
  40. m_me = usr;
  41. }
  42. void DialogChat::on_lineChat_returnPressed()
  43. {
  44. emit sendMessageRequested(m_user, ui->lineChat->text());
  45. append(m_me, ui->lineChat->text());
  46. ui->lineChat->clear();
  47. }
  48. void DialogChat::append(NetSoul::User usr, QString msg)
  49. {
  50. ui->textChat->append(usr.login + "@" + usr.location + ": " + msg);
  51. }