forked from qt-creator/qt-creator
Added colors to the "Application Output" panel.
This commit is contained in:
@@ -29,13 +29,25 @@
|
||||
|
||||
#include "outputformatter.h"
|
||||
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace TextEditor;
|
||||
|
||||
OutputFormatter::OutputFormatter(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_formats(0)
|
||||
{
|
||||
initFormats();
|
||||
}
|
||||
|
||||
OutputFormatter::~OutputFormatter()
|
||||
{
|
||||
if (m_formats)
|
||||
delete[] m_formats;
|
||||
}
|
||||
|
||||
QPlainTextEdit *OutputFormatter::plainTextEdit() const
|
||||
@@ -49,17 +61,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
|
||||
setParent(m_plainTextEdit);
|
||||
}
|
||||
|
||||
void OutputFormatter::appendApplicationOutput(const QString &text, bool /*onStdErr*/)
|
||||
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
|
||||
{
|
||||
QTextCharFormat format;
|
||||
format.setForeground(plainTextEdit()->palette().text().color());
|
||||
plainTextEdit()->setCurrentCharFormat(format);
|
||||
if (onStdErr)
|
||||
setFormat(StdErrFormat);
|
||||
else
|
||||
setFormat(StdOutFormat);
|
||||
|
||||
plainTextEdit()->insertPlainText(text);
|
||||
}
|
||||
|
||||
void OutputFormatter::appendMessage(const QString &text, bool isError)
|
||||
{
|
||||
appendApplicationOutput(text, isError);
|
||||
if (isError)
|
||||
setFormat(ErrorMessageFormat);
|
||||
else
|
||||
setFormat(NormalMessageFormat);
|
||||
|
||||
plainTextEdit()->insertPlainText(text);
|
||||
}
|
||||
|
||||
void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
|
||||
@@ -70,3 +89,35 @@ void OutputFormatter::mouseReleaseEvent(QMouseEvent * /*e*/)
|
||||
|
||||
void OutputFormatter::mouseMoveEvent(QMouseEvent * /*e*/)
|
||||
{}
|
||||
|
||||
void OutputFormatter::initFormats()
|
||||
{
|
||||
FontSettings fs = TextEditorSettings::instance()->fontSettings();
|
||||
QFont font = fs.font();
|
||||
QFont boldFont = font;
|
||||
boldFont.setBold(true);
|
||||
|
||||
m_formats = new QTextCharFormat[NumberOfFormats];
|
||||
|
||||
// NormalMessageFormat
|
||||
m_formats[NormalMessageFormat].setFont(boldFont);
|
||||
m_formats[NormalMessageFormat].setForeground(QColor(Qt::black));
|
||||
|
||||
// ErrorMessageFormat
|
||||
m_formats[ErrorMessageFormat].setFont(boldFont);
|
||||
m_formats[ErrorMessageFormat].setForeground(QColor(Qt::red));
|
||||
|
||||
// StdOutFormat
|
||||
m_formats[StdOutFormat].setFont(font);
|
||||
m_formats[StdOutFormat].setForeground(QColor(Qt::black));
|
||||
|
||||
// StdErrFormat
|
||||
m_formats[StdErrFormat].setFont(font);
|
||||
m_formats[StdErrFormat].setForeground(QColor(Qt::red));
|
||||
}
|
||||
|
||||
void OutputFormatter::setFormat(Format theFormat) const
|
||||
{
|
||||
if (m_formats)
|
||||
plainTextEdit()->setCurrentCharFormat(m_formats[theFormat]);
|
||||
}
|
||||
|
@@ -35,8 +35,9 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit);
|
||||
QT_FORWARD_DECLARE_CLASS(QMouseEvent);
|
||||
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit);
|
||||
QT_FORWARD_DECLARE_CLASS(QTextCharFormat);
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
@@ -46,6 +47,7 @@ class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject
|
||||
|
||||
public:
|
||||
OutputFormatter(QObject *parent = 0);
|
||||
virtual ~OutputFormatter();
|
||||
|
||||
QPlainTextEdit *plainTextEdit() const;
|
||||
void setPlainTextEdit(QPlainTextEdit *plainText);
|
||||
@@ -57,8 +59,22 @@ public:
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
virtual void mouseMoveEvent(QMouseEvent *e);
|
||||
|
||||
protected:
|
||||
enum Format {
|
||||
NormalMessageFormat = 0,
|
||||
ErrorMessageFormat = 1,
|
||||
StdOutFormat = 2,
|
||||
StdErrFormat = 3,
|
||||
|
||||
NumberOfFormats = 4
|
||||
};
|
||||
|
||||
void initFormats();
|
||||
void setFormat(Format theFormat) const;
|
||||
|
||||
private:
|
||||
QPlainTextEdit *m_plainTextEdit;
|
||||
QTextCharFormat *m_formats;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -44,16 +44,18 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool /*onStdErr*/)
|
||||
void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
|
||||
{
|
||||
QTextCharFormat normalFormat, linkFormat;
|
||||
normalFormat.setForeground(plainTextEdit()->palette().text().color());
|
||||
linkFormat.setForeground(plainTextEdit()->palette().link().color());
|
||||
if (onStdErr)
|
||||
setFormat(StdErrFormat);
|
||||
else
|
||||
setFormat(StdOutFormat);
|
||||
|
||||
QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat();
|
||||
QTextCharFormat linkFormat = normalFormat;
|
||||
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
||||
linkFormat.setAnchor(true);
|
||||
|
||||
plainTextEdit()->setCurrentCharFormat(normalFormat);
|
||||
|
||||
// Create links from QML errors (anything of the form "file:///...:[line]:[column]:")
|
||||
int index = 0;
|
||||
while (m_qmlError.indexIn(text, index) != -1) {
|
||||
@@ -72,11 +74,6 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool /*onS
|
||||
plainTextEdit()->insertPlainText(text.mid(index));
|
||||
}
|
||||
|
||||
void QmlOutputFormatter::appendMessage(const QString &text, bool isError)
|
||||
{
|
||||
appendApplicationOutput(text, isError);
|
||||
}
|
||||
|
||||
void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
|
||||
{
|
||||
m_mousePressed = true;
|
||||
|
@@ -43,7 +43,6 @@ public:
|
||||
QmlOutputFormatter(QObject *parent = 0);
|
||||
|
||||
virtual void appendApplicationOutput(const QString &text, bool onStdErr);
|
||||
virtual void appendMessage(const QString &text, bool isError);
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
|
@@ -89,8 +89,8 @@ void QmlRunControl::start()
|
||||
Debugger::DebuggerUISwitcher::instance()->setActiveLanguage(Qml::Constants::LANG_QML);
|
||||
|
||||
emit started();
|
||||
emit addToOutputWindow(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
|
||||
m_commandLineArguments.join(QLatin1String(" "))), false);
|
||||
emit appendMessage(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
|
||||
m_commandLineArguments.join(QLatin1String(" "))), false);
|
||||
}
|
||||
|
||||
void QmlRunControl::stop()
|
||||
|
Reference in New Issue
Block a user