Deactivate selections on click
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 31 Jul 2008 22:50:20 +0000 (00:50 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Aug 2008 13:17:11 +0000 (15:17 +0200)
src/qtui/chatitem.cpp
src/qtui/chatscene.cpp

index 286fd62..e0d3e22 100644 (file)
@@ -197,9 +197,15 @@ void ChatItem::continueSelecting(const QPointF &pos) {
 
 void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
   if(event->buttons() & Qt::LeftButton) {
-    chatScene()->setSelectingItem(this);  // removes earlier selection if exists
-    _selectionStart = _selectionEnd = posToCursor(event->pos());
-    _selectionMode = PartialSelection;
+    if(_selectionMode == NoSelection) {
+      chatScene()->setSelectingItem(this);  // removes earlier selection if exists
+      _selectionStart = _selectionEnd = posToCursor(event->pos());
+      _selectionMode = PartialSelection;
+    } else {
+      chatScene()->setSelectingItem(0);
+      _selectionMode = NoSelection;
+      update();
+    }
     event->accept();
   } else {
     event->ignore();
index 797290d..0671365 100644 (file)
@@ -39,6 +39,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject
   _width = 0;
   _selectingItem = 0;
   _isSelecting = false;
+  _selectionStart = -1;
   connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &)));
 
   connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
@@ -211,8 +212,15 @@ void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 }
 
 void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
-  qDebug() << "pressed";
-  QGraphicsScene::mousePressEvent(event);
+  if(event->buttons() & Qt::LeftButton && _selectionStart >= 0) {
+    for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++) {
+      _lines[l]->setSelected(false);
+    }
+    _selectionStart = -1;
+    event->accept();
+  } else {
+    QGraphicsScene::mousePressEvent(event);
+  }
 }
 
 void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {