X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=b159dc903a2a349052dc24d622d2d6c5dbc652bd;hp=e20f3d636464641807aed3692ef021bf65735a96;hb=9fd12737c55a0119801c90c399c926b35ffee708;hpb=064dcac965d1e724a0434683685a24ec7e6ba855 diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index e20f3d63..b159dc90 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -96,6 +96,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w this, SLOT(rowsInserted(const QModelIndex &, int, int))); connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int))); + connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); if(model->rowCount() > 0) rowsInserted(QModelIndex(), 0, model->rowCount() - 1); @@ -380,6 +381,10 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e updateSceneRect(); } +void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) { + layout(tl.row(), br.row(), _sceneRect.width()); +} + void ChatScene::updateForViewport(qreal width, qreal height) { _viewportHeight = height; setWidth(width); @@ -388,27 +393,37 @@ void ChatScene::updateForViewport(qreal width, qreal height) { void ChatScene::setWidth(qreal width) { if(width == _sceneRect.width()) return; - layout(width); + layout(0, _lines.count()-1, width); } -void ChatScene::layout(qreal width) { +void ChatScene::layout(int start, int end, qreal width) { // clock_t startT = clock(); - if(width < 0) - width = _sceneRect.width(); - // disabling the index while doing this complex updates is about // 2 to 10 times faster! //setItemIndexMethod(QGraphicsScene::NoIndex); - QList::iterator lineIter = _lines.end(); - QList::iterator lineIterBegin = _lines.begin(); - qreal linePos = _sceneRect.y() + _sceneRect.height(); - qreal contentsWidth = width - secondColumnHandle()->sceneRight(); - while(lineIter != lineIterBegin) { - lineIter--; - (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos); + if(end >= 0) { + int row = end; + qreal linePos = _lines.at(row)->scenePos().y() + _lines.at(row)->height(); + qreal contentsWidth = width - secondColumnHandle()->sceneRight(); + while(row >= start) { + _lines.at(row--)->setGeometryByWidth(width, contentsWidth, linePos); + } + + if(row >= 0) { + // remaining items don't need geometry changes, but maybe repositioning? + ChatLine *line = _lines.at(row); + qreal offset = linePos - (line->scenePos().y() + line->height()); + if(offset != 0) { + while(row >= 0) { + line = _lines.at(row--); + line->setPos(0, line->scenePos().y() + offset); + } + } + } } + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); updateSceneRect(width);