us to move most of the former BufferWidget logic into uisupport, thus reducing code duplication.
It also allows us to switch between ChatWidget and ChatView more easily.
QVariant BufferSettings::value(const QString &key, const QVariant &def) {
return localValue(key, def);
-}
\ No newline at end of file
+}
***************************************************************************/
#include "bufferwidget.h"
-#include "buffer.h"
#include "chatline.h"
#include "chatline-old.h"
+#include "chatview.h"
#include "chatwidget.h"
#include "settings.h"
#include "client.h"
-#include "identity.h"
-#include "network.h"
-#include "networkmodel.h"
#include "global.h"
-BufferWidget::BufferWidget(QWidget *parent)
- : AbstractItemView(parent),
- _currentBuffer(0)
-{
+BufferWidget::BufferWidget(QWidget *parent) : AbstractBufferContainer(parent) {
ui.setupUi(this);
}
BufferWidget::~BufferWidget() {
-}
-void BufferWidget::init() {
}
-void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
- Q_ASSERT(model());
- if(!parent.isValid()) {
- // ok this means that whole networks are about to be removed
- // we can't determine which buffers are affect, so we hope that all nets are removed
- // this is the most common case (for example disconnecting from the core or terminating the clint)
- if(model()->rowCount(parent) != end - start + 1)
- return;
-
- ChatWidget *chatWidget;
- QHash<BufferId, ChatWidget *>::iterator iter = _chatWidgets.begin();
- while(iter != _chatWidgets.end()) {
- chatWidget = *iter;
- iter = _chatWidgets.erase(iter);
- ui.stackedWidget->removeWidget(chatWidget);
- chatWidget->deleteLater();
- }
-
+AbstractChatView *BufferWidget::createChatView(BufferId id) {
+ AbstractChatView *chatView;
+ if(Global::SPUTDEV) {
+ chatView = new ChatView(Client::buffer(id), this);
} else {
- // check if there are explicitly buffers removed
- for(int i = start; i <= end; i++) {
- QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole);
- if(!variant.isValid())
- continue;
-
- BufferId bufferId = qVariantValue<BufferId>(variant);
- removeBuffer(bufferId);
- }
+ chatView = new ChatWidget(id, this);
}
+ ui.stackedWidget->addWidget(dynamic_cast<QWidget *>(chatView));
+ dynamic_cast<QWidget *>(chatView)->setFocusProxy(this);
+ return chatView;
}
-void BufferWidget::removeBuffer(BufferId bufferId) {
- if(!_chatWidgets.contains(bufferId))
- return;
-
- if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
- ChatWidget *chatWidget = _chatWidgets.take(bufferId);
- ui.stackedWidget->removeWidget(chatWidget);
- chatWidget->deleteLater();
-}
-
-void BufferWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
- BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
- BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
- if(newBufferId != oldBufferId)
- setCurrentBuffer(newBufferId);
+void BufferWidget::removeChatView(AbstractChatView *view) {
+ ui.stackedWidget->removeWidget(dynamic_cast<QWidget *>(view));
+ dynamic_cast<QWidget *>(view)->deleteLater();
}
-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;
- return;
- }
- Buffer *prevBuffer = Client::buffer(currentBuffer());
- if(prevBuffer) prevBuffer->setVisible(false);
- if(Global::SPUTDEV) {
- if(_chatViews.contains(bufferId)) {
- chatView = _chatViews[bufferId];
- } else {
- chatView = new ChatView(buf, this);
- //chatView->init(bufferId);
- QList<ChatLine *> lines;
- QList<AbstractUiMsg *> msgs = buf->contents();
- foreach(AbstractUiMsg *msg, msgs) {
- lines.append(dynamic_cast<ChatLine *>(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 {
- if(_chatWidgets.contains(bufferId)) {
- chatWidget = _chatWidgets[bufferId];
- } else {
- chatWidget = new ChatWidget(this);
- chatWidget->init(bufferId);
- QList<ChatLineOld *> lines;
- QList<AbstractUiMsg *> msgs = buf->contents();
- foreach(AbstractUiMsg *msg, msgs) {
- lines.append(dynamic_cast<ChatLineOld*>(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);
- }
- _currentBuffer = bufferId;
- ui.stackedWidget->setCurrentWidget(chatWidget);
- }
- buf->setVisible(true);
- setFocus();
+void BufferWidget::showChatView(AbstractChatView *view) {
+ if(!view) ui.stackedWidget->setCurrentWidget(ui.page);
+ else ui.stackedWidget->setCurrentWidget(dynamic_cast<QWidget *>(view));
}
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#ifndef _BUFFERWIDGET_H_
-#define _BUFFERWIDGET_H_
+#ifndef BUFFERWIDGET_H_
+#define BUFFERWIDGET_H_
#include "ui_bufferwidget.h"
-#include "abstractitemview.h"
-#include "chatview.h"
-#include "types.h"
+#include "abstractbuffercontainer.h"
-class Network;
-class ChatView;
-class ChatWidget;
-
-#include "buffermodel.h"
-
-//! Displays the contents of a Buffer.
-/**
-*/
-class BufferWidget : public AbstractItemView {
+class BufferWidget : public AbstractBufferContainer {
Q_OBJECT
-public:
- BufferWidget(QWidget *parent = 0);
- virtual ~BufferWidget();
- void init();
+ public:
+ BufferWidget(QWidget *parent);
+ virtual ~BufferWidget();
- inline BufferId currentBuffer() const { return _currentBuffer; }
-
-protected slots:
- virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
- virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+ protected:
+ virtual AbstractChatView *createChatView(BufferId);
+ virtual void removeChatView(AbstractChatView *view);
-private slots:
- void removeBuffer(BufferId bufferId);
- void setCurrentBuffer(BufferId bufferId);
+ protected slots:
+ virtual void showChatView(AbstractChatView *view);
-private:
- Ui::BufferWidget ui;
- QHash<BufferId, ChatWidget *> _chatWidgets;
- QHash<BufferId, ChatView *> _chatViews;
+ private:
+ Ui::BufferWidget ui;
- BufferId _currentBuffer;
};
#endif
#include "chatview.h"
#include "quasselui.h"
-ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent) {
+ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
_scene = new ChatScene(buf, this);
setScene(_scene);
}
}
-void ChatView::setContents(QList<ChatLine *> list) {
+void ChatView::setContents(const QList<AbstractUiMsg *> &list) {
qDebug() << "setting" << list.count();
- appendChatLines(list);
+ //appendChatLines(list);
}
#include <QGraphicsView>
+#include "abstractbuffercontainer.h"
+
class AbstractUiMsg;
class Buffer;
class ChatLine;
class ChatScene;
-class ChatView : public QGraphicsView {
+class ChatView : public QGraphicsView, public AbstractChatView {
Q_OBJECT
public:
void prependChatLines(QList<ChatLine *>);
void appendChatLines(QList<ChatLine *>);
- void setContents(QList<ChatLine *>);
+ void setContents(const QList<AbstractUiMsg *> &);
private:
ChatScene *_scene;
#include "buffer.h"
#include "clientbacklogmanager.h"
-ChatWidget::ChatWidget(QWidget *parent)
- : QAbstractScrollArea(parent),
+ChatWidget::ChatWidget(BufferId bufid, QWidget *parent) : QAbstractScrollArea(parent), AbstractChatView(),
lastBacklogOffset(0),
lastBacklogSize(0)
{
pointerPosition = QPoint(0,0);
connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(scrollBarAction(int)));
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrollBarValChanged(int)));
+
+ init(bufid);
}
void ChatWidget::init(BufferId id) {
viewport()->update();
}
-void ChatWidget::setContents(QList<ChatLineOld *> list) {
+void ChatWidget::setContents(const QList<AbstractUiMsg *> &list) {
ycoords.clear();
ycoords.append(0);
height = 0;
lines.clear();
- appendChatLines(list);
+ QList<ChatLineOld *> cl;
+ foreach(AbstractUiMsg *msg, list) cl << dynamic_cast<ChatLineOld *>(msg);
+ appendChatLines(cl);
}
//!\brief Computes the different x position vars for given tsWidth and senderWidth.
#include <QtGui>
+#include "abstractbuffercontainer.h"
#include "types.h"
class ChatLineOld;
* Because we use this as a custom widget in Qt Designer, we cannot use a constructor that takes custom
* parameters. Instead, it is mandatory to call init() before using this widget.
*/
-class ChatWidget : public QAbstractScrollArea {
+class ChatWidget : public QAbstractScrollArea, public AbstractChatView {
Q_OBJECT
public:
- ChatWidget(QWidget *parent = 0);
+ ChatWidget(BufferId, QWidget *parent = 0);
~ChatWidget();
void init(BufferId id);
void appendChatLine(ChatLineOld *);
void prependChatLines(QList<ChatLineOld *>);
void appendChatLines(QList<ChatLineOld *>);
- void setContents(QList<ChatLineOld *>);
+ void setContents(const QList<AbstractUiMsg *> &);
protected:
virtual void resizeEvent(QResizeEvent *event);
connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
- ui.bufferWidget->init();
+ //ui.bufferWidget->init();
show();
VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
dock->setObjectName("ChatMonitorDock");
- ChatWidget *chatWidget = new ChatWidget(this);
+ ChatWidget *chatWidget = new ChatWidget(0, this);
chatWidget->show();
dock->setWidget(chatWidget);
dock->show();
if(!buf)
return;
- chatWidget->init(BufferId(0));
- QList<ChatLineOld *> lines;
- QList<AbstractUiMsg *> msgs = buf->contents();
- foreach(AbstractUiMsg *msg, msgs) {
- lines.append(dynamic_cast<ChatLineOld*>(msg));
- }
- chatWidget->setContents(lines);
+ chatWidget->setContents(buf->contents());
connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "abstractbuffercontainer.h"
+#include "buffer.h"
+#include "client.h"
+#include "networkmodel.h"
+
+AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) : AbstractItemView(parent), _currentBuffer(0)
+{
+
+}
+
+AbstractBufferContainer::~AbstractBufferContainer() {
+
+}
+
+
+void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
+ Q_ASSERT(model());
+ if(!parent.isValid()) {
+ // ok this means that whole networks are about to be removed
+ // we can't determine which buffers are affect, so we hope that all nets are removed
+ // this is the most common case (for example disconnecting from the core or terminating the client)
+ if(model()->rowCount(parent) != end - start + 1)
+ return;
+
+ AbstractChatView *chatView;
+ QHash<BufferId, AbstractChatView *>::iterator iter = _chatViews.begin();
+ while(iter != _chatViews.end()) {
+ chatView = *iter;
+ iter = _chatViews.erase(iter);
+ removeChatView(chatView);
+ }
+ } else {
+ // check if there are explicitly buffers removed
+ for(int i = start; i <= end; i++) {
+ QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole);
+ if(!variant.isValid())
+ continue;
+
+ BufferId bufferId = variant.value<BufferId>();
+ removeBuffer(bufferId);
+ }
+ }
+}
+
+void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
+ if(!_chatViews.contains(bufferId))
+ return;
+
+ if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
+ AbstractChatView *chatView = _chatViews.take(bufferId);
+ removeChatView(chatView);
+}
+
+void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
+ BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
+ if(newBufferId != oldBufferId)
+ setCurrentBuffer(newBufferId);
+}
+
+void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
+ if(!bufferId.isValid()) {
+ showChatView(0);
+ return;
+ }
+
+ AbstractChatView *chatView = 0;
+ Buffer *buf = Client::buffer(bufferId);
+ if(!buf) {
+ qWarning() << "AbstractBufferContainer::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
+ return;
+ }
+ Buffer *prevBuffer = Client::buffer(currentBuffer());
+ if(prevBuffer) prevBuffer->setVisible(false);
+ if(_chatViews.contains(bufferId)) {
+ chatView = _chatViews[bufferId];
+ } else {
+ chatView = createChatView(bufferId);
+ chatView->setContents(buf->contents());
+ connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), this, SLOT(appendMsg(AbstractUiMsg *)));
+ connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), this, SLOT(prependMsg(AbstractUiMsg *)));
+ _chatViews[bufferId] = chatView;
+ }
+ _currentBuffer = bufferId;
+ showChatView(chatView);
+ buf->setVisible(true);
+ setFocus();
+}
+
+void AbstractBufferContainer::appendMsg(AbstractUiMsg *msg) {
+ Buffer *buf = qobject_cast<Buffer *>(sender());
+ if(!buf) {
+ qWarning() << "AbstractBufferContainer::appendMsg(): Invalid slot caller!";
+ return;
+ }
+ BufferId id = buf->bufferInfo().bufferId();
+ if(!_chatViews.contains(id)) {
+ qWarning() << "AbstractBufferContainer::appendMsg(): Received message for unknown buffer!";
+ return;
+ }
+ _chatViews[id]->appendMsg(msg);
+}
+
+void AbstractBufferContainer::prependMsg(AbstractUiMsg *msg) {
+ Buffer *buf = qobject_cast<Buffer *>(sender());
+ if(!buf) {
+ qWarning() << "AbstractBufferContainer:prependMsg(): Invalid slot caller!";
+ return;
+ }
+ BufferId id = buf->bufferInfo().bufferId();
+ if(!_chatViews.contains(id)) {
+ qWarning() << "AbstractBufferContainer::prependMsg(): Received message for unknown buffer!";
+ return;
+ }
+ _chatViews[id]->prependMsg(msg);
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef ABSTRACTBUFFERCONTAINER_H_
+#define ABSTRACTBUFFERCONTAINER_H_
+
+#include "abstractitemview.h"
+#include "buffermodel.h"
+
+class AbstractChatView;
+class AbstractUiMsg;
+class Buffer;
+
+class AbstractBufferContainer : public AbstractItemView {
+ Q_OBJECT
+
+ public:
+ AbstractBufferContainer(QWidget *parent);
+ virtual ~AbstractBufferContainer();
+
+ inline BufferId currentBuffer() const { return _currentBuffer; }
+
+ protected:
+ //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary
+ virtual AbstractChatView *createChatView(BufferId) = 0;
+
+ //! Remove a chat view from the UI and delete it
+ /** This method shall remove the view from the UI (for example, from a QStackedWidget) if appropriate.
+ * It also shall delete the object afterwards.
+ * \param view The chat view to be removed and deleted
+ */
+ virtual void removeChatView(AbstractChatView *view) = 0;
+
+ protected slots:
+ virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
+ virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+
+ //! Show the given chat view
+ /** This method is called when the given chat view should be displayed. Use this e.g. for
+ * selecting the appropriate page in a QStackedWidget.
+ * \param view The chat view to be displayed. May be 0 if no chat view is selected.
+ */
+ virtual void showChatView(AbstractChatView *view) = 0;
+
+ private slots:
+ void appendMsg(AbstractUiMsg *);
+ void prependMsg(AbstractUiMsg *);
+ void removeBuffer(BufferId bufferId);
+ void setCurrentBuffer(BufferId bufferId);
+
+ private:
+ BufferId _currentBuffer;
+ QHash<BufferId, AbstractChatView *> _chatViews;
+};
+
+class AbstractChatView {
+
+ public:
+ virtual void appendMsg(AbstractUiMsg *msg) = 0;
+ virtual void prependMsg(AbstractUiMsg *msg) = 0;
+ virtual void setContents(const QList<AbstractUiMsg *> &contents) = 0;
+
+};
+
+#endif
network->requestDisconnect();
} else
if(result == joinChannelAction) {
+ // FIXME no QInputDialog in Qtopia
+#ifndef Q_WS_QWS
bool ok;
QString channelName = QInputDialog::getText(this, tr("Join Channel"),
tr("Input channel name:"),QLineEdit::Normal,
QDir::home().dirName(), &ok);
+
if (ok && !channelName.isEmpty()) {
BufferInfo bufferInfo = index.child(0,0).data(NetworkModel::BufferInfoRole).value<BufferInfo>();
if(bufferInfo.isValid()) {
Client::instance()->userInput(bufferInfo, QString("/J %1").arg(channelName));
}
}
+#endif
} else
if(result == joinBufferAction) {
Client::instance()->userInput(bufferInfo, QString("/JOIN %1").arg(channelname));
{
clearButton = new QToolButton(this);
clearButton->setIcon(QIcon(":/22x22/actions/oxygen/22x22/actions/edit-clear-locationbar-rtl.png"));
+#ifndef Q_WS_QWS
clearButton->setCursor(Qt::ArrowCursor);
+#endif
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
clearButton->hide();
DEPMOD = common client
QT_MOD = core gui network
-SRCS += abstractitemview.cpp bufferview.cpp bufferviewfilter.cpp clearablelineedit.cpp colorbutton.cpp nickviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp uistylesettings.cpp
-HDRS += abstractitemview.h bufferview.h bufferviewfilter.h clearablelineedit.h colorbutton.h nickviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h uistylesettings.h
+SRCS += abstractbuffercontainer.cpp abstractitemview.cpp bufferview.cpp bufferviewfilter.cpp clearablelineedit.cpp colorbutton.cpp \
+ nickviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp uistylesettings.cpp
+HDRS += abstractbuffercontainer.h abstractitemview.h bufferview.h bufferviewfilter.h clearablelineedit.h colorbutton.h \
+ nickviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h uistylesettings.h
FORMNAMES =
{ using namespace Global;
quasselVersion = "0.2.0-alpha4-pre";
- quasselDate = "2008-03-21";
- quasselBuild = 655;
+ quasselDate = "2008-03-25";
+ quasselBuild = 657;
//! Minimum client build number the core needs
clientBuildNeeded = 642;