Commit eb03bd1a authored by con's avatar con

General messages should stay at bottom when messages are posted

Fix is copying code from project explorer OutputWindow, which should be
shared instead.

Task-number: QTCREATORBUG-3839
Reviewed-by: Robert Loehning
parent c8e03e5e
......@@ -33,13 +33,13 @@
#include "messageoutputwindow.h"
#include <QtGui/QTextEdit>
#include <QtGui/QScrollBar>
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();
}
......@@ -36,13 +36,28 @@
#include <coreplugin/ioutputpane.h>
QT_BEGIN_NAMESPACE
class QTextEdit;
QT_END_NAMESPACE
#include <QtGui/QShowEvent>
#include <QtGui/QResizeEvent>
#include <QtGui/QTextEdit>
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment