From debe6903a3cd3dac8d59c58571d6dc477b635fee Mon Sep 17 00:00:00 2001 From: krepa098 Date: Wed, 7 Jan 2015 13:05:28 +0100 Subject: [PATCH] faster scrolling, more cheating --- src/chatlog/chatline.cpp | 6 ++++++ src/chatlog/chatlog.cpp | 17 ++++++++++++----- src/chatlog/chatlog.h | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/chatlog/chatline.cpp b/src/chatlog/chatline.cpp index 4bb68a913..9f2c9d72f 100644 --- a/src/chatlog/chatline.cpp +++ b/src/chatlog/chatline.cpp @@ -174,6 +174,12 @@ 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); diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index bf5a5bdfc..dae6e44df 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -69,6 +69,11 @@ ChatLog::ChatLog(QWidget* parent) selectionTimer->setSingleShot(false); selectionTimer->start(); 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() @@ -287,13 +292,13 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const if(lines.empty()) return nullptr; - QList::const_iterator upperBound; + QVector::const_iterator upperBound; upperBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs) { return lhs < rhs->boundingSceneRect().bottom(); }); - QList::const_iterator lowerBound; + QVector::const_iterator lowerBound; lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs) { return lhs->boundingSceneRect().top() < rhs; @@ -512,14 +517,14 @@ void ChatLog::checkVisibility() return; // find first visible row - QList::const_iterator upperBound; + QVector::const_iterator upperBound; upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs) { return lhs < rhs->boundingSceneRect().bottom(); }); // find last visible row - QList::const_iterator lowerBound; + QVector::const_iterator lowerBound; lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().bottom(), [](const ChatLine::Ptr lhs, const qreal rhs) { return lhs->boundingSceneRect().top() < rhs; @@ -555,7 +560,9 @@ void ChatLog::checkVisibility() void ChatLog::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy(dx, dy); - partialUpdate(); + if(!refreshTimer->isActive()) + refreshTimer->start(); + checkVisibility(); } void ChatLog::resizeEvent(QResizeEvent* ev) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index efca339ec..05f1903e4 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -91,7 +91,7 @@ private: }; QGraphicsScene* scene = nullptr; - QList lines; + QVector lines; QList visibleLines; bool multiLineInsert = false; @@ -108,6 +108,7 @@ private: QPointF lastPos; QGraphicsRectItem* selGraphItem = nullptr; QTimer* selectionTimer = nullptr; + QTimer* refreshTimer = nullptr; AutoScrollDirection selectionScrollDir = NoDirection; // actions