X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqtui%2Fbufferwidget.cpp;h=d46fdec55c9f7fc7bbeea8b241c3f1785038f490;hb=858c7dbcbfa84deda9a71b4f4d25b1555bae3cc1;hp=8831a28ea3685b51570d180cb8721326b1cef3a2;hpb=8010224cf5bfe5685dc2cf535e8dc1ec19c4c364;p=quassel.git diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index 8831a28e..d46fdec5 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,10 +29,10 @@ #include "network.h" #include "networkmodel.h" +#include "global.h" + BufferWidget::BufferWidget(QWidget *parent) - : QWidget(parent), - _bufferModel(0), - _selectionModel(0), + : AbstractItemView(parent), _currentBuffer(0) { ui.setupUi(this); @@ -43,24 +44,6 @@ BufferWidget::~BufferWidget() { void BufferWidget::init() { } -void BufferWidget::setModel(BufferModel *bufferModel) { - if(_bufferModel) { - disconnect(_bufferModel, 0, this, 0); - } - _bufferModel = bufferModel; - connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), - this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int))); -} - -void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) { - if(_selectionModel) { - disconnect(_selectionModel, 0, this, 0); - } - _selectionModel = selectionModel; - connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - this, SLOT(currentChanged(QModelIndex, QModelIndex))); -} - void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { Q_ASSERT(model()); if(!parent.isValid()) { @@ -84,7 +67,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 +86,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 +107,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(); }