fixing BR #261 (making fields removable from the chatmonitor). Changes effect current...
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 11 Aug 2008 11:28:47 +0000 (13:28 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 11 Aug 2008 12:03:54 +0000 (14:03 +0200)
src/qtui/CMakeLists.txt
src/qtui/chatmonitorfilter.cpp
src/qtui/chatmonitorfilter.h
src/qtui/chatmonitorview.cpp [new file with mode: 0644]
src/qtui/chatmonitorview.h [new file with mode: 0644]
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/chatview.h
src/qtui/mainwin.cpp

index 670cda3..f128985 100644 (file)
@@ -14,6 +14,7 @@ set(SOURCES
     chatlinemodel.cpp
     chatlinemodelitem.cpp
     chatmonitorfilter.cpp
     chatlinemodel.cpp
     chatlinemodelitem.cpp
     chatmonitorfilter.cpp
+    chatmonitorview.cpp
     chatscene.cpp
     chatview.cpp
     columnhandleitem.cpp
     chatscene.cpp
     chatview.cpp
     columnhandleitem.cpp
@@ -43,6 +44,7 @@ set(MOC_HDRS
     channellistdlg.h
     chatlinemodel.h
     chatmonitorfilter.h
     channellistdlg.h
     chatlinemodel.h
     chatmonitorfilter.h
+    chatmonitorview.h
     chatscene.h
     chatview.h
     columnhandleitem.h
     chatscene.h
     chatview.h
     columnhandleitem.h
index 9c7082b..d11378d 100644 (file)
 #include "networkmodel.h"
 
 ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
 #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 {
 }
 
 bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
@@ -38,37 +37,62 @@ bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
   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;
   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;
 }
 
   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 {
 // 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));
+}
+
index 782797f..a27d3e5 100644 (file)
 #include <QDateTime>
 
 #include "messagefilter.h"
 #include <QDateTime>
 
 #include "messagefilter.h"
+#include "qtuisettings.h"
 
 class ChatMonitorFilter : public MessageFilter {
   Q_OBJECT
 
 
 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
 };
 
 #endif
diff --git a/src/qtui/chatmonitorview.cpp b/src/qtui/chatmonitorview.cpp
new file mode 100644 (file)
index 0000000..6b9fe60
--- /dev/null
@@ -0,0 +1,67 @@
+/***************************************************************************
+ *   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());    
+}
diff --git a/src/qtui/chatmonitorview.h b/src/qtui/chatmonitorview.h
new file mode 100644 (file)
index 0000000..bf0b334
--- /dev/null
@@ -0,0 +1,44 @@
+/***************************************************************************
+ *   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
index a6578fa..aeac420 100644 (file)
@@ -305,3 +305,12 @@ void ChatScene::requestBacklogIfNeeded() {
     _lastBacklogSize = model()->rowCount();
   }
 }
     _lastBacklogSize = model()->rowCount();
   }
 }
+
+int ChatScene::sectionByScenePos(int x) {
+  if(x < firstColHandlePos)
+    return ChatLineModel::TimestampColumn;
+  if(x < secondColHandlePos)
+    return ChatLineModel::SenderColumn;
+
+  return ChatLineModel::ContentsColumn;
+}
index e72308e..c69f0e1 100644 (file)
@@ -49,6 +49,8 @@ class ChatScene : public QGraphicsScene {
     inline bool isFetchingBacklog() const;
     inline bool isBacklogFetchingEnabled() const;
     inline BufferId bufferForBacklogFetching() const;
     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);
 
   public slots:
     void setWidth(qreal);
index 6d4e5ea..dbddaaa 100644 (file)
 #include "messagefilter.h"
 #include "quasselui.h"
 
 #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);
   QList<BufferId> filterList;
   filterList.append(buf->bufferInfo().bufferId());
   MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this);
@@ -37,7 +40,10 @@ ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), Abstra
 
 }
 
 
 }
 
-ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
+ChatView::ChatView(MessageFilter *filter, QWidget *parent)
+  : QGraphicsView(parent),
+    AbstractChatView()
+{
   init(filter);
 }
 
   init(filter);
 }
 
@@ -55,18 +61,6 @@ void ChatView::init(MessageFilter *filter) {
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
 }
 
   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());
 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());
index b9c1892..6da995e 100644 (file)
@@ -34,32 +34,29 @@ class MessageFilter;
 class ChatView : public QGraphicsView, public AbstractChatView {
   Q_OBJECT
 
 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;
 };
 
 
 };
 
 
index 6c8628a..9d0de30 100644 (file)
@@ -27,6 +27,7 @@
 #include "channellistdlg.h"
 #include "chatlinemodel.h"
 #include "chatmonitorfilter.h"
 #include "channellistdlg.h"
 #include "chatlinemodel.h"
 #include "chatmonitorfilter.h"
+#include "chatmonitorview.h"
 #include "chatview.h"
 #include "client.h"
 #include "clientbacklogmanager.h"
 #include "chatview.h"
 #include "client.h"
 #include "clientbacklogmanager.h"
@@ -295,7 +296,7 @@ void MainWin::setupChatMonitor() {
   dock->setObjectName("ChatMonitorDock");
 
   ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
   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();
   chatView->show();
   dock->setWidget(chatView);
   dock->show();