Commit 15047f88 authored by con's avatar con
Browse files

Application output always scrolled, and moved the cursor.

Task-number: QTCREATORBUG-1790
Reviewed-by: dt
Reviewed-by: mae
parent dec87b22
......@@ -63,26 +63,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{
gotoEnd();
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
plainTextEdit()->insertPlainText(text);
append(text, onStdErr ? StdErrFormat : StdOutFormat);
}
void OutputFormatter::appendMessage(const QString &text, bool isError)
{
gotoEnd();
append(text, isError ? ErrorMessageFormat : NormalMessageFormat);
}
if (isError)
setFormat(ErrorMessageFormat);
else
setFormat(NormalMessageFormat);
void OutputFormatter::append(const QString &text, Format format)
{
append(text, m_formats[format]);
}
plainTextEdit()->insertPlainText(text);
void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format);
}
void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
......@@ -119,14 +117,3 @@ void OutputFormatter::initFormats()
m_formats[StdErrFormat].setFont(font);
m_formats[StdErrFormat].setForeground(QColor(200, 0, 0));
}
void OutputFormatter::setFormat(Format theFormat) const
{
if (m_formats)
plainTextEdit()->setCurrentCharFormat(m_formats[theFormat]);
}
void OutputFormatter::gotoEnd() const
{
plainTextEdit()->moveCursor(QTextCursor::End);
}
......@@ -70,9 +70,8 @@ protected:
};
void initFormats();
void setFormat(Format theFormat) const;
void gotoEnd() const;
void append(const QString &text, Format format);
void append(const QString &text, const QTextCharFormat &format);
private:
QPlainTextEdit *m_plainTextEdit;
......
......@@ -496,8 +496,7 @@ void OutputWindow::appendMessage(const QString &out, bool isError)
bool OutputWindow::isScrollbarAtBottom() const
{
return blockBoundingRect(document()->lastBlock()).bottom() + contentOffset().y()
<= viewport()->rect().bottom();
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
}
void OutputWindow::scrollToBottom()
......
......@@ -46,15 +46,7 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent)
void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{
gotoEnd();
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat();
QTextCharFormat linkFormat = normalFormat;
QTextCharFormat linkFormat;
linkFormat.setForeground(plainTextEdit()->palette().link().color());
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
linkFormat.setAnchor(true);
......@@ -64,17 +56,15 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStd
while (m_qmlError.indexIn(text, index) != -1) {
const int matchPos = m_qmlError.pos(1);
const QString leader = text.mid(index, matchPos - index);
plainTextEdit()->insertPlainText(leader);
append(leader, onStdErr ? StdErrFormat : StdOutFormat);
const QString matched = m_qmlError.cap(1);
linkFormat.setAnchorHref(matched);
plainTextEdit()->setCurrentCharFormat(linkFormat);
plainTextEdit()->insertPlainText(matched);
plainTextEdit()->setCurrentCharFormat(normalFormat);
append(matched, linkFormat);
index = matchPos + m_qmlError.matchedLength() - 1;
}
plainTextEdit()->insertPlainText(text.mid(index));
append(text.mid(index), onStdErr ? StdErrFormat : StdOutFormat);
}
void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
......
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