Browse Source

faster scrolling, more cheating

pull/974/head
krepa098 11 years ago
parent
commit
debe6903a3
  1. 6
      src/chatlog/chatline.cpp
  2. 17
      src/chatlog/chatlog.cpp
  3. 3
      src/chatlog/chatlog.h

6
src/chatlog/chatline.cpp

@ -174,6 +174,12 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent) @@ -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);

17
src/chatlog/chatlog.cpp

@ -69,6 +69,11 @@ ChatLog::ChatLog(QWidget* parent) @@ -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 @@ -287,13 +292,13 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
if(lines.empty())
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)
{
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)
{
return lhs->boundingSceneRect().top() < rhs;
@ -512,14 +517,14 @@ void ChatLog::checkVisibility() @@ -512,14 +517,14 @@ void ChatLog::checkVisibility()
return;
// 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)
{
return lhs < rhs->boundingSceneRect().bottom();
});
// 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)
{
return lhs->boundingSceneRect().top() < rhs;
@ -555,7 +560,9 @@ void ChatLog::checkVisibility() @@ -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)

3
src/chatlog/chatlog.h

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

Loading…
Cancel
Save