Work around problems in QTreeView when using Qt 4.8
[quassel.git] / src / uisupport / nickview.cpp
index 1a1c4bb..34fb554 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "nickview.h"
 
+#include <QApplication>
 #include <QHeaderView>
 #include <QScrollBar>
 #include <QDebug>
@@ -33,7 +34,6 @@
 #include "nickviewfilter.h"
 #include "networkmodel.h"
 #include "types.h"
-#include "uisettings.h"
 
 class ExpandAllEvent : public QEvent {
 public:
@@ -43,13 +43,7 @@ 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();
   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   setSortingEnabled(true);
@@ -58,6 +52,10 @@ NickView::NickView(QWidget *parent)
   setContextMenuPolicy(Qt::CustomContextMenu);
   setSelectionMode(QAbstractItemView::ExtendedSelection);
 
+  // breaks with Qt 4.8
+  if(QString("4.8.0") > qVersion()) // FIXME breaks with Qt versions >= 4.10!
+    setAnimated(true);
+
   connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(showContextMenu(const QPoint&)));
 
 #if defined Q_WS_QWS || defined Q_WS_X11
@@ -104,9 +102,10 @@ QModelIndexList NickView::selectedIndexes() const {
   QModelIndexList indexList = QTreeView::selectedIndexes();
 
   // make sure the item we clicked on is first
-  Q_ASSERT(indexList.contains(currentIndex()));
-  indexList.removeAll(currentIndex());
-  indexList.prepend(currentIndex());
+  if(indexList.contains(currentIndex())) {
+    indexList.removeAll(currentIndex());
+    indexList.prepend(currentIndex());
+  }
 
   return indexList;
 }
@@ -128,11 +127,7 @@ void NickView::startQuery(const QModelIndex &index) {
   if(!ircUser || !networkId.isValid())
     return;
 
-  BufferId bufId = Client::networkModel()->bufferId(networkId, ircUser->nick());
-  if(bufId.isValid())
-    Client::bufferModel()->switchToBuffer(bufId);
-  else
-    Client::userInput(index.data(NetworkModel::BufferInfoRole).value<BufferInfo>(), QString("/QUERY %1").arg(ircUser->nick()));
+  Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
 }
 
 void NickView::customEvent(QEvent *event) {
@@ -148,6 +143,9 @@ void NickView::customEvent(QEvent *event) {
   if(event->type() != QEvent::User)
     return;
 
+  if(!model())
+    return;
+
   QModelIndex topLevelIdx;
   for(int i = 0; i < model()->rowCount(rootIndex()); i++) {
     topLevelIdx = model()->index(i, 0, rootIndex());
@@ -162,28 +160,3 @@ 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);
-
-  if(!index.isValid())
-    return;
-
-  QColor fgColor = _FgOnlineStatus;
-  if(!index.data(NetworkModel::ItemActiveRole).toBool())
-    fgColor = _FgAwayStatus;
-
-  option->palette.setColor(QPalette::Text, fgColor);
-}