chatlinemodel.cpp
chatlinemodelitem.cpp
chatmonitorfilter.cpp
+ chatmonitorview.cpp
chatscene.cpp
chatview.cpp
columnhandleitem.cpp
channellistdlg.h
chatlinemodel.h
chatmonitorfilter.h
+ chatmonitorview.h
chatscene.h
chatview.h
columnhandleitem.h
#include "networkmodel.h"
ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
-: MessageFilter(model, QList<BufferId>(), parent)
+ : MessageFilter(model, QList<BufferId>(), parent),
+ _initTime(QDateTime::currentDateTime())
{
- _initTime = QDateTime::currentDateTime();
-
}
bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
Message::Flags flags = (Message::Flags)sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::FlagsRole).toInt();
if(!((type & (Message::Plain | Message::Notice | Message::Action)) || flags & Message::Self))
return false;
+
QDateTime msgTime = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::TimestampRole).toDateTime();
return msgTime > _initTime;
}
-QString ChatMonitorFilter::idString() const {
- return "ChatMonitor";
-}
-
// override this to inject display of network and channel
QVariant ChatMonitorFilter::data(const QModelIndex &index, int role) const {
- if(index.column() != ChatLineModel::SenderColumn) return MessageFilter::data(index, role);
- if(role == ChatLineModel::DisplayRole) {
- BufferId bufid = data(index, ChatLineModel::BufferIdRole).value<BufferId>();
- if(bufid.isValid()) {
- Buffer *buf = Client::buffer(bufid);
- if(!buf) {
- qDebug() << "invalid buffer!";
- return QVariant();
- }
- const Network *net = Client::networkModel()->networkByIndex(Client::networkModel()->bufferIndex(bufid));
- if(!net) {
- qDebug() << "invalid net!";
- return QVariant();
- }
- QString result = QString("<%1:%2:%3").arg(net->networkName())
- .arg(buf->bufferInfo().bufferName())
- .arg(MessageFilter::data(index, role).toString().mid(1));
- return result;
- }
+ if(index.column() != ChatLineModel::SenderColumn || role != ChatLineModel::DisplayRole)
+ return MessageFilter::data(index, role);
+ int showFields_ = showFields();
+
+ BufferId bufid = data(index, ChatLineModel::BufferIdRole).value<BufferId>();
+ if(!bufid.isValid()) {
+ qDebug() << "ChatMonitorFilter::data(): chatline belongs to an invalid buffer!";
+ return QVariant();
}
- return MessageFilter::data(index, role);
+
+ QStringList fields;
+ if(showFields_ & NetworkField) {
+ fields << Client::networkModel()->networkName(bufid);
+ }
+ if(showFields_ & BufferField) {
+ fields << Client::networkModel()->bufferName(bufid);
+ }
+ fields << MessageFilter::data(index, role).toString().mid(1);
+ return QString("<%1").arg(fields.join(":"));
+}
+
+void ChatMonitorFilter::addShowField(int field) {
+ QtUiSettings s;
+ int fields = s.value(showFieldSettingId(), AllFields).toInt();
+ if(fields & field)
+ return;
+ fields |= field;
+ s.setValue(showFieldSettingId(), fields);
+ showFieldSettingsChanged();
}
+
+void ChatMonitorFilter::removeShowField(int field) {
+ QtUiSettings s;
+ int fields = s.value(showFieldSettingId(), AllFields).toInt();
+ if(!(fields & field))
+ return;
+
+ fields ^= field;
+ s.setValue(showFieldSettingId(), fields);
+ showFieldSettingsChanged();
+}
+
+void ChatMonitorFilter::showFieldSettingsChanged() {
+ int rows = rowCount();
+ if(rows == 0)
+ return;
+
+ emit dataChanged(index(0, ChatLineModel::SenderColumn), index(rows - 1, ChatLineModel::SenderColumn));
+}
+
#include <QDateTime>
#include "messagefilter.h"
+#include "qtuisettings.h"
class ChatMonitorFilter : public MessageFilter {
Q_OBJECT
- public:
- ChatMonitorFilter(MessageModel *model, QObject *parent = 0);
+public:
+ enum SenderFields {
+ NoField = 0x00,
+ NetworkField = 0x01,
+ BufferField = 0x02,
+ SenderField = 0x04,
+ AllFields = 0xFF
+ };
- virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
- virtual QString idString() const;
+ ChatMonitorFilter(MessageModel *model, QObject *parent = 0);
- virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ virtual QString idString() const { return "ChatMonitor"; }
+ virtual QVariant data(const QModelIndex &index, int role) const;
- private:
- QDateTime _initTime;
+ inline QString showFieldSettingId() const { return QString("ChatView/%1/showFields").arg(idString()); }
+ inline int showFields() const { return QtUiSettings().value(showFieldSettingId(), AllFields).toInt(); }
+ void addShowField(int field);
+ void removeShowField(int field);
+
+private:
+ QDateTime _initTime;
+
+ void showFieldSettingsChanged();
};
#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel Project *
+ * 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 "chatmonitorview.h"
+
+#include <QAction>
+#include <QMenu>
+#include <QContextMenuEvent>
+
+#include "chatmonitorfilter.h"
+#include "chatlinemodel.h"
+#include "chatscene.h"
+#include "qtuisettings.h"
+
+ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent)
+ : ChatView(filter, parent),
+ _filter(filter)
+{
+}
+
+void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
+ if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn)
+ return;
+
+ int showFields = _filter->showFields();
+
+ QMenu contextMenu(this);
+ QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
+ showNetworkAction->setCheckable(true);
+ showNetworkAction->setChecked(showFields & ChatMonitorFilter::NetworkField);
+ showNetworkAction->setData(ChatMonitorFilter::NetworkField);
+
+ QAction *showBufferAction = contextMenu.addAction(tr("Show buffer name"), this, SLOT(showFieldsChanged(bool)));
+ showBufferAction->setCheckable(true);
+ showBufferAction->setChecked(showFields & ChatMonitorFilter::BufferField);
+ showBufferAction->setData(ChatMonitorFilter::BufferField);
+
+ contextMenu.exec(QCursor::pos());
+}
+
+void ChatMonitorView::showFieldsChanged(bool checked) {
+ QAction *showAction = qobject_cast<QAction *>(sender());
+ if(!showAction)
+ return;
+
+ if(checked)
+ _filter->addShowField(showAction->data().toInt());
+ else
+ _filter->removeShowField(showAction->data().toInt());
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel Project *
+ * 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 CHATMONITORVIEW_H
+#define CHATMONITORVIEW_H
+
+#include "chatview.h"
+
+class ChatMonitorFilter;
+
+class ChatMonitorView : public ChatView {
+ Q_OBJECT
+
+public:
+ ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent);
+
+protected:
+ virtual void contextMenuEvent(QContextMenuEvent *event);
+
+private slots:
+ void showFieldsChanged(bool checked);
+
+private:
+ ChatMonitorFilter *_filter;
+};
+
+#endif //CHATMONITORVIEW_H
_lastBacklogSize = model()->rowCount();
}
}
+
+int ChatScene::sectionByScenePos(int x) {
+ if(x < firstColHandlePos)
+ return ChatLineModel::TimestampColumn;
+ if(x < secondColHandlePos)
+ return ChatLineModel::SenderColumn;
+
+ return ChatLineModel::ContentsColumn;
+}
inline bool isFetchingBacklog() const;
inline bool isBacklogFetchingEnabled() const;
inline BufferId bufferForBacklogFetching() const;
+ int sectionByScenePos(int x);
+ inline int sectionByScenePos(const QPoint &pos) { return sectionByScenePos(pos.x()); }
public slots:
void setWidth(qreal);
#include "messagefilter.h"
#include "quasselui.h"
-ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
+ChatView::ChatView(Buffer *buf, QWidget *parent)
+ : QGraphicsView(parent),
+ AbstractChatView()
+{
QList<BufferId> filterList;
filterList.append(buf->bufferInfo().bufferId());
MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this);
}
-ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
+ChatView::ChatView(MessageFilter *filter, QWidget *parent)
+ : QGraphicsView(parent),
+ AbstractChatView()
+{
init(filter);
}
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
}
-ChatView::~ChatView() {
-
-}
-
-ChatScene *ChatView::scene() const {
- return _scene;
-}
-
-void ChatView::clear() {
-
-}
-
void ChatView::resizeEvent(QResizeEvent *event) {
scene()->setWidth(event->size().width() - 2); // FIXME figure out why we have to hardcode the -2 here
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
class ChatView : public QGraphicsView, public AbstractChatView {
Q_OBJECT
- public:
- ChatView(MessageFilter *, QWidget *parent = 0);
- ChatView(Buffer *, QWidget *parent = 0);
- ~ChatView();
+public:
+ ChatView(MessageFilter *, QWidget *parent = 0);
+ ChatView(Buffer *, QWidget *parent = 0);
- ChatScene *scene() const;
+ inline ChatScene *scene() const { return _scene; }
- public slots:
+public slots:
+ inline virtual void clear() {}
+ void setBufferForBacklogFetching(BufferId buffer);
- void clear();
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
- void setBufferForBacklogFetching(BufferId buffer);
+protected slots:
+ virtual void sceneHeightChanged(qreal height);
+ virtual void verticalScrollbarChanged(int);
+ virtual void sliderPressed();
+ virtual void sliderReleased();
+
+private:
+ void init(MessageFilter *filter);
- protected:
- virtual void resizeEvent(QResizeEvent *event);
-
- protected slots:
- virtual void sceneHeightChanged(qreal height);
- virtual void verticalScrollbarChanged(int);
- virtual void sliderPressed();
- virtual void sliderReleased();
-
- private:
- void init(MessageFilter *filter);
-
- ChatScene *_scene;
+ ChatScene *_scene;
};
#include "channellistdlg.h"
#include "chatlinemodel.h"
#include "chatmonitorfilter.h"
+#include "chatmonitorview.h"
#include "chatview.h"
#include "client.h"
#include "clientbacklogmanager.h"
dock->setObjectName("ChatMonitorDock");
ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
- ChatView *chatView = new ChatView(filter, this);
+ ChatMonitorView *chatView = new ChatMonitorView(filter, this);
chatView->show();
dock->setWidget(chatView);
dock->show();