From 2a276da5e7eec4ca24e5480d8e07eeb670c03c51 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Mon, 21 Sep 2009 16:41:01 +0200
Subject: [PATCH] Be more agressive in scrolling to the bottom in output panes
 when output was appended while the window was not visible.

---
 src/plugins/projectexplorer/outputwindow.cpp | 13 +++++++++++++
 src/plugins/projectexplorer/outputwindow.h   |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp
index d886584db07..d2f7ec7ac27 100644
--- a/src/plugins/projectexplorer/outputwindow.cpp
+++ b/src/plugins/projectexplorer/outputwindow.cpp
@@ -341,6 +341,7 @@ OutputWindow::OutputWindow(QWidget *parent)
     : QPlainTextEdit(parent)
 {
     m_enforceNewline = false;
+    m_scrollToBottom = false;
 
     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
     //setCenterOnScroll(false);
@@ -392,8 +393,18 @@ OutputWindow::~OutputWindow()
     Core::ICore::instance()->removeContextObject(m_outputWindowContext);
 }
 
+void OutputWindow::showEvent(QShowEvent *e)
+{
+    QPlainTextEdit::showEvent(e);
+    if (m_scrollToBottom) {
+        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
+    }
+    m_scrollToBottom = false;
+}
+
 void OutputWindow::appendOutput(const QString &out)
 {
+    m_scrollToBottom = true;
     QString s = out;
     m_enforceNewline = true; // make appendOutputInline put in a newline next time
     if (s.endsWith(QLatin1Char('\n'))) {
@@ -407,6 +418,7 @@ void OutputWindow::appendOutput(const QString &out)
 
 void OutputWindow::appendOutputInline(const QString &out)
 {
+    m_scrollToBottom = true;
     setMaximumBlockCount(MaxBlockCount);
 
     int newline = -1;
@@ -439,6 +451,7 @@ void OutputWindow::appendOutputInline(const QString &out)
 
 void OutputWindow::insertLine()
 {
+    m_scrollToBottom = true;
     setMaximumBlockCount(MaxBlockCount);
     appendPlainText(QString());
     enableUndoRedo();
diff --git a/src/plugins/projectexplorer/outputwindow.h b/src/plugins/projectexplorer/outputwindow.h
index 6820f5076e0..ce81025bdbd 100644
--- a/src/plugins/projectexplorer/outputwindow.h
+++ b/src/plugins/projectexplorer/outputwindow.h
@@ -126,10 +126,13 @@ public:
     void appendOutputInline(const QString &out);
     void insertLine();
 
+    void showEvent(QShowEvent *);
+
 private:
     Core::BaseContext *m_outputWindowContext;
     void enableUndoRedo();
     bool m_enforceNewline;
+    bool m_scrollToBottom;
 };
 
 #if 0
-- 
GitLab