Fixing issues with moving the mouse while double/triple clicking
[quassel.git] / src / qtui / chatscene.cpp
index 9d1e04a..6e4dda1 100644 (file)
@@ -30,6 +30,7 @@
 #include "chatline.h"
 #include "chatlinemodelitem.h"
 #include "chatscene.h"
+#include "chatview.h"
 #include "client.h"
 #include "clientbacklogmanager.h"
 #include "columnhandleitem.h"
@@ -109,10 +110,6 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
   _clickTimer.setSingleShot(true);
   connect(&_clickTimer, SIGNAL(timeout()), SLOT(clickTimeout()));
 
-  _clickTimer.setInterval(QApplication::doubleClickInterval());
-  _clickTimer.setSingleShot(true);
-  connect(&_clickTimer, SIGNAL(timeout()), SLOT(clickTimeout()));
-
   setItemIndexMethod(QGraphicsScene::NoIndex);
 }
 
@@ -555,7 +552,7 @@ bool ChatScene::isPosOverSelection(const QPointF &pos) const {
   if(hasGlobalSelection()) {
     int row = chatItem->row();
     if(row >= qMin(_selectionStart, _selectionEnd) && row <= qMax(_selectionStart, _selectionEnd))
-      return true;
+      return columnByScenePos(pos) >= _selectionMinCol;
   } else {
     return chatItem->isPosOverSelection(chatItem->mapFromScene(pos));
   }
@@ -577,11 +574,20 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   QPointF pos = event->scenePos();
   QMenu menu;
 
+  // zoom actions and similar
+  chatView()->addActionsToMenu(&menu, pos);
+  menu.addSeparator();
+
   if(isPosOverSelection(pos))
     menu.addAction(SmallIcon("edit-copy"), tr("Copy Selection"),
                     this, SLOT(selectionToClipboard()),
                     QKeySequence::Copy);
 
+  // item-specific options (select link etc)
+  ChatItem *item = chatItemAt(pos);
+  if(item)
+    item->addActionsToMenu(&menu, item->mapFromScene(pos));
+
   menu.exec(event->screenPos());
 
 }
@@ -589,7 +595,8 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
 void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
   if(event->buttons() == Qt::LeftButton) {
     if(!_clickHandled && (event->scenePos() - _clickPos).toPoint().manhattanLength() >= QApplication::startDragDistance()) {
-      if(_clickTimer.isActive()) _clickTimer.stop();
+      if(_clickTimer.isActive())
+        _clickTimer.stop();
       if(_clickMode == SingleClick && isPosOverSelection(_clickPos))
         initiateDrag(event->widget());
       else {
@@ -602,7 +609,7 @@ void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
       updateSelection(event->scenePos());
       emit mouseMoveWhileSelecting(event->scenePos());
       event->accept();
-    } else if(_clickHandled)
+    } else if(_clickHandled && _clickMode < DoubleClick)
       QGraphicsScene::mouseMoveEvent(event);
   } else
     QGraphicsScene::mouseMoveEvent(event);
@@ -618,14 +625,12 @@ void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
     }
     if(_clickMode != NoClick && _clickTimer.isActive()) {
       _clickMode = (ClickMode)(_clickMode == TripleClick ? DoubleClick : _clickMode + 1);
-      handleClick(Qt::LeftButton, event->scenePos());
+      handleClick(Qt::LeftButton, _clickPos);
     } else {
       _clickMode = SingleClick;
       _clickPos = event->scenePos();
     }
     _clickTimer.start();
-  } else if(event->buttons() == Qt::RightButton) {
-    handleClick(Qt::RightButton, event->scenePos());
   }
   if(event->type() == QEvent::GraphicsSceneMouseDoubleClick)
     QGraphicsScene::mouseDoubleClickEvent(event);
@@ -693,13 +698,17 @@ void ChatScene::selectionToClipboard(QClipboard::Mode mode) {
   if(!hasSelection())
     return;
 
+  stringToClipboard(selection(), mode);
+}
+
+void ChatScene::stringToClipboard(const QString &str, QClipboard::Mode mode) {
   switch(mode) {
     case QClipboard::Clipboard:
-      QApplication::clipboard()->setText(selection());
+      QApplication::clipboard()->setText(str);
       break;
     case QClipboard::Selection:
       if(QApplication::clipboard()->supportsSelection())
-        QApplication::clipboard()->setText(selection(), QClipboard::Selection);
+        QApplication::clipboard()->setText(str, QClipboard::Selection);
       break;
     default:
       break;
@@ -766,7 +775,7 @@ void ChatScene::requestBacklog() {
   return;
 }
 
-ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) {
+ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) const {
   if(x < _firstColHandle->x())
     return ChatLineModel::TimestampColumn;
   if(x < _secondColHandle->x())
@@ -775,7 +784,7 @@ ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) {
   return ChatLineModel::ContentsColumn;
 }
 
-int ChatScene::rowByScenePos(qreal y) {
+int ChatScene::rowByScenePos(qreal y) const {
   // This is somewhat hacky... we look at the contents item that is at the given y position, since
   // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
   // ChatItems cover their ChatLine, so we won't get to the latter directly.