Fix issues with single and double clicks in ChatView
[quassel.git] / src / qtui / nicklistwidget.cpp
index 714731a..2005151 100644 (file)
 
 #include "nicklistwidget.h"
 
-#include "buffer.h"
 #include "nickview.h"
 #include "client.h"
 #include "networkmodel.h"
 #include "buffermodel.h"
 #include "nickviewfilter.h"
+#include "qtuisettings.h"
+
+#include <QAction>
+#include <QDebug>
+#include <QEvent>
+#include <QAbstractButton>
 
 NickListWidget::NickListWidget(QWidget *parent)
   : AbstractItemView(parent)
@@ -33,6 +38,31 @@ NickListWidget::NickListWidget(QWidget *parent)
   ui.setupUi(this);
 }
 
+QDockWidget *NickListWidget::dock() const {
+  QDockWidget *dock = qobject_cast<QDockWidget *>(parent());
+  if(dock)
+    return dock;
+  else
+    return 0;
+}
+
+void NickListWidget::showWidget(bool visible) {
+  if(!selectionModel())
+    return;
+
+  QModelIndex currentIndex = selectionModel()->currentIndex();
+  if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
+    QDockWidget *dock_ = dock();
+    if(!dock_)
+      return;
+
+    if(visible)
+      dock_->show();
+    else
+      dock_->close();
+  }
+}
+
 void NickListWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
   BufferInfo::Type bufferType = (BufferInfo::Type)current.data(NetworkModel::BufferTypeRole).toInt();
   BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
@@ -43,6 +73,21 @@ void NickListWidget::currentChanged(const QModelIndex &current, const QModelInde
     return;
   }
 
+  // See NickListDock::NickListDock() below
+//   if(bufferType != BufferInfo::ChannelBuffer) {
+//     ui.stackedWidget->setCurrentWidget(ui.emptyPage);
+//     QDockWidget *dock_ = dock();
+//     if(dock_) {
+//       dock_->close();
+//     }
+//     return;
+//   } else {
+//     QDockWidget *dock_ = dock();
+//     if(dock_ && dock_->toggleViewAction()->isChecked()) {
+//       dock_->show();
+//     }
+//   }
+
   if(newBufferId == oldBufferId)
     return;
 
@@ -54,7 +99,6 @@ void NickListWidget::currentChanged(const QModelIndex &current, const QModelInde
     view->setModel(filter);
     QModelIndex source_current = Client::bufferModel()->mapToSource(current);
     view->setRootIndex(filter->mapFromSource(source_current));
-    view->expandAll();
     nickViews[newBufferId] = view;
     ui.stackedWidget->addWidget(view);
     ui.stackedWidget->setCurrentWidget(view);
@@ -114,3 +158,39 @@ QSize NickListWidget::sizeHint() const {
   else
     return currentWidget->sizeHint();
 }
+
+
+// ==============================
+//  NickList Dock
+// ==============================
+NickListDock::NickListDock(const QString &title, QWidget *parent)
+  : QDockWidget(title, parent)
+{
+  // THIS STUFF IS NEEDED FOR NICKLIST AUTOHIDE... 
+  // AS THIS BRINGS LOTS OF FUCKUPS WITH IT IT'S DEACTIVATED FOR NOW...
+  
+//   QAction *toggleView = toggleViewAction();
+//   disconnect(toggleView, SIGNAL(triggered(bool)), this, 0);
+//   toggleView->setChecked(QtUiSettings().value("ShowNickList", QVariant(true)).toBool());
+
+//   // reconnecting the closebuttons clicked signal to the action
+//   foreach(QAbstractButton *button, findChildren<QAbstractButton *>()) {
+//     if(disconnect(button, SIGNAL(clicked()), this, SLOT(close())))
+//       connect(button, SIGNAL(clicked()), toggleView, SLOT(trigger()));
+//   }
+}
+
+// NickListDock::~NickListDock() {
+//   QtUiSettings().setValue("ShowNickList", toggleViewAction()->isChecked());
+// }
+
+// bool NickListDock::event(QEvent *event) {
+//   switch (event->type()) {
+//   case QEvent::Hide:
+//   case QEvent::Show:
+//     emit visibilityChanged(event->type() == QEvent::Show);
+//     return QWidget::event(event);
+//   default:
+//     return QDockWidget::event(event);
+//   }
+// }