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:
parent
0f52bf3f5c
commit
39d2bbb341
|
@ -174,12 +174,6 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
|
||||||
|
|
||||||
void ChatLine::layout(qreal w, QPointF scenePos)
|
void ChatLine::layout(qreal w, QPointF scenePos)
|
||||||
{
|
{
|
||||||
if(width == w)
|
|
||||||
{
|
|
||||||
moveBy(scenePos.y() - bbox.top());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
width = w;
|
width = w;
|
||||||
bbox.setTopLeft(scenePos);
|
bbox.setTopLeft(scenePos);
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,54 @@ ChatLog::ChatLog(QWidget* parent)
|
||||||
|
|
||||||
refreshTimer = new QTimer(this);
|
refreshTimer = new QTimer(this);
|
||||||
refreshTimer->setSingleShot(true);
|
refreshTimer->setSingleShot(true);
|
||||||
refreshTimer->setInterval(100);
|
refreshTimer->setInterval(500);
|
||||||
connect(refreshTimer, &QTimer::timeout, this, [this] { partialUpdate(); });
|
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()
|
ChatLog::~ChatLog()
|
||||||
|
@ -108,7 +154,6 @@ void ChatLog::updateSceneRect()
|
||||||
|
|
||||||
qreal ChatLog::layout(int start, int end, qreal width)
|
qreal ChatLog::layout(int start, int end, qreal width)
|
||||||
{
|
{
|
||||||
//qDebug() << "layout " << start << end;
|
|
||||||
if(lines.empty())
|
if(lines.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -154,7 +199,7 @@ void ChatLog::partialUpdate()
|
||||||
if(!visibleLines.empty())
|
if(!visibleLines.empty())
|
||||||
{
|
{
|
||||||
repos = layout(visibleLines.first()->getRowIndex(), visibleLines.last()->getRowIndex(), useableWidth());
|
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);
|
verticalScrollBar()->setValue(verticalScrollBar()->value() - repos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,6 +625,11 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
|
|
||||||
updateMultiSelectionRect();
|
updateMultiSelectionRect();
|
||||||
|
|
||||||
|
qDebug() << "starting worker";
|
||||||
|
lastWorkerIndex = 0;
|
||||||
|
workerDy = 0.0;
|
||||||
|
workerTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::updateMultiSelectionRect()
|
void ChatLog::updateMultiSelectionRect()
|
||||||
|
|
|
@ -109,8 +109,12 @@ private:
|
||||||
QGraphicsRectItem* selGraphItem = nullptr;
|
QGraphicsRectItem* selGraphItem = nullptr;
|
||||||
QTimer* selectionTimer = nullptr;
|
QTimer* selectionTimer = nullptr;
|
||||||
QTimer* refreshTimer = nullptr;
|
QTimer* refreshTimer = nullptr;
|
||||||
|
QTimer* workerTimer = nullptr;
|
||||||
AutoScrollDirection selectionScrollDir = NoDirection;
|
AutoScrollDirection selectionScrollDir = NoDirection;
|
||||||
|
|
||||||
|
int lastWorkerIndex = 0;
|
||||||
|
qreal workerDy = 0;
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
QAction* copyAction = nullptr;
|
QAction* copyAction = nullptr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user