From: Manuel Nickschas Date: Mon, 11 Aug 2008 21:56:45 +0000 (+0200) Subject: Rework selections to make them not fail with weird button combinations X-Git-Tag: 0.3.0~55 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=16192b6fb8ddce1f3c1202eef709edc45e0e2c27 Rework selections to make them not fail with weird button combinations --- diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 655d1fd3..7a11a665 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -239,7 +239,7 @@ void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(_selectionMode != NoSelection && event->buttons() == Qt::LeftButton) { + if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) { _selectionEnd = posToCursor(event->pos()); QString selection = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd)); diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 1af7e850..7ba7d392 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -179,7 +179,7 @@ void ChatScene::setSelectingItem(ChatItem *item) { } void ChatScene::startGlobalSelection(ChatItem *item, const QPointF &itemPos) { - _selectionStart = _selectionEnd = item->row(); + _selectionStart = _selectionEnd = _lastSelectionRow = _firstSelectionRow = item->row(); _selectionStartCol = _selectionMinCol = item->column(); _isSelecting = true; _lines[_selectionStart]->setSelected(true, (ChatLineModel::ColumnType)_selectionMinCol); @@ -206,26 +206,31 @@ void ChatScene::updateSelection(const QPointF &pos) { } } - if(curRow > _selectionEnd && curRow > _selectionStart) { // select further towards bottom - for(int l = _selectionEnd + 1; l <= curRow; l++) { + int newstart = qMin(curRow, _firstSelectionRow); + int newend = qMax(curRow, _firstSelectionRow); + + if(newstart < _selectionStart) { + for(int l = newstart; l < _selectionStart; l++) _lines[l]->setSelected(true, minColumn); - } - } else if(curRow > _selectionEnd && curRow <= _selectionStart) { // deselect towards bottom - for(int l = _selectionEnd; l < curRow; l++) { - _lines[l]->setSelected(false); - } - } else if(curRow < _selectionEnd && curRow >= _selectionStart) { - for(int l = _selectionEnd; l > curRow; l--) { + } + if(newstart > _selectionStart) { + for(int l = _selectionStart; l < newstart; l++) _lines[l]->setSelected(false); - } - } else if(curRow < _selectionEnd && curRow < _selectionStart) { - for(int l = _selectionEnd - 1; l >= curRow; l--) { + } + if(newend > _selectionEnd) { + for(int l = _selectionEnd+1; l <= newend; l++) _lines[l]->setSelected(true, minColumn); - } } - _selectionEnd = curRow; + if(newend < _selectionEnd) { + for(int l = newend+1; l <= _selectionEnd; l++) + _lines[l]->setSelected(false); + } + + _selectionStart = newstart; + _selectionEnd = newend; + _lastSelectionRow = curRow; - if(curRow == _selectionStart && minColumn == ChatLineModel::ContentsColumn) { + if(newstart == newend && minColumn == ChatLineModel::ContentsColumn) { _lines[curRow]->setSelected(false); _isSelecting = false; _selectingItem->continueSelecting(_selectingItem->mapFromScene(pos)); @@ -254,7 +259,7 @@ void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { } void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(_isSelecting && event->buttons() == Qt::LeftButton) { + if(_isSelecting && !event->buttons() & Qt::LeftButton) { # ifdef Q_WS_X11 QApplication::clipboard()->setText(selectionToString(), QClipboard::Selection); # endif diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index de6add9c..17c009c8 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -97,6 +97,7 @@ class ChatScene : public QGraphicsScene { int _selectionStartCol, _selectionMinCol; int _selectionStart; int _selectionEnd; + int _firstSelectionRow, _lastSelectionRow; bool _isSelecting; bool _fetchingBacklog;