X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=c24933a280fdf0f41bc07ad5ed5f842553422655;hp=ff28ea4a6eea050edd2c6be66e93670e27ef741e;hb=954b1a6f53da55f9713fb4e75a2fb46dae7d9df8;hpb=80fcc77b8883ef496fcf0ee9b43cf678232e175c diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index ff28ea4a..c24933a2 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -68,13 +68,13 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w _firstColHandle = new ColumnHandleItem(QtUi::style()->firstColumnSeparator()); addItem(_firstColHandle); _firstColHandle->setXPos(_firstColHandlePos); - connect(_firstColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(handlePositionChanged(qreal))); + connect(_firstColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(firstHandlePositionChanged(qreal))); connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _firstColHandle, SLOT(sceneRectChanged(const QRectF &))); _secondColHandle = new ColumnHandleItem(QtUi::style()->secondColumnSeparator()); addItem(_secondColHandle); _secondColHandle->setXPos(_secondColHandlePos); - connect(_secondColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(handlePositionChanged(qreal))); + connect(_secondColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(secondHandlePositionChanged(qreal))); connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _secondColHandle, SLOT(sceneRectChanged(const QRectF &))); setHandleXLimits(); @@ -93,6 +93,8 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w webPreview.deleteTimer.setInterval(600000); connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreviewEvent())); #endif + + setItemIndexMethod(QGraphicsScene::NoIndex); } ChatScene::~ChatScene() { @@ -266,8 +268,7 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e } } - Q_ASSERT(start == 0 || _lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height() == _lines.at(start)->pos().y()); - Q_ASSERT(end + 1 == _lines.count() || _lines.at(end)->pos().y() + _lines.at(end)->height() == _lines.at(end + 1)->pos().y()); + Q_ASSERT(start == 0 || start >= _lines.count() || _lines.at(start - 1)->pos().y() + _lines.at(start - 1)->height() == _lines.at(start)->pos().y()); // update sceneRect // when searching for the first non-date-line we have to take into account that our @@ -295,50 +296,25 @@ void ChatScene::updateForViewport(qreal width, qreal height) { setWidth(width); } -// setWidth is used for 2 things: -// a) updating the scene to fit the width of the corresponding view -// b) to update the positions of the items if a columhandle has changed it's position -// forceReposition is true in the second case -// this method features some codeduplication for the sake of performance -void ChatScene::setWidth(qreal width, bool forceReposition) { - if(width == _sceneRect.width() && !forceReposition) +void ChatScene::setWidth(qreal width) { + if(width == _sceneRect.width()) return; -// clock_t startT = clock(); + // clock_t startT = clock(); // disabling the index while doing this complex updates is about // 2 to 10 times faster! - setItemIndexMethod(QGraphicsScene::NoIndex); + //setItemIndexMethod(QGraphicsScene::NoIndex); - qreal linePos = _sceneRect.y() + _sceneRect.height(); QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); - ChatLine *line = 0; - qreal lineHeight = 0; + qreal linePos = _sceneRect.y() + _sceneRect.height(); qreal contentsWidth = width - secondColumnHandle()->sceneRight(); - - if(forceReposition) { - qreal timestampWidth = firstColumnHandle()->sceneLeft(); - qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight(); - QPointF senderPos(firstColumnHandle()->sceneRight(), 0); - QPointF contentsPos(secondColumnHandle()->sceneRight(), 0); - while(lineIter != lineIterBegin) { - lineIter--; - line = *lineIter; - lineHeight = line->setColumns(timestampWidth, senderWidth, contentsWidth, senderPos, contentsPos); - linePos -= lineHeight; - line->setPos(0, linePos); - } - } else { - while(lineIter != lineIterBegin) { - lineIter--; - line = *lineIter; - lineHeight = line->setGeometryByWidth(width, contentsWidth); - linePos -= lineHeight; - line->setPos(0, linePos); - } + while(lineIter != lineIterBegin) { + lineIter--; + (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos); } - setItemIndexMethod(QGraphicsScene::BspTreeIndex); + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); updateSceneRect(width); setHandleXLimits(); @@ -347,29 +323,72 @@ void ChatScene::setWidth(qreal width, bool forceReposition) { // qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec"; } -void ChatScene::handlePositionChanged(qreal xpos) { - bool first = (sender() == _firstColHandle); - qreal oldx; - if(first) { - oldx = _firstColHandlePos; - _firstColHandlePos = xpos; - } else { - oldx = _secondColHandlePos; - _secondColHandlePos = xpos; - } +void ChatScene::firstHandlePositionChanged(qreal xpos) { + if(_firstColHandlePos == xpos) + return; + _firstColHandlePos = xpos; ChatViewSettings viewSettings(this); viewSettings.setValue("FirstColumnHandlePos", _firstColHandlePos); - viewSettings.setValue("SecondColumnHandlePos", _secondColHandlePos); - ChatViewSettings defaultSettings; defaultSettings.setValue("FirstColumnHandlePos", _firstColHandlePos); + + // 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 timestampWidth = firstColumnHandle()->sceneLeft(); + qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight(); + QPointF senderPos(firstColumnHandle()->sceneRight(), 0); + + while(lineIter != lineIterBegin) { + lineIter--; + (*lineIter)->setFirstColumn(timestampWidth, senderWidth, senderPos); + } + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); + + setHandleXLimits(); + +// clock_t endT = clock(); +// qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec"; +} + +void ChatScene::secondHandlePositionChanged(qreal xpos) { + if(_secondColHandlePos == xpos) + return; + + _secondColHandlePos = xpos; + ChatViewSettings viewSettings(this); + viewSettings.setValue("SecondColumnHandlePos", _secondColHandlePos); + ChatViewSettings defaultSettings; defaultSettings.setValue("SecondColumnHandlePos", _secondColHandlePos); - setWidth(width(), true); // readjust all chatlines - // we get ugly redraw errors if we don't update this explicitly... :( - // width() should be the same for both handles, so just use _firstColHandle regardless - //update(qMin(oldx, xpos), 0, qMax(oldx, xpos) + firstColHandle->width(), height()); + // 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 senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight(); + qreal contentsWidth = _sceneRect.width() - secondColumnHandle()->sceneRight(); + QPointF contentsPos(secondColumnHandle()->sceneRight(), 0); + while(lineIter != lineIterBegin) { + lineIter--; + (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos); + } + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); + + setHandleXLimits(); + +// clock_t endT = clock(); +// qDebug() << "resized" << _lines.count() << "in" << (float)(endT - startT) / CLOCKS_PER_SEC << "sec"; } void ChatScene::setHandleXLimits() { @@ -529,9 +548,9 @@ int ChatScene::sectionByScenePos(int x) { return ChatLineModel::ContentsColumn; } -void ChatScene::updateSceneRect() { +void ChatScene::updateSceneRect(qreal width) { if(_lines.isEmpty()) { - updateSceneRect(QRectF(0, 0, _sceneRect.width(), 0)); + updateSceneRect(QRectF(0, 0, width, 0)); return; } @@ -554,14 +573,14 @@ void ChatScene::updateSceneRect() { } // the following call should be safe. If it crashes something went wrong during insert/remove - ChatLine *firstLine = _lines.at(_firstLineRow); - 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(); + if(_firstLineRow < _lines.count()) { + ChatLine *firstLine = _lines.at(_firstLineRow); + ChatLine *lastLine = _lines.last(); + updateSceneRect(QRectF(0, firstLine->pos().y(), width, lastLine->pos().y() + lastLine->height() - firstLine->pos().y())); + } else { + // empty scene rect + updateSceneRect(QRectF(0, 0, width, 0)); + } } void ChatScene::updateSceneRect(const QRectF &rect) {