X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=86a461bbf55394c48cd588fea7b4bdaa65cd2ca7;hp=2cb90ea9f66126f0aba165a97a3f7135f823b125;hb=d36a37a4a2e2fa889cf12d596258f9ba4dfcc5ed;hpb=830076bb8c321ee7866ffd430062282e7fe50afb diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 2cb90ea9..86a461bb 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -24,7 +24,10 @@ #include #include #include -#include + +#ifdef HAVE_WEBKIT +# include +#endif #include "chatitem.h" #include "chatline.h" @@ -89,13 +92,14 @@ 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))); - - if(model->rowCount() > 0) - rowsInserted(QModelIndex(), 0, model->rowCount() - 1); + connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); #ifdef HAVE_WEBKIT webPreview.timer.setSingleShot(true); @@ -377,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); @@ -385,21 +393,37 @@ void ChatScene::updateForViewport(qreal width, qreal height) { void ChatScene::setWidth(qreal width) { if(width == _sceneRect.width()) return; + layout(0, _lines.count()-1, width); +} +void ChatScene::layout(int start, int end, qreal width) { // clock_t startT = clock(); // 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); @@ -414,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; @@ -858,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; @@ -943,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; }