From: Sebastian Goth Date: Tue, 17 Jun 2014 17:26:50 +0000 (+0200) Subject: Keep scrolled down views through resizeEvents X-Git-Tag: 0.11.0~21^2~1 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=e105229e4443fbb05496fcec02a83cb8ffba09db Keep scrolled down views through resizeEvents There's a reason for everything... ChatView is rendered into the viewport from top to bottom. If we don't scroll to bottom, the topmost line doesn't change and therefore the scrollbar will move upwards on shrinking events. So if the scrollbar was at bottom before the resize, make it stay there. --- diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index b40b2900..b8cb2f17 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -126,11 +126,26 @@ bool ChatView::event(QEvent *event) void ChatView::resizeEvent(QResizeEvent *event) { + // if view is currently scrolled to bottom, we want it that way after resizing + bool atBottom = (_lastScrollbarPos == verticalScrollBar()->maximum()); + QGraphicsView::resizeEvent(event); + // if scrolling to bottom, do it immediately. + if(atBottom) + { + // we can reduce viewport updates if we scroll to the bottom allready at the beginning + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + } + scene()->updateForViewport(viewport()->width(), viewport()->height()); adjustSceneRect(); + if(atBottom) + { + _lastScrollbarPos = verticalScrollBar()->maximum(); + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + } checkChatLineCaches(); }