Brining back the removed color options
[quassel.git] / src / uisupport / nickview.cpp
index e0a5893..fd86abd 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>
 
 #include "buffermodel.h"
 #include "client.h"
-#include "nickview.h"
 #include "nickviewfilter.h"
 #include "networkmodel.h"
 #include "quasselui.h"
 #include "types.h"
+#include "uisettings.h"
 
 class ExpandAllEvent : public QEvent {
 public:
@@ -39,6 +41,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,6 +55,7 @@ NickView::NickView(QWidget *parent)
   sortByColumn(0, Qt::AscendingOrder);
 
   setContextMenuPolicy(Qt::CustomContextMenu);
+  setSelectionMode(QAbstractItemView::ExtendedSelection);
 
   connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(showContextMenu(const QPoint&)));
 
@@ -89,8 +98,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 +151,25 @@ void NickView::customEvent(QEvent *event) {
   }
   event->accept();
 }
+
+
+// ****************************************
+//  NickViewDelgate
+// ****************************************
+NickViewDelegate::NickViewDelegate(QObject *parent)
+  : QStyledItemDelegate(parent)
+{
+  UiSettings s("QtUiStyle/Colors");
+  _FgOnlineStatus = s.value("onlineStatusFG", QVariant(QColor(Qt::black))).value<QColor>();
+  _FgAwayStatus = s.value("awayStatusFG", QVariant(QColor(Qt::gray))).value<QColor>();
+}
+
+void NickViewDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const {
+  QStyledItemDelegate::initStyleOption(option, index);
+
+  QColor fgColor = _FgOnlineStatus;
+  if(!index.data(NetworkModel::ItemActiveRole).toBool())
+    fgColor = _FgAwayStatus;
+
+  option->palette.setColor(QPalette::Text, fgColor);
+}