summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2011-11-04 17:17:26 +0000
committerAlex Merry <dev@randomguy3.me.uk>2011-11-04 17:17:26 +0000
commite850fd2feeee95491e4d58aa2499db9d7173ac5c (patch)
tree0407611eed8c083ad70db3751044c3616c432d0e
parentc34fead27404ea494c8642bf94a9f5c6f85fd8b9 (diff)
Improve the display of the message console
-rw-r--r--mpris2/testconsole.cpp53
-rw-r--r--mpris2/testconsole.h9
2 files changed, 49 insertions, 13 deletions
diff --git a/mpris2/testconsole.cpp b/mpris2/testconsole.cpp
index fce6dd2..365ae48 100644
--- a/mpris2/testconsole.cpp
+++ b/mpris2/testconsole.cpp
@@ -30,6 +30,14 @@ TestConsole::TestConsole(QWidget* parent)
edit = new QTextEdit();
layout->addWidget(edit);
edit->setReadOnly(true);
+ cursor = QTextCursor(edit->document());
+ plainFormat = cursor.charFormat();
+ errorFormat = cursor.charFormat();
+ errorFormat.setForeground(QBrush(Qt::red));
+ warningFormat = cursor.charFormat();
+ warningFormat.setForeground(QBrush(QColor(255,127,0)));
+ infoFormat = cursor.charFormat();
+ infoFormat.setForeground(QBrush(Qt::blue));
}
TestConsole::~TestConsole()
@@ -52,24 +60,45 @@ static QString locationName(InterfaceTest::LocationType locType, const QString&
void TestConsole::interfaceError(InterfaceTest::LocationType locType, const QString& location, const QString& desc)
{
- if (locType == Mpris2::InterfaceTest::Other && location.isEmpty())
- edit->append("Error: " + desc + "\n");
- else
- edit->append("Error at " + locationName(locType, location) + ": " + desc + "\n");
+ cursor.insertText("Error", errorFormat);
+ if (locType == Mpris2::InterfaceTest::Other && location.isEmpty()) {
+ cursor.insertText(": ", plainFormat);
+ } else {
+ cursor.insertText(" at ", plainFormat);
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(": ");
+ }
+ cursor.insertText(desc);
+ cursor.insertBlock();
}
void TestConsole::interfaceWarning(InterfaceTest::LocationType locType, const QString& location, const QString& desc)
{
- if (locType == Mpris2::InterfaceTest::Other && location.isEmpty())
- edit->append("Warning: " + desc + "\n");
- else
- edit->append("Warning at " + locationName(locType, location) + ": " + desc + "\n");
+ cursor.insertText("Warning", warningFormat);
+ if (locType == Mpris2::InterfaceTest::Other && location.isEmpty()) {
+ cursor.insertText(": ", plainFormat);
+ } else {
+ cursor.insertText(" at ", plainFormat);
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(": ");
+ }
+ cursor.insertText(desc);
+ cursor.insertBlock();
}
void TestConsole::interfaceInfo(InterfaceTest::LocationType locType, const QString& location, const QString& desc)
{
- if (locType == Mpris2::InterfaceTest::Other && location.isEmpty())
- edit->append("Info: " + desc + "\n");
- else
- edit->append("Info at " + locationName(locType, location) + ": " + desc + "\n");
+ cursor.insertText("Info", infoFormat);
+ if (locType == Mpris2::InterfaceTest::Other && location.isEmpty()) {
+ cursor.insertText(": ", plainFormat);
+ } else {
+ cursor.insertText(" at ", plainFormat);
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(locationName(locType, location));
+ cursor.insertText(": ");
+ }
+ cursor.insertText(desc);
+ cursor.insertBlock();
}
diff --git a/mpris2/testconsole.h b/mpris2/testconsole.h
index 4ac3039..d62c54f 100644
--- a/mpris2/testconsole.h
+++ b/mpris2/testconsole.h
@@ -20,9 +20,11 @@
#ifndef TESTCONSOLE_H
#define TESTCONSOLE_H
-#include <QtGui/QWidget>
#include "interfacetest.h"
+#include <QtGui/QWidget>
+#include <QTextCursor>
+
class QTextEdit;
namespace Mpris2
{
@@ -41,6 +43,11 @@ namespace Mpris2
private:
QTextEdit* edit;
+ QTextCursor cursor;
+ QTextCharFormat plainFormat;
+ QTextCharFormat errorFormat;
+ QTextCharFormat warningFormat;
+ QTextCharFormat infoFormat;
};
}