From: Manuel Nickschas Date: Fri, 6 Feb 2009 00:21:53 +0000 (+0100) Subject: Generate selection change events and propagate to ToolBarActionProvider X-Git-Tag: 0.4.0~122 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=982359db5545edf340a246cd13dfcdc9bf2ccf33 Generate selection change events and propagate to ToolBarActionProvider --- diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index b3e724da..b5d90a44 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -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); diff --git a/src/qtui/nicklistwidget.cpp b/src/qtui/nicklistwidget.cpp index 68e720fc..d2ef8e87 100644 --- a/src/qtui/nicklistwidget.cpp +++ b/src/qtui/nicklistwidget.cpp @@ -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(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 ¤t, const QModelInde if(bufferType != BufferInfo::ChannelBuffer) { ui.stackedWidget->setCurrentWidget(ui.emptyPage); + emit nickSelectionChanged(QModelIndexList()); return; } @@ -91,10 +105,12 @@ void NickListWidget::currentChanged(const QModelIndex ¤t, 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 ¤t, 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(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) { diff --git a/src/qtui/nicklistwidget.h b/src/qtui/nicklistwidget.h index 79caf350..18f966aa 100644 --- a/src/qtui/nicklistwidget.h +++ b/src/qtui/nicklistwidget.h @@ -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 ¤t, const QModelIndex &previous); @@ -52,7 +57,8 @@ protected slots: private slots: void removeBuffer(BufferId bufferId); - + void nickSelectionChanged(); + private: Ui::NickListWidget ui; QHash nickViews; diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 3c1ac8c8..88fb4348 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -71,6 +71,7 @@ void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const Q if(newBufferId != oldBufferId) { setCurrentBuffer(newBufferId); emit currentChanged(newBufferId); + emit currentChanged(current); } } diff --git a/src/uisupport/abstractbuffercontainer.h b/src/uisupport/abstractbuffercontainer.h index 747b8852..bf583333 100644 --- a/src/uisupport/abstractbuffercontainer.h +++ b/src/uisupport/abstractbuffercontainer.h @@ -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 diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index 1a1c4bba..e27640e3 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -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; } diff --git a/src/uisupport/nickview.h b/src/uisupport/nickview.h index d77f1786..0a567e55 100644 --- a/src/uisupport/nickview.h +++ b/src/uisupport/nickview.h @@ -49,7 +49,7 @@ signals: void selectionUpdated(); private: - + friend class NickListWidget; // needs selectedIndexes() }; // ******************************