Fix doubleclicks in empty spaces in ChatMonitorView as well, thanks al_!
[quassel.git] / src / qtui / chatmonitorview.cpp
index 6b9fe60..3f31591 100644 (file)
 
 #include "chatmonitorfilter.h"
 #include "chatlinemodel.h"
+#include "chatitem.h"
 #include "chatscene.h"
+#include "client.h"
+#include "networkmodel.h"
+#include "buffermodel.h"
+#include "messagemodel.h"
 #include "qtuisettings.h"
 
 ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent)
@@ -38,7 +43,7 @@ ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent)
 void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
   if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn)
     return;
-  
+
   int showFields = _filter->showFields();
 
   QMenu contextMenu(this);
@@ -46,7 +51,7 @@ void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
   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);
@@ -55,6 +60,30 @@ void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
   contextMenu.exec(QCursor::pos());
 }
 
+void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent *event) {
+  if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn) {
+    ChatView::mouseDoubleClickEvent(event);
+    return;
+  }
+
+  ChatItem *chatItem = dynamic_cast<ChatItem *>(itemAt(event->pos()));
+  if(!chatItem) {
+    event->ignore();
+    return;
+  }
+
+  event->accept();
+  BufferId bufferId = chatItem->data(MessageModel::BufferIdRole).value<BufferId>();
+  if(!bufferId.isValid())
+    return;
+
+  QModelIndex bufferIdx = Client::networkModel()->bufferIndex(bufferId);
+  if(!bufferIdx.isValid())
+    return;
+
+  Client::bufferModel()->setCurrentIndex(Client::bufferModel()->mapFromSource(bufferIdx));
+}
+
 void ChatMonitorView::showFieldsChanged(bool checked) {
   QAction *showAction = qobject_cast<QAction *>(sender());
   if(!showAction)
@@ -63,5 +92,5 @@ void ChatMonitorView::showFieldsChanged(bool checked) {
   if(checked)
     _filter->addShowField(showAction->data().toInt());
   else
-    _filter->removeShowField(showAction->data().toInt());    
+    _filter->removeShowField(showAction->data().toInt());
 }