From 537d3828b060150a24e9cd1a6a81d2ee7b8cc753 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Mon, 25 May 2020 22:44:07 +0200 Subject: [PATCH] add contectmenu to contactitems --- src/contactmodel.cpp | 19 +++++++++++++++---- src/contactmodel.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index 6f452fa..8700a32 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -6,10 +6,19 @@ #include "mainwindow.h" #include "chatmodel.h" + void ContactModel::renderContactList(QListView* view) { QStandardItemModel* contact = new QStandardItemModel(); - + QMenu* contextMenu; + QAction* requestAction; + QAction* editAction; + contextMenu = new QMenu(view); + requestAction = new QAction("Send a contact request",contextMenu); + editAction = new QAction("Edit this contact",contextMenu); + + // QObject::connect(requestAction,SIGNAL(customContextMenuRequested(const QModelIndex)),this, SLOT(&ContactModel::requestActionClickedSlot)); + for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) { @@ -18,14 +27,16 @@ void ContactModel::renderContactList(QListView* view) QStandardItem* Items1 = new QStandardItem(c.getName()); Items1->setData(QIcon(avatar),Qt::DecorationRole); + contact->appendRow(Items1); view->setModel(contact); view->setIconSize(QSize(60,70)); view->setUniformItemSizes(true); view->setDragDropMode(QAbstractItemView::DropOnly); view->show(); - + view->setContextMenuPolicy(Qt::ActionsContextMenu); + view->addAction(requestAction); + view->addAction(editAction); } - -} \ No newline at end of file +} diff --git a/src/contactmodel.h b/src/contactmodel.h index fcdf7a3..cfe57bc 100644 --- a/src/contactmodel.h +++ b/src/contactmodel.h @@ -8,6 +8,7 @@ class ContactModel + { public: ContactModel() {}