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

faster scrolling, more cheating

This commit is contained in:
krepa098 2015-01-07 13:05:28 +01:00
parent 1274c213d0
commit debe6903a3
3 changed files with 20 additions and 6 deletions

View File

@ -174,6 +174,12 @@ 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);

View File

@ -69,6 +69,11 @@ ChatLog::ChatLog(QWidget* parent)
selectionTimer->setSingleShot(false); selectionTimer->setSingleShot(false);
selectionTimer->start(); selectionTimer->start();
connect(selectionTimer, &QTimer::timeout, this, &ChatLog::onSelectionTimerTimeout); connect(selectionTimer, &QTimer::timeout, this, &ChatLog::onSelectionTimerTimeout);
refreshTimer = new QTimer(this);
refreshTimer->setSingleShot(true);
refreshTimer->setInterval(100);
connect(refreshTimer, &QTimer::timeout, this, [this] { partialUpdate(); });
} }
ChatLog::~ChatLog() ChatLog::~ChatLog()
@ -287,13 +292,13 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
if(lines.empty()) if(lines.empty())
return nullptr; return nullptr;
QList<ChatLine::Ptr>::const_iterator upperBound; QVector<ChatLine::Ptr>::const_iterator upperBound;
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs) upperBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs)
{ {
return lhs < rhs->boundingSceneRect().bottom(); return lhs < rhs->boundingSceneRect().bottom();
}); });
QList<ChatLine::Ptr>::const_iterator lowerBound; QVector<ChatLine::Ptr>::const_iterator lowerBound;
lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs) lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs)
{ {
return lhs->boundingSceneRect().top() < rhs; return lhs->boundingSceneRect().top() < rhs;
@ -512,14 +517,14 @@ void ChatLog::checkVisibility()
return; return;
// find first visible row // find first visible row
QList<ChatLine::Ptr>::const_iterator upperBound; QVector<ChatLine::Ptr>::const_iterator upperBound;
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs) upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
{ {
return lhs < rhs->boundingSceneRect().bottom(); return lhs < rhs->boundingSceneRect().bottom();
}); });
// find last visible row // find last visible row
QList<ChatLine::Ptr>::const_iterator lowerBound; QVector<ChatLine::Ptr>::const_iterator lowerBound;
lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().bottom(), [](const ChatLine::Ptr lhs, const qreal rhs) lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().bottom(), [](const ChatLine::Ptr lhs, const qreal rhs)
{ {
return lhs->boundingSceneRect().top() < rhs; return lhs->boundingSceneRect().top() < rhs;
@ -555,7 +560,9 @@ void ChatLog::checkVisibility()
void ChatLog::scrollContentsBy(int dx, int dy) void ChatLog::scrollContentsBy(int dx, int dy)
{ {
QGraphicsView::scrollContentsBy(dx, dy); QGraphicsView::scrollContentsBy(dx, dy);
partialUpdate(); if(!refreshTimer->isActive())
refreshTimer->start();
checkVisibility();
} }
void ChatLog::resizeEvent(QResizeEvent* ev) void ChatLog::resizeEvent(QResizeEvent* ev)

View File

@ -91,7 +91,7 @@ private:
}; };
QGraphicsScene* scene = nullptr; QGraphicsScene* scene = nullptr;
QList<ChatLine::Ptr> lines; QVector<ChatLine::Ptr> lines;
QList<ChatLine::Ptr> visibleLines; QList<ChatLine::Ptr> visibleLines;
bool multiLineInsert = false; bool multiLineInsert = false;
@ -108,6 +108,7 @@ private:
QPointF lastPos; QPointF lastPos;
QGraphicsRectItem* selGraphItem = nullptr; QGraphicsRectItem* selGraphItem = nullptr;
QTimer* selectionTimer = nullptr; QTimer* selectionTimer = nullptr;
QTimer* refreshTimer = nullptr;
AutoScrollDirection selectionScrollDir = NoDirection; AutoScrollDirection selectionScrollDir = NoDirection;
// actions // actions