From 8efabae6c310d17265eaeb03df43ffe8b555a52e Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 1 Aug 2008 00:50:20 +0200 Subject: [PATCH] Deactivate selections on click --- src/qtui/chatitem.cpp | 12 +++++++++--- src/qtui/chatscene.cpp | 12 ++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 286fd62c..e0d3e221 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -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(); diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 797290d7..06713652 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -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) { -- 2.20.1