X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fbufferwidget.cpp;h=51c551c3328a97dde609021d002f4dd3cc4e30b6;hp=8831a28ea3685b51570d180cb8721326b1cef3a2;hb=87828aeae2510b29619aa79a3bd76885e2c1ebd4;hpb=8010224cf5bfe5685dc2cf535e8dc1ec19c4c364 diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index 8831a28e..51c551c3 100644 --- a/src/qtui/bufferwidget.cpp +++ b/src/qtui/bufferwidget.cpp @@ -20,6 +20,7 @@ #include "bufferwidget.h" #include "buffer.h" +#include "chatline.h" #include "chatline-old.h" #include "chatwidget.h" #include "settings.h" @@ -28,6 +29,8 @@ #include "network.h" #include "networkmodel.h" +#include "global.h" + BufferWidget::BufferWidget(QWidget *parent) : QWidget(parent), _bufferModel(0), @@ -48,8 +51,11 @@ void BufferWidget::setModel(BufferModel *bufferModel) { disconnect(_bufferModel, 0, this, 0); } _bufferModel = bufferModel; - connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), - this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int))); + + if(bufferModel) { + connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), + this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int))); + } } void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) { @@ -57,8 +63,11 @@ void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) { disconnect(_selectionModel, 0, this, 0); } _selectionModel = selectionModel; - connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - this, SLOT(currentChanged(QModelIndex, QModelIndex))); + + if(selectionModel) { + connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + this, SLOT(currentChanged(QModelIndex, QModelIndex))); + } } void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { @@ -84,7 +93,7 @@ void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, in for(int i = start; i <= end; i++) { QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole); if(!variant.isValid()) - continue; + continue; BufferId bufferId = qVariantValue(variant); removeBuffer(bufferId); @@ -103,17 +112,20 @@ void BufferWidget::removeBuffer(BufferId bufferId) { } void BufferWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { - Q_UNUSED(previous); - QVariant variant; - - variant = current.data(NetworkModel::BufferIdRole); - if(!variant.isValid()) - return; - setCurrentBuffer(variant.value()); + BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value(); + BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value(); + if(newBufferId != oldBufferId) + setCurrentBuffer(newBufferId); } void BufferWidget::setCurrentBuffer(BufferId bufferId) { + if(!bufferId.isValid()) { + ui.stackedWidget->setCurrentWidget(ui.page); + return; + } + ChatWidget *chatWidget = 0; + ChatView *chatView = 0; Buffer *buf = Client::buffer(bufferId); if(!buf) { qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId; @@ -121,25 +133,47 @@ void BufferWidget::setCurrentBuffer(BufferId bufferId) { } Buffer *prevBuffer = Client::buffer(currentBuffer()); if(prevBuffer) prevBuffer->setVisible(false); - if(_chatWidgets.contains(bufferId)) { - chatWidget = _chatWidgets[bufferId]; + if(Global::SPUTDEV) { + if(_chatViews.contains(bufferId)) { + chatView = _chatViews[bufferId]; + } else { + chatView = new ChatView(buf, this); + //chatView->init(bufferId); + QList lines; + QList msgs = buf->contents(); + foreach(AbstractUiMsg *msg, msgs) { + lines.append(dynamic_cast(msg)); + } + chatView->setContents(lines); + connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatView, SLOT(appendMsg(AbstractUiMsg *))); + connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatView, SLOT(prependMsg(AbstractUiMsg *))); + _chatViews[bufferId] = chatView; + ui.stackedWidget->addWidget(chatView); + chatView->setFocusProxy(this); + } + _currentBuffer = bufferId; + ui.stackedWidget->setCurrentWidget(chatView); } else { - chatWidget = new ChatWidget(this); - chatWidget->init(bufferId); - QList lines; - QList msgs = buf->contents(); - foreach(AbstractUiMsg *msg, msgs) { - lines.append(dynamic_cast(msg)); + if(_chatWidgets.contains(bufferId)) { + chatWidget = _chatWidgets[bufferId]; + } else { + chatWidget = new ChatWidget(this); + chatWidget->init(bufferId); + QList lines; + QList msgs = buf->contents(); + foreach(AbstractUiMsg *msg, msgs) { + lines.append(dynamic_cast(msg)); + } + chatWidget->setContents(lines); + connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *))); + connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *))); + _chatWidgets[bufferId] = chatWidget; + ui.stackedWidget->addWidget(chatWidget); + chatWidget->setFocusProxy(this); } - chatWidget->setContents(lines); - connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *))); - connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *))); - _chatWidgets[bufferId] = chatWidget; - ui.stackedWidget->addWidget(chatWidget); - chatWidget->setFocusProxy(this); + _currentBuffer = bufferId; + ui.stackedWidget->setCurrentWidget(chatWidget); } - _currentBuffer = bufferId; - ui.stackedWidget->setCurrentWidget(chatWidget); buf->setVisible(true); setFocus(); }