Add buffer-specific actions to ChatView's context menu
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 25 Nov 2008 23:53:56 +0000 (00:53 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 30 Nov 2008 04:24:41 +0000 (05:24 +0100)
src/qtui/chatitem.cpp
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/uisupport/bufferview.cpp

index e3e9ad7..b629a26 100644 (file)
 #include <QTextLayout>
 #include <QMenu>
 
-
+#include "bufferview.h"
 #include "chatitem.h"
 #include "chatlinemodel.h"
+#include "iconloader.h"
+#include "mainwin.h"
 #include "qtui.h"
 #include "qtuistyle.h"
 
@@ -580,13 +582,25 @@ void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) {
     switch(privateData()->currentClickable.type) {
       case Clickable::Url:
         privateData()->activeClickable = privateData()->currentClickable;
-        menu->addAction(tr("Copy Link Address"), &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
+        menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
+                         &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
         break;
 
       default:
         break;
     }
   }
+
+  // Buffer-specific actions
+  // We add these in ChatItem (rather than the scene), because they depend on the current clickable
+  if(chatScene()->isSingleBufferScene()) {
+    QModelIndex index = Client::networkModel()->bufferIndex(chatScene()->singleBufferId());
+    if(index.isValid()) {
+      menu->addSeparator();
+      QtUi::mainWindow()->allBuffersView()->addActionsToMenu(menu, index);
+    }
+  }
+
 }
 
 void ContentsChatItem::copyLinkToClipboard() {
index ae63e55..f83cfe8 100644 (file)
@@ -48,7 +48,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
     _chatView(parent),
     _idString(idString),
     _model(model),
-    _singleBufferScene(false),
+    _singleBufferId(BufferId()),
     _sceneRect(0, 0, width, 0),
     _firstLineRow(-1),
     _viewportHeight(0),
@@ -61,8 +61,8 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
     _leftButtonPressed(false)
 {
   MessageFilter *filter = qobject_cast<MessageFilter*>(model);
-  if(filter) {
-    _singleBufferScene = filter->isSingleBufferFilter();
+  if(filter && filter->isSingleBufferFilter()) {
+    _singleBufferId = filter->singleBufferId();
   }
 
   ChatViewSettings defaultSettings;
index a941fd9..41fb51a 100644 (file)
@@ -81,10 +81,11 @@ public:
 
   ChatView *chatView() const;
   ChatItem *chatItemAt(const QPointF &pos) const;
+  inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
 
-  inline bool isSingleBufferScene() const { return _singleBufferScene; }
+  inline bool isSingleBufferScene() const { return _singleBufferId.isValid(); }
+  inline BufferId singleBufferId() const { return _singleBufferId; }
   bool containsBuffer(const BufferId &id) const;
-  inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
 
   ColumnHandleItem *firstColumnHandle() const;
   ColumnHandleItem *secondColumnHandle() const;
@@ -155,7 +156,7 @@ private:
   QString _idString;
   QAbstractItemModel *_model;
   QList<ChatLine *> _lines;
-  bool _singleBufferScene;
+  BufferId _singleBufferId;
 
   // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
   // we store the size in a member variable.
index 6da7535..6ce560a 100644 (file)
@@ -399,21 +399,21 @@ QMenu *BufferView::createHideEventsSubMenu(QMenu *menu, BufferId bufferId) {
 }
 
 void BufferView::contextMenuEvent(QContextMenuEvent *event) {
-  _menuIndex = indexAt(event->pos());
-  if(!_menuIndex.isValid())
-    _menuIndex = rootIndex();
-  if(!_menuIndex.isValid())
+  QModelIndex index = indexAt(event->pos());
+  if(!index.isValid())
+    index = rootIndex();
+  if(!index.isValid())
     return;
 
   QMenu contextMenu(this);
-  addActionsToMenu(&contextMenu, _menuIndex);
+  addActionsToMenu(&contextMenu, index);
   if(!contextMenu.actions().isEmpty())
     contextMenu.exec(QCursor::pos());
 
-  _menuIndex = QModelIndex();
 }
 
 void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index) {
+  _menuIndex = index;
   const Network *network = Client::network(index.data(NetworkModel::NetworkIdRole).value<NetworkId>());
   Q_CHECK_PTR(network);