diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 092815b5e..29b5ed153 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -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() 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() 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() 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; diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index ac4eec148..b86700800 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -54,6 +54,7 @@ public: ChatLine::Ptr getTypingNotification() const; protected: + QRectF calculateSceneRect() const; QRect getVisibleRect() const; ChatLineContent* getContentFromPos(QPointF scenePos) const;