1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

towards better scrolling

Experimental changes!
Known bug: Scrolling gets extremly slow while the cursor is inside
qTox's main window.
Cause: Unknown.
This commit is contained in:
krepa098 2015-01-07 15:03:02 +01:00
parent 0f52bf3f5c
commit 39d2bbb341
3 changed files with 57 additions and 9 deletions

View File

@ -174,12 +174,6 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
void ChatLine::layout(qreal w, QPointF scenePos)
{
if(width == w)
{
moveBy(scenePos.y() - bbox.top());
return;
}
width = w;
bbox.setTopLeft(scenePos);

View File

@ -72,8 +72,54 @@ ChatLog::ChatLog(QWidget* parent)
refreshTimer = new QTimer(this);
refreshTimer->setSingleShot(true);
refreshTimer->setInterval(100);
refreshTimer->setInterval(500);
connect(refreshTimer, &QTimer::timeout, this, [this] { partialUpdate(); });
workerTimer = new QTimer(this);
workerTimer->setSingleShot(false);
workerTimer->setInterval(100);
connect(workerTimer, &QTimer::timeout, this, [this] {
const int stepSize = 200;
workerDy += layout(lastWorkerIndex, lastWorkerIndex+stepSize, useableWidth());
qDebug() << "working... " << lastWorkerIndex << "/" << lines.size();
if(!visibleLines.isEmpty())
{
int firstVisLineIndex = visibleLines.first()->getRowIndex();
int delta = firstVisLineIndex - lastWorkerIndex;
if(delta > 0 && delta < stepSize)
{
//qDebug() << "delta " << delta << "fvl " << firstVisLineIndex;
lastWorkerIndex += delta+1;
if(!stickToBottom())
verticalScrollBar()->setValue(verticalScrollBar()->value() - workerDy);
workerDy = 0.0;
checkVisibility();
}
else
lastWorkerIndex += stepSize;
}
else
lastWorkerIndex += stepSize;
if(lastWorkerIndex >= lines.size())
{
workerTimer->stop();
lastWorkerIndex = 0;
workerDy = 0.0;
bool stb = stickToBottom();
updateSceneRect();
if(stb)
scrollToBottom();
qDebug() << "working... done!";
}
});
}
ChatLog::~ChatLog()
@ -108,7 +154,6 @@ void ChatLog::updateSceneRect()
qreal ChatLog::layout(int start, int end, qreal width)
{
//qDebug() << "layout " << start << end;
if(lines.empty())
return false;
@ -154,7 +199,7 @@ void ChatLog::partialUpdate()
if(!visibleLines.empty())
{
repos = layout(visibleLines.first()->getRowIndex(), visibleLines.last()->getRowIndex(), useableWidth());
reposition(visibleLines.last()->getRowIndex()+1, lines.size(), -repos);
reposition(visibleLines.last()->getRowIndex()+1, visibleLines.last()->getRowIndex()+10, -repos);
verticalScrollBar()->setValue(verticalScrollBar()->value() - repos);
}
@ -580,6 +625,11 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
scrollToBottom();
updateMultiSelectionRect();
qDebug() << "starting worker";
lastWorkerIndex = 0;
workerDy = 0.0;
workerTimer->start();
}
void ChatLog::updateMultiSelectionRect()

View File

@ -109,8 +109,12 @@ private:
QGraphicsRectItem* selGraphItem = nullptr;
QTimer* selectionTimer = nullptr;
QTimer* refreshTimer = nullptr;
QTimer* workerTimer = nullptr;
AutoScrollDirection selectionScrollDir = NoDirection;
int lastWorkerIndex = 0;
qreal workerDy = 0;
// actions
QAction* copyAction = nullptr;