From db511df7b183771ae444f14d0aca42381ee0ae37 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 26 Nov 2008 00:53:56 +0100 Subject: [PATCH] Add buffer-specific actions to ChatView's context menu --- src/qtui/chatitem.cpp | 18 ++++++++++++++++-- src/qtui/chatscene.cpp | 6 +++--- src/qtui/chatscene.h | 7 ++++--- src/uisupport/bufferview.cpp | 12 ++++++------ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index e3e9ad74..b629a263 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -28,9 +28,11 @@ #include #include - +#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(this)); + menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"), + &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue(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() { diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index ae63e550..f83cfe81 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -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(model); - if(filter) { - _singleBufferScene = filter->isSingleBufferFilter(); + if(filter && filter->isSingleBufferFilter()) { + _singleBufferId = filter->singleBufferId(); } ChatViewSettings defaultSettings; diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index a941fd90..41fb51a9 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -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 _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. diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 6da75355..6ce560aa 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -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()); Q_CHECK_PTR(network); -- 2.20.1