X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferview.cpp;h=48e75ba9d2bcf630c25d24bd02229cc808f72e23;hp=e922559043bd65be57f4fdf99a0d8afdbdf2e9ec;hb=997a62b68d7469a93f373476dd955c44eb051be0;hpb=ad801015af3afad53e0b245afc3a2214373a1b44 diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index e9225590..48e75ba9 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -18,16 +18,26 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "client.h" -#include "buffersyncer.h" #include "bufferview.h" -#include "networkmodel.h" + +#include "bufferviewfilter.h" +#include "buffersyncer.h" +#include "client.h" #include "network.h" +#include "networkmodel.h" #include "uisettings.h" #include "global.h" +#include +#include +#include +#include +#include +#include +#include + /***************************************** * The TreeView showing the Buffers *****************************************/ @@ -66,16 +76,12 @@ void BufferView::init() { #endif } -void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QList nets) { - BufferViewFilter *filter = new BufferViewFilter(model, mode, nets); - setModel(filter); - connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &))); -} - void BufferView::setModel(QAbstractItemModel *model) { delete selectionModel(); QTreeView::setModel(model); init(); + if(!model) + return; // remove old Actions QList oldactions = header()->actions(); @@ -98,6 +104,59 @@ void BufferView::setModel(QAbstractItemModel *model) { } +void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *config) { + BufferViewFilter *filter = qobject_cast(model()); + if(filter) { + filter->setConfig(config); + setConfig(config); + return; + } + + if(model()) { + disconnect(this, 0, model(), 0); + } + + if(!model_) { + setModel(model_); + } else { + BufferViewFilter *filter = new BufferViewFilter(model_, config); + setModel(filter); + connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &))); + } + setConfig(config); +} + +void BufferView::setConfig(BufferViewConfig *config) { + if(_config == config) + return; + + if(_config) { + disconnect(_config, 0, this, 0); + } + + _config = config; + if(config) { + connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(setRootIndexForNetworkId(const NetworkId &))); + setRootIndexForNetworkId(config->networkId()); + } else { + setRootIndex(QModelIndex()); + } +} + +void BufferView::setRootIndexForNetworkId(const NetworkId &networkId) { + if(!networkId.isValid() || !model()) { + setRootIndex(QModelIndex()); + } else { + int networkCount = model()->rowCount(); + QModelIndex child; + for(int i = 0; i < networkCount; i++) { + child = model()->index(i, 0); + if(networkId == model()->data(child, NetworkModel::NetworkIdRole).value()) + setRootIndex(child); + } + } +} + void BufferView::joinChannel(const QModelIndex &index) { BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value(); @@ -304,7 +363,7 @@ void BufferView::wheelEvent(QWheelEvent* event) { QSize BufferView::sizeHint() const { - return QSize(120, 50); + return QTreeView::sizeHint(); if(!model()) return QTreeView::sizeHint(); @@ -319,3 +378,28 @@ QSize BufferView::sizeHint() const { } return QSize(columnSize, 50); } + +// ============================== +// BufferView Dock +// ============================== +BufferViewDock::BufferViewDock(BufferViewConfig *config, QWidget *parent) + : QDockWidget(config->bufferViewName(), parent) +{ + setObjectName("BufferViewDock-" + QString::number(config->bufferViewId())); + toggleViewAction()->setData(config->bufferViewId()); + setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); + connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(bufferViewRenamed(const QString &))); +} + +BufferViewDock::BufferViewDock(QWidget *parent) + : QDockWidget(tr("All Buffers"), parent) +{ + setObjectName("BufferViewDock--1"); + toggleViewAction()->setData((int)-1); + setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); +} + +void BufferViewDock::bufferViewRenamed(const QString &newName) { + setWindowTitle(newName); + toggleViewAction()->setText(newName); +}