X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fnicklistwidget.cpp;h=d2ef8e87488014e5aed61bb54408d1db443f7513;hp=68a6757ce4a64b4ca8bdab313c6a9d9711fd438c;hb=d37bdc91c5474603e1417c2cd9c40c02e1ad5ee6;hpb=76a276c472cb99032e2407d8e4bc2f2d693e8e67 diff --git a/src/qtui/nicklistwidget.cpp b/src/qtui/nicklistwidget.cpp index 68a6757c..d2ef8e87 100644 --- a/src/qtui/nicklistwidget.cpp +++ b/src/qtui/nicklistwidget.cpp @@ -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 * @@ -20,7 +20,6 @@ #include "nicklistwidget.h" -#include "buffer.h" #include "nickview.h" #include "client.h" #include "networkmodel.h" @@ -28,33 +27,36 @@ #include "nickviewfilter.h" #include "qtuisettings.h" +#include +#include +#include +#include + NickListWidget::NickListWidget(QWidget *parent) - : AbstractItemView(parent), - _showNickListAction(new QAction(tr("Nicks"), this)), - _showDockAction(0) + : AbstractItemView(parent) { - _showNickListAction->setCheckable(true); - QtUiSettings s; - _showNickListAction->setChecked(s.value("ShowNickListAction", QVariant(true)).toBool()); ui.setupUi(this); - connect(_showNickListAction, SIGNAL(toggled(bool)), this, SLOT(showWidget(bool))); } -NickListWidget::~NickListWidget() { - QtUiSettings s; - s.setValue("ShowNickListAction", showNickListAction()->isChecked()); +QDockWidget *NickListWidget::dock() const { + QDockWidget *dock = qobject_cast(parent()); + if(dock) + return dock; + else + return 0; } -void NickListWidget::setShowDockAction(QAction *action) { - _showDockAction = action; +void NickListWidget::hideEvent(QHideEvent *event) { + emit nickSelectionChanged(QModelIndexList()); + AbstractItemView::hideEvent(event); } -QAction *NickListWidget::showDockAction() const { - return _showDockAction; -} +void NickListWidget::showEvent(QShowEvent *event) { + NickView *view = qobject_cast(ui.stackedWidget->currentWidget()); + if(view) + emit nickSelectionChanged(view->selectedIndexes()); -QAction *NickListWidget::showNickListAction() const { - return _showNickListAction; + AbstractItemView::showEvent(event); } void NickListWidget::showWidget(bool visible) { @@ -62,21 +64,15 @@ void NickListWidget::showWidget(bool visible) { return; QModelIndex currentIndex = selectionModel()->currentIndex(); - if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && showDockAction()) { - if(visible != showDockAction()->isChecked()) { - // show or hide - showDockAction()->trigger(); - } - } -} - -void NickListWidget::changedVisibility(bool visible) { - if(!selectionModel()) - return; - - QModelIndex currentIndex = selectionModel()->currentIndex(); - if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && !visible) { - showNickListAction()->setChecked(false); + if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) { + QDockWidget *dock_ = dock(); + if(!dock_) + return; + + if(visible) + dock_->show(); + else + dock_->close(); } } @@ -87,35 +83,54 @@ void NickListWidget::currentChanged(const QModelIndex ¤t, const QModelInde if(bufferType != BufferInfo::ChannelBuffer) { ui.stackedWidget->setCurrentWidget(ui.emptyPage); - if(showDockAction() && showDockAction()->isChecked()) { - // hide - showDockAction()->trigger(); - } + emit nickSelectionChanged(QModelIndexList()); return; - } else { - if(showNickListAction()->isChecked()) - if(showDockAction()&& !showDockAction()->isChecked()) { - // show - showDockAction()->trigger(); - } } + // 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; + 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); view->setRootIndex(filter->mapFromSource(source_current)); - view->expandAll(); 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) { @@ -171,3 +186,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()) { +// 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); +// } +// }