Generate selection change events and propagate to ToolBarActionProvider
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 6 Feb 2009 00:21:53 +0000 (01:21 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 6 Feb 2009 00:26:32 +0000 (01:26 +0100)
src/qtui/mainwin.cpp
src/qtui/nicklistwidget.cpp
src/qtui/nicklistwidget.h
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/abstractbuffercontainer.h
src/uisupport/nickview.cpp
src/uisupport/nickview.h

index b3e724d..b5d90a4 100644 (file)
@@ -523,6 +523,11 @@ void MainWin::setupSystray() {
 }
 
 void MainWin::setupToolBars() {
+  connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
+          QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
+  connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
+          QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
+
   _networkToolBar = addToolBar("Network");
   _networkToolBar->setObjectName("NetworkToolBar");
   QtUi::toolBarActionProvider()->addActions(_networkToolBar, ToolBarActionProvider::NetworkToolBar);
index 68e720f..d2ef8e8 100644 (file)
@@ -46,6 +46,19 @@ QDockWidget *NickListWidget::dock() const {
     return 0;
 }
 
+void NickListWidget::hideEvent(QHideEvent *event) {
+  emit nickSelectionChanged(QModelIndexList());
+  AbstractItemView::hideEvent(event);
+}
+
+void NickListWidget::showEvent(QShowEvent *event) {
+  NickView *view = qobject_cast<NickView *>(ui.stackedWidget->currentWidget());
+  if(view)
+    emit nickSelectionChanged(view->selectedIndexes());
+
+  AbstractItemView::showEvent(event);
+}
+
 void NickListWidget::showWidget(bool visible) {
   if(!selectionModel())
     return;
@@ -70,6 +83,7 @@ void NickListWidget::currentChanged(const QModelIndex &current, const QModelInde
 
   if(bufferType != BufferInfo::ChannelBuffer) {
     ui.stackedWidget->setCurrentWidget(ui.emptyPage);
+    emit nickSelectionChanged(QModelIndexList());
     return;
   }
 
@@ -91,10 +105,12 @@ void NickListWidget::currentChanged(const QModelIndex &current, const QModelInde
   if(newBufferId == oldBufferId)
     return;
 
+  NickView *view;
   if(nickViews.contains(newBufferId)) {
-    ui.stackedWidget->setCurrentWidget(nickViews.value(newBufferId));
+    view = nickViews.value(newBufferId);
+    ui.stackedWidget->setCurrentWidget(view);
   } else {
-    NickView *view = new NickView(this);
+    view = new NickView(this);
     NickViewFilter *filter = new NickViewFilter(newBufferId, Client::networkModel());
     view->setModel(filter);
     QModelIndex source_current = Client::bufferModel()->mapToSource(current);
@@ -102,7 +118,19 @@ void NickListWidget::currentChanged(const QModelIndex &current, const QModelInde
     nickViews[newBufferId] = view;
     ui.stackedWidget->addWidget(view);
     ui.stackedWidget->setCurrentWidget(view);
+    connect(view, SIGNAL(selectionUpdated()), SLOT(nickSelectionChanged()));
+  }
+  emit nickSelectionChanged(view->selectedIndexes());
+}
+
+void NickListWidget::nickSelectionChanged() {
+  NickView *view = qobject_cast<NickView *>(sender());
+  Q_ASSERT(view);
+  if(view != ui.stackedWidget->currentWidget()) {
+    qDebug() << "Nick selection of hidden view changed!";
+    return;
   }
+  emit nickSelectionChanged(view->selectedIndexes());
 }
 
 void NickListWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
index 79caf35..18f966a 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _NICKLISTWIDGET_H_
-#define _NICKLISTWIDGET_H_
+#ifndef NICKLISTWIDGET_H_
+#define NICKLISTWIDGET_H_
 
 #include "ui_nicklistwidget.h"
 #include "abstractitemview.h"
@@ -43,8 +43,13 @@ public:
 public slots:
   void showWidget(bool visible);
 
+signals:
+  void nickSelectionChanged(const QModelIndexList &);
+
 protected:
   virtual QSize sizeHint() const;
+  virtual void hideEvent(QHideEvent *);
+  virtual void showEvent(QShowEvent *);
 
 protected slots:
   virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
@@ -52,7 +57,8 @@ protected slots:
 
 private slots:
   void removeBuffer(BufferId bufferId);
-  
+  void nickSelectionChanged();
+
 private:
   Ui::NickListWidget ui;
   QHash<BufferId, NickView *> nickViews;
index 3c1ac8c..88fb434 100644 (file)
@@ -71,6 +71,7 @@ void AbstractBufferContainer::currentChanged(const QModelIndex &current, const Q
   if(newBufferId != oldBufferId) {
     setCurrentBuffer(newBufferId);
     emit currentChanged(newBufferId);
+    emit currentChanged(current);
   }
 }
 
index 747b885..bf58333 100644 (file)
@@ -39,6 +39,7 @@ public:
 
 signals:
   void currentChanged(BufferId);
+  void currentChanged(const QModelIndex &);
 
 protected:
   //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary
index 1a1c4bb..e27640e 100644 (file)
@@ -104,9 +104,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;
 }
index d77f178..0a567e5 100644 (file)
@@ -49,7 +49,7 @@ signals:
   void selectionUpdated();
 
 private:
-
+  friend class NickListWidget;  // needs selectedIndexes()
 };
 
 // ******************************