Fixes #510 - Network item shows wrong buffer
[quassel.git] / src / uisupport / nickview.cpp
index ad13a2f..dd7d1af 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -18,6 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include "nickview.h"
+
 #include <QHeaderView>
 #include <QScrollBar>
 #include <QDebug>
@@ -25,7 +27,6 @@
 
 #include "buffermodel.h"
 #include "client.h"
-#include "nickview.h"
 #include "nickviewfilter.h"
 #include "networkmodel.h"
 #include "quasselui.h"
@@ -39,6 +40,12 @@ public:
 NickView::NickView(QWidget *parent)
   : QTreeView(parent)
 {
+  QAbstractItemDelegate *oldDelegate = itemDelegate();
+  NickViewDelegate *newDelegate = new NickViewDelegate(this);
+  setItemDelegate(newDelegate);
+  delete oldDelegate;
+
+  
   setIndentation(10);
   setAnimated(true);
   header()->hide();
@@ -47,10 +54,11 @@ NickView::NickView(QWidget *parent)
   sortByColumn(0, Qt::AscendingOrder);
 
   setContextMenuPolicy(Qt::CustomContextMenu);
+  setSelectionMode(QAbstractItemView::ExtendedSelection);
 
   connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(showContextMenu(const QPoint&)));
 
-#if defined Q_WS_QWS or defined Q_WS_X11
+#if defined Q_WS_QWS || defined Q_WS_X11
   connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(startQuery(QModelIndex)));
 #else
   // afaik this is better on Mac and Windows
@@ -89,8 +97,13 @@ void NickView::showContextMenu(const QPoint & pos ) {
   if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType)
     return;
 
+  QModelIndexList indexList = selectedIndexes();
+  // make sure the item we clicked on is first
+  indexList.removeAll(index);
+  indexList.prepend(index);
+
   QMenu contextMenu(this);
-  Client::mainUi()->actionProvider()->addActions(&contextMenu, index);
+  Client::mainUi()->actionProvider()->addActions(&contextMenu, indexList);
   contextMenu.exec(QCursor::pos());
 }
 
@@ -137,3 +150,19 @@ void NickView::customEvent(QEvent *event) {
   }
   event->accept();
 }
+
+
+// ****************************************
+//  NickViewDelgate
+// ****************************************
+NickViewDelegate::NickViewDelegate(QObject *parent)
+  : QStyledItemDelegate(parent)
+{
+}
+
+void NickViewDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const {
+  QStyledItemDelegate::initStyleOption(option, index);
+
+  if(!index.data(NetworkModel::ItemActiveRole).toBool())
+    option->palette.setColor(QPalette::Text, option->palette.color(QPalette::Dark));
+}