Browse Source

Don't stick to bottom if the user scrolls while the worker is still

running
pull/974/head
krepa098 11 years ago
parent
commit
437282b80c
  1. 23
      src/chatlog/chatlog.cpp
  2. 1
      src/chatlog/chatlog.h

23
src/chatlog/chatlog.cpp

@ -106,7 +106,7 @@ ChatLog::ChatLog(QWidget* parent) @@ -106,7 +106,7 @@ ChatLog::ChatLog(QWidget* parent)
workerLastIndex = 0;
workerDy = 0.0;
if(workerStb)
if(stickToBottom())
scrollToBottom();
}
});
@ -134,17 +134,12 @@ void ChatLog::clearSelection() @@ -134,17 +134,12 @@ void ChatLog::clearSelection()
QRect ChatLog::getVisibleRect() const
{
return mapToScene(viewport()->rect()).boundingRect().toRect();
return mapToScene(calculateSceneRect().toRect()).boundingRect().toRect();
}
void ChatLog::updateSceneRect()
{
qreal bottom = (lines.empty() ? 0.0 : lines.last()->boundingSceneRect().bottom());
if(typingNotification.get() != nullptr)
bottom += typingNotification->boundingSceneRect().height() + lineSpacing;
setSceneRect(QRectF(-margins.left(), -margins.top(), useableWidth(), bottom + margins.bottom() + margins.top()));
setSceneRect(calculateSceneRect());
}
qreal ChatLog::layout(int start, int end, qreal width)
@ -584,8 +579,6 @@ void ChatLog::checkVisibility() @@ -584,8 +579,6 @@ void ChatLog::checkVisibility()
if(lines.empty())
return;
updateSceneRect();
// find first visible line
auto lowerBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
{
@ -688,6 +681,16 @@ void ChatLog::updateTypingNotification() @@ -688,6 +681,16 @@ void ChatLog::updateTypingNotification()
notification->layout(useableWidth(), QPointF(0.0, posY));
}
QRectF ChatLog::calculateSceneRect() const
{
qreal bottom = (lines.empty() ? 0.0 : lines.last()->boundingSceneRect().bottom());
if(typingNotification.get() != nullptr)
bottom += typingNotification->boundingSceneRect().height() + lineSpacing;
return QRectF(-margins.left(), -margins.top(), useableWidth(), bottom + margins.bottom() + margins.top());
}
void ChatLog::onSelectionTimerTimeout()
{
const int scrollSpeed = 10;

1
src/chatlog/chatlog.h

@ -54,6 +54,7 @@ public: @@ -54,6 +54,7 @@ public:
ChatLine::Ptr getTypingNotification() const;
protected:
QRectF calculateSceneRect() const;
QRect getVisibleRect() const;
ChatLineContent* getContentFromPos(QPointF scenePos) const;

Loading…
Cancel
Save