X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=681996a55cec169b75d76c8f52a91ea49fb29d95;hp=9ac7974d8e87416410462d8e797bbb3283d7ded1;hb=7ce0cf6c209c30b1b8702e6623cb6d6d6cad822d;hpb=533eaaeda64759c01daa624365b8fc63eeba5ccf diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 9ac7974d..681996a5 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -30,6 +30,7 @@ #include "client.h" #include "clientbacklogmanager.h" #include "columnhandleitem.h" +#include "messagefilter.h" #include "qtui.h" #include "qtuisettings.h" @@ -37,14 +38,20 @@ const qreal minContentsWidth = 200; ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject *parent) : QGraphicsScene(parent), - _idString(idString), - _model(model) + _idString(idString), + _width(0), + _height(0), + _model(model), + _singleBufferScene(false), + _selectingItem(0), + _selectionStart(-1), + _isSelecting(false), + _fetchingBacklog(false) { - _width = 0; - _selectingItem = 0; - _isSelecting = false; - _selectionStart = -1; - _fetchingBacklog = false; + MessageFilter *filter = qobject_cast(model); + if(filter) { + _singleBufferScene = filter->isSingleBufferFilter(); + } connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &))); @@ -105,6 +112,15 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { _lines[i]->setRow(i); } + // update selection + if(_selectionStart >= 0) { + int offset = end - start + 1; + if(_selectionStart >= start) _selectionStart += offset; + if(_selectionEnd >= start) _selectionEnd += offset; + if(_firstSelectionRow >= start) _firstSelectionRow += offset; + if(_lastSelectionRow >= start) _lastSelectionRow += offset; + } + if(h > 0) { _height += h; for(int i = end+1; i < _lines.count(); i++) { @@ -124,6 +140,7 @@ void ChatScene::modelReset() { } _lines.clear(); setSceneRect(QRectF(0, 0, _width, 0)); + emit heightChanged(0); } void ChatScene::setWidth(qreal w) { @@ -171,7 +188,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); @@ -197,35 +214,40 @@ void ChatScene::updateSelection(const QPointF &pos) { _lines[l]->setSelected(true, minColumn); } } - - 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; + Q_ASSERT(_selectingItem); // this seems to not always be true, but I have no idea why + // adding this assert to make sure the occasional segfault is caused by this _selectingItem->continueSelecting(_selectingItem->mapFromScene(pos)); } } void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(_isSelecting && event->buttons() & Qt::LeftButton) { + if(_isSelecting && event->buttons() == Qt::LeftButton) { updateSelection(event->scenePos()); event->accept(); } else { @@ -234,7 +256,7 @@ void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->buttons() & Qt::LeftButton && _selectionStart >= 0) { + if(event->buttons() == Qt::LeftButton && _selectionStart >= 0) { for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++) { _lines[l]->setSelected(false); } @@ -246,13 +268,8 @@ void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { } void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(_isSelecting) { -# ifdef Q_WS_X11 - QApplication::clipboard()->setText(selectionToString(), QClipboard::Selection); -# endif -//# else - QApplication::clipboard()->setText(selectionToString()); -//# endif + if(_isSelecting && !event->buttons() & Qt::LeftButton) { + putToClipboard(selectionToString()); _isSelecting = false; event->accept(); } else { @@ -260,6 +277,16 @@ void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { } } +void ChatScene::putToClipboard(const QString &selection) { + // TODO Configure clipboards +# ifdef Q_WS_X11 + QApplication::clipboard()->setText(selection, QClipboard::Selection); +# endif +//# else + QApplication::clipboard()->setText(selection); +//# endif +} + //!\brief Convert current selection to human-readable string. QString ChatScene::selectionToString() const { //TODO Make selection format configurable!