X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=86a461bbf55394c48cd588fea7b4bdaa65cd2ca7;hp=bcfea000e81ccb4e0d6d2e8aa341111fa4b2616b;hb=66c5feaf7c9f480f06dfb45df2cf54e44c8b487b;hpb=d7a7c6e5242fd0f500b2c1c75579c9db81a91d0c diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index bcfea000..86a461bb 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -92,15 +92,15 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w setHandleXLimits(); + if(model->rowCount() > 0) + rowsInserted(QModelIndex(), 0, model->rowCount() - 1); + connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), 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); - #ifdef HAVE_WEBKIT webPreview.timer.setSingleShot(true); connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep())); @@ -382,10 +382,7 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e } void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) { - // This should only be sent (currently) if the style is reloaded -> re-layout the whole scene - // TODO: Check range and only do partial relayouts, if appropriate - - layout(); + layout(tl.row(), br.row(), _sceneRect.width()); } void ChatScene::updateForViewport(qreal width, qreal height) { @@ -396,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); @@ -431,7 +438,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) { if(_firstColHandlePos == xpos) return; - _firstColHandlePos = xpos; + _firstColHandlePos = xpos >= 0 ? xpos : 0; ChatViewSettings viewSettings(this); viewSettings.setValue("FirstColumnHandlePos", _firstColHandlePos); ChatViewSettings defaultSettings; @@ -875,7 +882,7 @@ bool ChatScene::event(QEvent *e) { // Webkit Only stuff // ======================================== #ifdef HAVE_WEBKIT -void ChatScene::loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect) { +void ChatScene::loadWebPreview(ChatItem *parentItem, const QUrl &url, const QRectF &urlRect) { if(!_showWebPreview) return; @@ -960,7 +967,7 @@ void ChatScene::webPreviewNextStep() { webPreview.previewItem = 0; } webPreview.parentItem = 0; - webPreview.url = QString(); + webPreview.url = QUrl(); webPreview.urlRect = QRectF(); webPreview.previewState = WebPreview::NoPreview; }