#include "dialogaddcontact.h" #include "ui_dialogaddcontact.h" DialogAddContact::DialogAddContact(QWidget *parent) : QDialog(parent), ui(new Ui::DialogAddContact) { ui->setupUi(this); connect(ui->lineSearch, SIGNAL(textChanged(QString)), ui->listContacts, SLOT(filter(QString))); connect(ui->listContacts, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(menuRequested(QPoint))); m_menu = new QMenu("Add contact"); connect(m_menu->addAction("Add to contacts"), SIGNAL(triggered()), this, SLOT(addContact())); connect(m_menu->addAction("Chat"), SIGNAL(triggered()), this, SLOT(chat())); } DialogAddContact::~DialogAddContact() { delete ui; delete m_menu; } void DialogAddContact::setUsers(NetSoul::Users users) { ui->listContacts->clear(); ui->listContacts->addUsers(users); } void DialogAddContact::on_lineSearch_returnPressed() { emit contactAdded(ui->lineSearch->text()); } void DialogAddContact::on_listContacts_itemDoubleClicked(QTreeWidgetItem *item, int column) { emit contactAdded(item->text(0)); } void DialogAddContact::chat() { emit chatRequested(ui->listContacts->getSelectedUsers()); } void DialogAddContact::addContact() { foreach(NetSoul::User usr, ui->listContacts->getSelectedUsers()) emit contactAdded(usr.login); } void DialogAddContact::menuRequested(QPoint p) { if(ui->listContacts->getSelectedUsers().isEmpty()) return; m_menu->move(ui->listContacts->mapToGlobal(p) + QPoint(0, ui->listContacts->header()->height())); m_menu->show(); }