forked from qt-creator/qt-creator
Fixed the link style in the application output window.
Reviewed-by: Tobias Hunger
This commit is contained in:
@@ -88,7 +88,7 @@ void OutputFormatter::clearLastLine()
|
||||
cursor.removeSelectedText();
|
||||
}
|
||||
|
||||
static QColor mix_colors(QColor a, QColor b)
|
||||
QColor OutputFormatter::mixColors(const QColor &a, const QColor &b)
|
||||
{
|
||||
return QColor((a.red() + 2 * b.red()) / 3, (a.green() + 2 * b.green()) / 3,
|
||||
(a.blue() + 2* b.blue()) / 3, (a.alpha() + 2 * b.alpha()) / 3);
|
||||
@@ -108,11 +108,11 @@ void OutputFormatter::initFormats()
|
||||
|
||||
// NormalMessageFormat
|
||||
m_formats[NormalMessageFormat].setFont(boldFont);
|
||||
m_formats[NormalMessageFormat].setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::blue)));
|
||||
m_formats[NormalMessageFormat].setForeground(mixColors(p.color(QPalette::Text), QColor(Qt::blue)));
|
||||
|
||||
// ErrorMessageFormat
|
||||
m_formats[ErrorMessageFormat].setFont(boldFont);
|
||||
m_formats[ErrorMessageFormat].setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
|
||||
m_formats[ErrorMessageFormat].setForeground(mixColors(p.color(QPalette::Text), QColor(Qt::red)));
|
||||
|
||||
// StdOutFormat
|
||||
m_formats[StdOutFormat].setFont(font);
|
||||
@@ -120,7 +120,7 @@ void OutputFormatter::initFormats()
|
||||
|
||||
// StdErrFormat
|
||||
m_formats[StdErrFormat].setFont(font);
|
||||
m_formats[StdErrFormat].setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
|
||||
m_formats[StdErrFormat].setForeground(mixColors(p.color(QPalette::Text), QColor(Qt::red)));
|
||||
}
|
||||
|
||||
void OutputFormatter::handleLink(const QString &href)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QMouseEvent);
|
||||
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit);
|
||||
@@ -71,6 +72,8 @@ protected:
|
||||
void clearLastLine();
|
||||
QTextCharFormat format(Format format);
|
||||
|
||||
static QColor mixColors(const QColor &a, const QColor &b);
|
||||
|
||||
private:
|
||||
QPlainTextEdit *m_plainTextEdit;
|
||||
QTextCharFormat *m_formats;
|
||||
|
||||
@@ -77,14 +77,6 @@ LinkResult QtOutputFormatter::matchLine(const QString &line) const
|
||||
|
||||
void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdErr)
|
||||
{
|
||||
// Do the initialization lazily, as we don't have a plaintext edit
|
||||
// in the ctor
|
||||
if (!m_linkFormat.isValid()) {
|
||||
m_linkFormat.setForeground(plainTextEdit()->palette().link().color());
|
||||
m_linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
||||
m_linkFormat.setAnchor(true);
|
||||
}
|
||||
|
||||
QTextCursor cursor(plainTextEdit()->document());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
cursor.beginEditBlock();
|
||||
@@ -166,10 +158,18 @@ void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdEr
|
||||
|
||||
void QtOutputFormatter::appendLine(QTextCursor &cursor, LinkResult lr, const QString &line, bool onStdErr)
|
||||
{
|
||||
cursor.insertText(line.left(lr.start), format(onStdErr ? StdErrFormat : StdOutFormat));
|
||||
m_linkFormat.setAnchorHref(lr.href);
|
||||
cursor.insertText(line.mid(lr.start, lr.end - lr.start), m_linkFormat);
|
||||
cursor.insertText(line.mid(lr.end), format(onStdErr ? StdErrFormat : StdOutFormat));
|
||||
const QTextCharFormat normalFormat = format(onStdErr ? StdErrFormat : StdOutFormat);
|
||||
cursor.insertText(line.left(lr.start), normalFormat);
|
||||
|
||||
QTextCharFormat linkFormat = normalFormat;
|
||||
const QColor textColor = plainTextEdit()->palette().color(QPalette::Text);
|
||||
linkFormat.setForeground(mixColors(textColor, QColor(Qt::blue)));
|
||||
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
||||
linkFormat.setAnchor(true);
|
||||
linkFormat.setAnchorHref(lr.href);
|
||||
cursor.insertText(line.mid(lr.start, lr.end - lr.start), linkFormat);
|
||||
|
||||
cursor.insertText(line.mid(lr.end), normalFormat);
|
||||
}
|
||||
|
||||
void QtOutputFormatter::handleLink(const QString &href)
|
||||
|
||||
@@ -69,7 +69,6 @@ private:
|
||||
QRegExp m_qtAssert;
|
||||
QRegExp m_qtTestFail;
|
||||
QWeakPointer<ProjectExplorer::Project> m_project;
|
||||
QTextCharFormat m_linkFormat;
|
||||
QString m_lastLine;
|
||||
QString m_deferedText;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user