20 #ifndef CONSOLE_OUTPUT_HANDLER_H
21 #define CONSOLE_OUTPUT_HANDLER_H
23 #include <QtGui/QPlainTextEdit>
24 #include <QtGui/QTextBrowser>
25 #include <QtGui/QTextBlock>
26 #include <QtGui/QApplication>
27 #include <QtCore/QTime>
29 class ConsoleOutputHandler :
public QObject {
35 ConsoleOutputHandler() {
42 void writeToConsole(QAbstractScrollArea *consoleWidget,
const QString &output,
bool errorOutput) {
47 QTextBrowser *textBrowser =
dynamic_cast<QTextBrowser*
>(consoleWidget);
48 QPlainTextEdit *textEdit =
dynamic_cast<QPlainTextEdit*
>(consoleWidget);
50 QBrush brush(Qt::SolidPattern);
53 brush.setColor(Qt::red);
56 brush.setColor(Qt::black);
60 QTextCharFormat formt;
63 formt = textEdit->textCursor().charFormat();
64 formt.setForeground(brush);
65 textEdit->moveCursor(QTextCursor::End);
66 cursor = textEdit->textCursor();
69 formt = textBrowser->textCursor().charFormat();
70 formt.setForeground(brush);
71 formt.setAnchor(
false);
72 formt.setUnderlineStyle(QTextCharFormat::NoUnderline);
73 formt.setAnchorHref(
"");
74 textBrowser->moveCursor(QTextCursor::End);
75 cursor = textBrowser->textCursor();
78 cursor.insertText(output, formt);
81 QRegExp rx(
"^.*File.*\"(.*)\".*line.*(\\d+).*$");
82 QRegExp rx2(
"^.*File.*\"(.*)\".*line.*(\\d+).*in (.*)$");
83 cursor = textBrowser->document()->find(rx, QTextCursor(textBrowser->document()->begin()));
85 while (!cursor.isNull()) {
86 rx.indexIn(cursor.selectedText());
87 rx2.indexIn(cursor.selectedText());
89 if (rx.cap(1) !=
"<string>" && rx2.cap(3) !=
"tlpimporthook") {
90 formt = cursor.charFormat();
91 formt.setAnchor(
true);
92 formt.setUnderlineStyle(QTextCharFormat::SingleUnderline);
93 formt.setAnchorHref(rx.cap(1) +
":" + rx.cap(2));
94 cursor.setCharFormat(formt);
97 cursor = textBrowser->document()->find(rx, cursor);
100 if (timer.elapsed() >= 50) {
101 QApplication::processEvents();
113 class ConsoleOutputEmitter :
public QObject {
119 ConsoleOutputEmitter() : _consoleWidget(NULL), _outputActivated(true) {}
121 void sendOutputToConsole(
const QString &output,
bool errorOutput) {
122 if (_outputActivated) {
123 emit consoleOutput(_consoleWidget, output, errorOutput);
127 void setConsoleWidget(QAbstractScrollArea *consoleWidget) {
128 _consoleWidget = consoleWidget;
131 QAbstractScrollArea *consoleWidget()
const {
132 return _consoleWidget;
135 void setOutputActivated(
bool outputActivated) {
136 _outputActivated = outputActivated;
141 void consoleOutput(QAbstractScrollArea *consoleWidget,
const QString &output,
bool errorOutput);
145 QAbstractScrollArea *_consoleWidget;
146 bool _outputActivated;