Skip to content
Snippets Groups Projects
Commit 24a9a22b authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added colors to the "Application Output" panel.

parent 825cea08
No related branches found
No related tags found
No related merge requests found
...@@ -29,13 +29,25 @@ ...@@ -29,13 +29,25 @@
#include "outputformatter.h" #include "outputformatter.h"
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <QtGui/QPlainTextEdit> #include <QtGui/QPlainTextEdit>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace TextEditor;
OutputFormatter::OutputFormatter(QObject *parent) OutputFormatter::OutputFormatter(QObject *parent)
: QObject(parent) : QObject(parent)
, m_formats(0)
{ {
initFormats();
}
OutputFormatter::~OutputFormatter()
{
if (m_formats)
delete[] m_formats;
} }
QPlainTextEdit *OutputFormatter::plainTextEdit() const QPlainTextEdit *OutputFormatter::plainTextEdit() const
...@@ -49,17 +61,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText) ...@@ -49,17 +61,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
setParent(m_plainTextEdit); setParent(m_plainTextEdit);
} }
void OutputFormatter::appendApplicationOutput(const QString &text, bool /*onStdErr*/) void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{ {
QTextCharFormat format; if (onStdErr)
format.setForeground(plainTextEdit()->palette().text().color()); setFormat(StdErrFormat);
plainTextEdit()->setCurrentCharFormat(format); else
setFormat(StdOutFormat);
plainTextEdit()->insertPlainText(text); plainTextEdit()->insertPlainText(text);
} }
void OutputFormatter::appendMessage(const QString &text, bool isError) 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*/) void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
...@@ -70,3 +89,35 @@ void OutputFormatter::mouseReleaseEvent(QMouseEvent * /*e*/) ...@@ -70,3 +89,35 @@ void OutputFormatter::mouseReleaseEvent(QMouseEvent * /*e*/)
void OutputFormatter::mouseMoveEvent(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 @@ ...@@ -35,8 +35,9 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QString> #include <QtCore/QString>
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit);
QT_FORWARD_DECLARE_CLASS(QMouseEvent); QT_FORWARD_DECLARE_CLASS(QMouseEvent);
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit);
QT_FORWARD_DECLARE_CLASS(QTextCharFormat);
namespace ProjectExplorer { namespace ProjectExplorer {
...@@ -46,6 +47,7 @@ class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject ...@@ -46,6 +47,7 @@ class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject
public: public:
OutputFormatter(QObject *parent = 0); OutputFormatter(QObject *parent = 0);
virtual ~OutputFormatter();
QPlainTextEdit *plainTextEdit() const; QPlainTextEdit *plainTextEdit() const;
void setPlainTextEdit(QPlainTextEdit *plainText); void setPlainTextEdit(QPlainTextEdit *plainText);
...@@ -57,8 +59,22 @@ public: ...@@ -57,8 +59,22 @@ public:
virtual void mouseReleaseEvent(QMouseEvent *e); virtual void mouseReleaseEvent(QMouseEvent *e);
virtual void mouseMoveEvent(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: private:
QPlainTextEdit *m_plainTextEdit; QPlainTextEdit *m_plainTextEdit;
QTextCharFormat *m_formats;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer
......
...@@ -44,16 +44,18 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent) ...@@ -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; if (onStdErr)
normalFormat.setForeground(plainTextEdit()->palette().text().color()); setFormat(StdErrFormat);
linkFormat.setForeground(plainTextEdit()->palette().link().color()); else
setFormat(StdOutFormat);
QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat();
QTextCharFormat linkFormat = normalFormat;
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
linkFormat.setAnchor(true); linkFormat.setAnchor(true);
plainTextEdit()->setCurrentCharFormat(normalFormat);
// Create links from QML errors (anything of the form "file:///...:[line]:[column]:") // Create links from QML errors (anything of the form "file:///...:[line]:[column]:")
int index = 0; int index = 0;
while (m_qmlError.indexIn(text, index) != -1) { while (m_qmlError.indexIn(text, index) != -1) {
...@@ -72,11 +74,6 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool /*onS ...@@ -72,11 +74,6 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool /*onS
plainTextEdit()->insertPlainText(text.mid(index)); plainTextEdit()->insertPlainText(text.mid(index));
} }
void QmlOutputFormatter::appendMessage(const QString &text, bool isError)
{
appendApplicationOutput(text, isError);
}
void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/) void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
{ {
m_mousePressed = true; m_mousePressed = true;
......
...@@ -43,7 +43,6 @@ public: ...@@ -43,7 +43,6 @@ public:
QmlOutputFormatter(QObject *parent = 0); QmlOutputFormatter(QObject *parent = 0);
virtual void appendApplicationOutput(const QString &text, bool onStdErr); virtual void appendApplicationOutput(const QString &text, bool onStdErr);
virtual void appendMessage(const QString &text, bool isError);
virtual void mousePressEvent(QMouseEvent *e); virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e); virtual void mouseReleaseEvent(QMouseEvent *e);
......
...@@ -89,8 +89,8 @@ void QmlRunControl::start() ...@@ -89,8 +89,8 @@ void QmlRunControl::start()
Debugger::DebuggerUISwitcher::instance()->setActiveLanguage(Qml::Constants::LANG_QML); Debugger::DebuggerUISwitcher::instance()->setActiveLanguage(Qml::Constants::LANG_QML);
emit started(); emit started();
emit addToOutputWindow(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable), emit appendMessage(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
m_commandLineArguments.join(QLatin1String(" "))), false); m_commandLineArguments.join(QLatin1String(" "))), false);
} }
void QmlRunControl::stop() void QmlRunControl::stop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment