diff --git a/src/plugins/coreplugin/messageoutputwindow.cpp b/src/plugins/coreplugin/messageoutputwindow.cpp index 65ce8dcdf17..e553dd13496 100644 --- a/src/plugins/coreplugin/messageoutputwindow.cpp +++ b/src/plugins/coreplugin/messageoutputwindow.cpp @@ -33,13 +33,13 @@ #include "messageoutputwindow.h" -#include +#include using namespace Core::Internal; MessageOutputWindow::MessageOutputWindow() { - m_widget = new QTextEdit; + m_widget = new TextView; m_widget->setReadOnly(true); m_widget->setFrameStyle(QFrame::NoFrame); } @@ -86,7 +86,10 @@ void MessageOutputWindow::visibilityChanged(bool /*b*/) void MessageOutputWindow::append(const QString &text) { + bool scroll = m_widget->isScrollbarAtBottom() || !m_widget->isVisible(); m_widget->append(text); + if (scroll) + m_widget->scrollToBottom(); } int MessageOutputWindow::priorityInStatusBar() const @@ -118,3 +121,34 @@ bool MessageOutputWindow::canNavigate() { return false; } + +// -------- Copied from OutputWindow which should be shared instead + +bool TextView::isScrollbarAtBottom() const +{ + return verticalScrollBar()->value() == verticalScrollBar()->maximum(); +} + +void TextView::scrollToBottom() +{ + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); +} + +void TextView::showEvent(QShowEvent *e) +{ + bool atBottom = isScrollbarAtBottom(); + QTextEdit::showEvent(e); + if (atBottom) + scrollToBottom(); +} + +void TextView::resizeEvent(QResizeEvent *e) +{ + //Keep scrollbar at bottom of window while resizing, to ensure we keep scrolling + //This can happen if window is resized while building, or if the horizontal scrollbar appears + bool atBottom = isScrollbarAtBottom(); + QTextEdit::resizeEvent(e); + if (atBottom) + scrollToBottom(); +} + diff --git a/src/plugins/coreplugin/messageoutputwindow.h b/src/plugins/coreplugin/messageoutputwindow.h index 3e4f18a8e5a..befdc7e74dc 100644 --- a/src/plugins/coreplugin/messageoutputwindow.h +++ b/src/plugins/coreplugin/messageoutputwindow.h @@ -36,13 +36,28 @@ #include -QT_BEGIN_NAMESPACE -class QTextEdit; -QT_END_NAMESPACE +#include +#include +#include namespace Core { namespace Internal { +class TextView : public QTextEdit +{ + Q_OBJECT + +public: + TextView(QWidget *parent = 0) : QTextEdit(parent) {} + + void showEvent(QShowEvent *); + void scrollToBottom(); + bool isScrollbarAtBottom() const; + +protected: + void resizeEvent(QResizeEvent *e); +}; + class MessageOutputWindow : public Core::IOutputPane { Q_OBJECT @@ -71,7 +86,7 @@ public: bool canNavigate(); private: - QTextEdit *m_widget; + TextView *m_widget; }; } // namespace Internal