X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=7ba9ada9addd0bfdc9e21f867c861c2c9510ee80;hb=de8ae1e75bbe0b429647db7da758a51323385e57;hp=10ef5d8f7069c143e0b45d47840153097dba77a2;hpb=46ddb293c61aeb90295fa1a14be71e8896f34ade;p=quassel.git diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 10ef5d8f..7ba9ada9 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -169,11 +169,8 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { } } - // update sceneRect - if(atTop || moveTop) { - updateSceneRect(_sceneRect.adjusted(0, -h, 0, 0)); - } else { - updateSceneRect(_sceneRect.adjusted(0, 0, 0, h)); + updateSceneRect(); + if(atBottom) { emit lastLineChanged(_lines.last()); } @@ -239,12 +236,34 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e } } + // update sceneRect - if(atTop || moveTop) { - updateSceneRect(_sceneRect.adjusted(0, h, 0, 0)); - } else { - updateSceneRect(_sceneRect.adjusted(0, 0, 0, -h)); + // when searching for the first non-date-line we have to take into account that our + // model still contains the just removed lines so we cannot simply call updateSceneRect() + if(_lines.isEmpty()) { + updateSceneRect(QRectF(0, 0, _sceneRect.width(), 0)); + return; } + int numRows = model()->rowCount(); + QModelIndex firstLineIdx; + int row = -1; + bool needOffset = false; + do { + row++; + if(row >= start && row <= end) { + row = end + 1; + needOffset = true; + } + firstLineIdx = model()->index(row, 0); + } while((Message::Type)(model()->data(firstLineIdx, MessageModel::TypeRole).toInt()) == Message::DayChange && row < numRows); + + if(needOffset) + row -= end - start + 1; + + ChatLine *firstLine = _lines.at(row); + ChatLine *lastLine = _lines.last(); + + updateSceneRect(QRectF(0, firstLine->pos().y(), _sceneRect.width(), lastLine->pos().y() + lastLine->height() - firstLine->pos().y())); } void ChatScene::updateForViewport(qreal width, qreal height) { @@ -264,7 +283,6 @@ void ChatScene::setWidth(qreal width, bool forceReposition) { // clock_t startT = clock(); qreal linePos = _sceneRect.y() + _sceneRect.height(); - qreal yBottom = linePos; QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); ChatLine *line = 0; @@ -293,7 +311,7 @@ void ChatScene::setWidth(qreal width, bool forceReposition) { } } - updateSceneRect(QRectF(0, linePos, width, yBottom - linePos)); + updateSceneRect(width); setHandleXLimits(); // clock_t endT = clock(); @@ -463,6 +481,9 @@ void ChatScene::requestBacklog() { int backlogSize = model()->rowCount(); if(isSingleBufferScene() && backlogSize != 0 && _lastBacklogSize + REQUEST_COUNT <= backlogSize) { QModelIndex msgIdx = model()->index(0, 0); + while((Message::Type)(model()->data(msgIdx, ChatLineModel::TypeRole).toInt()) == Message::DayChange) { + msgIdx = msgIdx.sibling(msgIdx.row() + 1, 0); + } MsgId msgId = model()->data(msgIdx, ChatLineModel::MsgIdRole).value(); BufferId bufferId = model()->data(msgIdx, ChatLineModel::BufferIdRole).value(); _lastBacklogSize = backlogSize; @@ -479,6 +500,31 @@ int ChatScene::sectionByScenePos(int x) { return ChatLineModel::ContentsColumn; } +void ChatScene::updateSceneRect() { + if(_lines.isEmpty()) + return; + + // we hide day change messages at the top by making the scene rect smaller + int numRows = model()->rowCount(); + int row = -1; + QModelIndex firstLineIdx; + do { + row++; + firstLineIdx = model()->index(row, 0); + } while((Message::Type)(model()->data(firstLineIdx, MessageModel::TypeRole).toInt()) == Message::DayChange && row < numRows); + + // the following call should be safe. If it crashes something went wrong during insert/remove + ChatLine *firstLine = _lines.at(row); + ChatLine *lastLine = _lines.last(); + + updateSceneRect(QRectF(0, firstLine->pos().y(), _sceneRect.width(), lastLine->pos().y() + lastLine->height() - firstLine->pos().y())); +} + +void ChatScene::updateSceneRect(qreal width) { + _sceneRect.setWidth(width); + updateSceneRect(); +} + void ChatScene::updateSceneRect(const QRectF &rect) { _sceneRect = rect; setSceneRect(rect);