Application output always scrolled, and moved the cursor.

Task-number: QTCREATORBUG-1790
Reviewed-by: dt
Reviewed-by: mae
This commit is contained in:
con
2010-07-06 15:06:33 +02:00
parent dec87b222b
commit 15047f8816
4 changed files with 19 additions and 44 deletions

View File

@@ -63,26 +63,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{ {
gotoEnd(); append(text, onStdErr ? StdErrFormat : StdOutFormat);
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
plainTextEdit()->insertPlainText(text);
} }
void OutputFormatter::appendMessage(const QString &text, bool isError) void OutputFormatter::appendMessage(const QString &text, bool isError)
{ {
gotoEnd(); append(text, isError ? ErrorMessageFormat : NormalMessageFormat);
}
if (isError) void OutputFormatter::append(const QString &text, Format format)
setFormat(ErrorMessageFormat); {
else append(text, m_formats[format]);
setFormat(NormalMessageFormat); }
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*/) void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
@@ -119,14 +117,3 @@ void OutputFormatter::initFormats()
m_formats[StdErrFormat].setFont(font); m_formats[StdErrFormat].setFont(font);
m_formats[StdErrFormat].setForeground(QColor(200, 0, 0)); 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);
}

View File

@@ -70,9 +70,8 @@ protected:
}; };
void initFormats(); void initFormats();
void setFormat(Format theFormat) const; void append(const QString &text, Format format);
void append(const QString &text, const QTextCharFormat &format);
void gotoEnd() const;
private: private:
QPlainTextEdit *m_plainTextEdit; QPlainTextEdit *m_plainTextEdit;

View File

@@ -496,8 +496,7 @@ void OutputWindow::appendMessage(const QString &out, bool isError)
bool OutputWindow::isScrollbarAtBottom() const bool OutputWindow::isScrollbarAtBottom() const
{ {
return blockBoundingRect(document()->lastBlock()).bottom() + contentOffset().y() return verticalScrollBar()->value() == verticalScrollBar()->maximum();
<= viewport()->rect().bottom();
} }
void OutputWindow::scrollToBottom() void OutputWindow::scrollToBottom()

View File

@@ -46,15 +46,7 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent)
void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{ {
gotoEnd(); QTextCharFormat linkFormat;
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat();
QTextCharFormat linkFormat = normalFormat;
linkFormat.setForeground(plainTextEdit()->palette().link().color()); linkFormat.setForeground(plainTextEdit()->palette().link().color());
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
linkFormat.setAnchor(true); linkFormat.setAnchor(true);
@@ -64,17 +56,15 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStd
while (m_qmlError.indexIn(text, index) != -1) { while (m_qmlError.indexIn(text, index) != -1) {
const int matchPos = m_qmlError.pos(1); const int matchPos = m_qmlError.pos(1);
const QString leader = text.mid(index, matchPos - index); const QString leader = text.mid(index, matchPos - index);
plainTextEdit()->insertPlainText(leader); append(leader, onStdErr ? StdErrFormat : StdOutFormat);
const QString matched = m_qmlError.cap(1); const QString matched = m_qmlError.cap(1);
linkFormat.setAnchorHref(matched); linkFormat.setAnchorHref(matched);
plainTextEdit()->setCurrentCharFormat(linkFormat); append(matched, linkFormat);
plainTextEdit()->insertPlainText(matched);
plainTextEdit()->setCurrentCharFormat(normalFormat);
index = matchPos + m_qmlError.matchedLength() - 1; index = matchPos + m_qmlError.matchedLength() - 1;
} }
plainTextEdit()->insertPlainText(text.mid(index)); append(text.mid(index), onStdErr ? StdErrFormat : StdOutFormat);
} }
void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/) void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/)