diff --git a/src/plugins/projectexplorer/outputformatter.cpp b/src/plugins/projectexplorer/outputformatter.cpp index 0cb8b7ea5a7..69bb04b72ea 100644 --- a/src/plugins/projectexplorer/outputformatter.cpp +++ b/src/plugins/projectexplorer/outputformatter.cpp @@ -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); -} diff --git a/src/plugins/projectexplorer/outputformatter.h b/src/plugins/projectexplorer/outputformatter.h index 3c8ff1ecd6a..effff7725a0 100644 --- a/src/plugins/projectexplorer/outputformatter.h +++ b/src/plugins/projectexplorer/outputformatter.h @@ -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; diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index 390986c0671..8e1a12a5cbe 100644 --- a/src/plugins/projectexplorer/outputwindow.cpp +++ b/src/plugins/projectexplorer/outputwindow.cpp @@ -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() diff --git a/src/plugins/qmlprojectmanager/qmloutputformatter.cpp b/src/plugins/qmlprojectmanager/qmloutputformatter.cpp index 0b4eaf6dc69..bd371334db1 100644 --- a/src/plugins/qmlprojectmanager/qmloutputformatter.cpp +++ b/src/plugins/qmlprojectmanager/qmloutputformatter.cpp @@ -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*/)