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

fixed chatlog not scrolling to bottom after resize

This commit is contained in:
krepa098 2015-01-14 10:56:44 +01:00
parent bde32d2171
commit 4930b32641
2 changed files with 25 additions and 16 deletions

View File

@ -76,17 +76,17 @@ ChatLog::ChatLog(QWidget* parent)
connect(workerTimer, &QTimer::timeout, this, [this] {
const int stepSize = 400;
workerDy += layout(lastWorkerIndex, lastWorkerIndex+stepSize, useableWidth());
workerDy += layout(workerLastIndex, workerLastIndex+stepSize, useableWidth());
if(!visibleLines.isEmpty())
{
int firstVisLineIndex = visibleLines.first()->getRowIndex();
int delta = firstVisLineIndex - lastWorkerIndex;
int delta = firstVisLineIndex - workerLastIndex;
if(delta > 0 && delta < stepSize)
{
lastWorkerIndex += delta+1;
workerLastIndex += delta+1;
if(!stickToBottom())
if(!workerStb)
verticalScrollBar()->setValue(verticalScrollBar()->value() - workerDy);
workerDy = 0.0;
@ -94,21 +94,19 @@ ChatLog::ChatLog(QWidget* parent)
}
else
{
lastWorkerIndex += stepSize;
workerLastIndex += stepSize;
}
}
else
lastWorkerIndex += stepSize;
workerLastIndex += stepSize;
if(lastWorkerIndex >= lines.size())
if(workerLastIndex >= lines.size())
{
workerTimer->stop();
lastWorkerIndex = 0;
workerLastIndex = 0;
workerDy = 0.0;
bool stb = stickToBottom();
updateSceneRect();
if(stb)
if(workerStb)
scrollToBottom();
}
});
@ -186,6 +184,8 @@ void ChatLog::partialUpdate()
if(visibleLines.empty())
return;
bool stb = stickToBottom();
auto oldUpdateMode = viewportUpdateMode();
setViewportUpdateMode(NoViewportUpdate);
@ -207,6 +207,9 @@ void ChatLog::partialUpdate()
checkVisibility();
setViewportUpdateMode(oldUpdateMode);
if(stb)
scrollToBottom();
}
void ChatLog::fullUpdate()
@ -631,6 +634,14 @@ void ChatLog::scrollContentsBy(int dx, int dy)
void ChatLog::resizeEvent(QResizeEvent* ev)
{
if(!workerTimer->isActive())
{
workerStb = stickToBottom();
workerLastIndex = 0;
workerDy = 0.0;
workerTimer->start();
}
bool stb = stickToBottom();
QGraphicsView::resizeEvent(ev);
@ -644,10 +655,6 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
scrollToBottom();
updateMultiSelectionRect();
lastWorkerIndex = 0;
workerDy = 0.0;
workerTimer->start();
}
void ChatLog::updateMultiSelectionRect()

View File

@ -112,8 +112,10 @@ private:
QTimer* workerTimer = nullptr;
AutoScrollDirection selectionScrollDir = NoDirection;
int lastWorkerIndex = 0;
//worker vars
int workerLastIndex = 0;
qreal workerDy = 0;
bool workerStb = false;
// actions
QAction* copyAction = nullptr;