Added a context menu to users
authorAlexander von Renteln <phon@quassel-irc.org>
Mon, 28 Jan 2008 15:59:57 +0000 (15:59 +0000)
committerAlexander von Renteln <phon@quassel-irc.org>
Mon, 28 Jan 2008 15:59:57 +0000 (15:59 +0000)
src/uisupport/nickview.cpp
src/uisupport/nickview.h

index b3efda4..0b4a741 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <QHeaderView>
+#include <QDebug>
+#include <QMenu>
+
 #include "nickview.h"
 #include "nickmodel.h"
 #include "nickview.h"
 #include "nickmodel.h"
+#include "networkmodel.h"
+#include "types.h"
+#include "client.h"
 
 
-#include <QHeaderView>
-#include <QDebug>
 
 NickView::NickView(QWidget *parent)
   : QTreeView(parent)
 
 NickView::NickView(QWidget *parent)
   : QTreeView(parent)
@@ -32,6 +37,11 @@ NickView::NickView(QWidget *parent)
   header()->hide();
   setSortingEnabled(true);
   sortByColumn(0, Qt::AscendingOrder);
   header()->hide();
   setSortingEnabled(true);
   sortByColumn(0, Qt::AscendingOrder);
+
+  setContextMenuPolicy(Qt::CustomContextMenu);
+
+  connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), 
+          this, SLOT(showContextMenu(const QPoint&)));
 }
 
 NickView::~NickView() {
 }
 
 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?
 }
 
   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<BufferInfo>();
+
+  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);
+  }
+}
index df8321d..aa25835 100644 (file)
 #ifndef _NICKVIEW_H_
 #define _NICKVIEW_H_
 
 #ifndef _NICKVIEW_H_
 #define _NICKVIEW_H_
 
+
 #include <QTreeView>
 
 #include <QTreeView>
 
+#include "types.h"
+#include "bufferinfo.h"
+
+
 class NickModel;
 class FilteredNickModel;
 class QSortFilterProxyModel;
 class NickModel;
 class FilteredNickModel;
 class QSortFilterProxyModel;
@@ -36,11 +41,13 @@ public:
   
 protected:
   void rowsInserted(const QModelIndex &, int, int);
   
 protected:
   void rowsInserted(const QModelIndex &, int, int);
-                                                 
+  
 public slots:
   void setModel(QAbstractItemModel *model);
   void init();
 public slots:
   void setModel(QAbstractItemModel *model);
   void init();
+  void showContextMenu(const QPoint & pos );
 
 };
 
 
 };
 
+
 #endif
 #endif