X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=bc62842880383f6a848c3a3af9a325c92006ec40;hp=c062082254e451879e4f7be866d6431e83f3b448;hb=0480c16e33acc3cc6b1f1b507aa8696a70627bf8;hpb=5cc01948319761863c121a74dc1e7b1c182beaa6 diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index c0620822..bc628428 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -103,9 +103,25 @@ ChatScene::~ChatScene() { void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { Q_UNUSED(index); -// QModelIndex sidx = model()->index(start, 0); -// QModelIndex eidx = model()->index(end, 0); -// qDebug() << "rowsInserted" << start << end << "-" << sidx.data(MessageModel::MsgIdRole).value() << eidx.data(MessageModel::MsgIdRole).value(); + + +// QModelIndex sidx = model()->index(start, 2); +// QModelIndex eidx = model()->index(end, 2); +// qDebug() << "rowsInserted:"; +// if(start > 0) { +// QModelIndex ssidx = model()->index(start - 1, 2); +// qDebug() << "Start--:" << start - 1 << ssidx.data(MessageModel::MsgIdRole).value() +// << ssidx.data(Qt::DisplayRole).toString(); +// } +// qDebug() << "Start:" << start << sidx.data(MessageModel::MsgIdRole).value() +// << sidx.data(Qt::DisplayRole).toString(); +// qDebug() << "End:" << end << eidx.data(MessageModel::MsgIdRole).value() +// << eidx.data(Qt::DisplayRole).toString(); +// if(end + 1 < model()->rowCount()) { +// QModelIndex eeidx = model()->index(end + 1, 2); +// qDebug() << "End++:" << end + 1 << eeidx.data(MessageModel::MsgIdRole).value() +// << eeidx.data(Qt::DisplayRole).toString(); +// } qreal h = 0; qreal y = 0; @@ -158,10 +174,17 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { // 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; + int oldStart = _selectionStart; + if(_selectionStart >= start) + _selectionStart += offset; + if(_selectionEnd >= start) { + _selectionEnd += offset; + if(_selectionStart == oldStart) + for(int i = start; i < start + offset; i++) + _lines[i]->setSelected(true); + } + if(_firstSelectionRow >= start) + _firstSelectionRow += offset; } // neither pre- or append means we have to do dirty work: move items... @@ -234,6 +257,13 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e bool atBottom = (end == _lines.count() - 1); bool moveTop = false; + // clear selection + if(_selectingItem) { + int row = _selectingItem->row(); + if(row >= start && row <= end) + setSelectingItem(0); + } + // remove items from scene QList::iterator lineIter = _lines.begin() + start; int lineCount = start; @@ -253,13 +283,16 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e if(_selectionStart >= 0) { int offset = end - start + 1; if(_selectionStart >= start) - _selectionStart -= offset; + _selectionStart = qMax(_selectionStart -= offset, start); if(_selectionEnd >= start) _selectionEnd -= offset; if(_firstSelectionRow >= start) _firstSelectionRow -= offset; - if(_lastSelectionRow >= start) - _lastSelectionRow -= offset; + + if(_selectionEnd < _selectionStart) { + _isSelecting = false; + _selectionStart = -1; + } } // neither removing at bottom or top means we have to move items... @@ -333,6 +366,7 @@ void ChatScene::setWidth(qreal width) { updateSceneRect(width); setHandleXLimits(); + emit layoutChanged(); // clock_t endT = clock(); // qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec"; @@ -400,7 +434,9 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) { } //setItemIndexMethod(QGraphicsScene::BspTreeIndex); + updateSceneRect(); setHandleXLimits(); + emit layoutChanged(); // clock_t endT = clock(); // qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec"; @@ -417,7 +453,7 @@ void ChatScene::setSelectingItem(ChatItem *item) { } void ChatScene::startGlobalSelection(ChatItem *item, const QPointF &itemPos) { - _selectionStart = _selectionEnd = _lastSelectionRow = _firstSelectionRow = item->row(); + _selectionStart = _selectionEnd = _firstSelectionRow = item->row(); _selectionStartCol = _selectionMinCol = item->column(); _isSelecting = true; _lines[_selectionStart]->setSelected(true, (ChatLineModel::ColumnType)_selectionMinCol); @@ -464,11 +500,10 @@ void ChatScene::updateSelection(const QPointF &pos) { _selectionStart = newstart; _selectionEnd = newend; - _lastSelectionRow = curRow; if(newstart == newend && minColumn == ChatLineModel::ContentsColumn) { if(!_selectingItem) { - qWarning() << "WARNING: ChatScene::updateSelection() has a null _selectingItem, this should never happen! Please report."; + // _selectingItem has been removed already return; } _lines[curRow]->setSelected(false); @@ -487,10 +522,11 @@ void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->buttons() == Qt::LeftButton && _selectionStart >= 0) { + if(_selectionStart >= 0 && event->buttons() == Qt::LeftButton) { for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++) { _lines[l]->setSelected(false); } + _isSelecting = false; _selectionStart = -1; QGraphicsScene::mousePressEvent(event); // so we can start a new local selection } else {