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.

dialogaddcontact.cpp 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "dialogaddcontact.h"
  2. #include "ui_dialogaddcontact.h"
  3. DialogAddContact::DialogAddContact(QWidget *parent) : QDialog(parent), ui(new Ui::DialogAddContact)
  4. {
  5. ui->setupUi(this);
  6. connect(ui->lineSearch, SIGNAL(textChanged(QString)), ui->listContacts, SLOT(filter(QString)));
  7. connect(ui->listContacts, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(menuRequested(QPoint)));
  8. m_menu = new QMenu("Add contact");
  9. connect(m_menu->addAction("Add to contacts"), SIGNAL(triggered()), this, SLOT(addContact()));
  10. connect(m_menu->addAction("Chat"), SIGNAL(triggered()), this, SLOT(chat()));
  11. }
  12. DialogAddContact::~DialogAddContact()
  13. {
  14. delete ui;
  15. delete m_menu;
  16. }
  17. void DialogAddContact::setUsers(NetSoul::Users users)
  18. {
  19. ui->listContacts->clear();
  20. ui->listContacts->addUsers(users);
  21. }
  22. void DialogAddContact::on_lineSearch_returnPressed()
  23. {
  24. emit contactAdded(ui->lineSearch->text());
  25. }
  26. void DialogAddContact::on_listContacts_itemDoubleClicked(QTreeWidgetItem *item, int column)
  27. {
  28. emit contactAdded(item->text(0));
  29. }
  30. void DialogAddContact::chat()
  31. {
  32. emit chatRequested(ui->listContacts->getSelectedUsers());
  33. }
  34. void DialogAddContact::addContact()
  35. {
  36. foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers())
  37. emit contactAdded(usr.login);
  38. }
  39. void DialogAddContact::menuRequested(QPoint p)
  40. {
  41. if(ui->listContacts->getSelectedUsers().isEmpty())
  42. return;
  43. m_menu->move(ui->listContacts->mapToGlobal(p) + QPoint(0, ui->listContacts->header()->height()));
  44. m_menu->show();
  45. }