From: Alexander von Renteln Date: Mon, 28 Jan 2008 15:59:57 +0000 (+0000) Subject: Added a context menu to users X-Git-Tag: 0.2.0-alpha1~186 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=4295cdd849be0ae914387d0f62afb6f653f5f27f Added a context menu to users --- diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index b3efda42..0b4a7410 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -18,11 +18,16 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include +#include + #include "nickview.h" #include "nickmodel.h" +#include "networkmodel.h" +#include "types.h" +#include "client.h" -#include -#include NickView::NickView(QWidget *parent) : QTreeView(parent) @@ -32,6 +37,11 @@ NickView::NickView(QWidget *parent) header()->hide(); setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); + + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(showContextMenu(const QPoint&))); } NickView::~NickView() { @@ -57,3 +67,19 @@ void NickView::rowsInserted(const QModelIndex &index, int start, int end) { expandAll(); // FIXME We need to do this more intelligently. Maybe a pimped TreeView? } +void NickView::showContextMenu(const QPoint & pos ) { + QModelIndex index = indexAt(pos); + QString username = index.sibling(index.row(), 0).data().toString(); + BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value(); + + QMenu nickContextMenu(this); + nickContextMenu.addAction(tr("context menu for %1").arg(username)); + nickContextMenu.addSeparator(); + + QAction *whoisAction = nickContextMenu.addAction(tr("WHOIS")); + QAction *result = nickContextMenu.exec(QCursor::pos()); + + if (result == whoisAction ) { + Client::instance()->userInput(bufferInfo, "/WHOIS "+username); + } +} diff --git a/src/uisupport/nickview.h b/src/uisupport/nickview.h index df8321dc..aa25835d 100644 --- a/src/uisupport/nickview.h +++ b/src/uisupport/nickview.h @@ -21,8 +21,13 @@ #ifndef _NICKVIEW_H_ #define _NICKVIEW_H_ + #include +#include "types.h" +#include "bufferinfo.h" + + class NickModel; class FilteredNickModel; class QSortFilterProxyModel; @@ -36,11 +41,13 @@ public: protected: void rowsInserted(const QModelIndex &, int, int); - + public slots: void setModel(QAbstractItemModel *model); void init(); + void showContextMenu(const QPoint & pos ); }; + #endif