blob: 86632a78891a77d981a1820eabd320e1429f28a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2008 Nanorex, Inc. See LICENSE file for details.
#include "LogHandlerWidget.h"
/* CONSTRUCTOR */
LogHandlerWidget::LogHandlerWidget(NXLogLevel logLevel, QWidget* parent)
: QWidget(parent), NXLogHandler(logLevel), Ui_LogHandlerWidget() {
setupUi(this);
QFont font;
#if defined(WIN32)
font.setPointSize(8); // TODO: set
#elif defined(__APPLE__)
font.setPointSize(11);
#else
// Linux
font.setPointSize(8);
#endif
textEdit->setFont(font);
}
/* FUNCTION: sizeHint */
QSize LogHandlerWidget::sizeHint() const {
return QSize(50, 50);
}
/* FUNCTION: publish */
void LogHandlerWidget::publish(LogRecord logRecord) {
if (logRecord.getLogLevel() >= logLevel) {
//mutex.lock();
QString color = "";
QString bgcolor = "";
if (logRecord.getLogLevel() == 3)
bgcolor = "yellow";
if (logRecord.getLogLevel() == 4) {
bgcolor = "orange";
}
QString level =
QString("%1").arg(LogLevelNames[logRecord.getLogLevel()], 7);
level.replace(QString(" "), QString(" "));
QString source =
logRecord.getSource().length() == 0 ?
"" : logRecord.getSource().append(": ").c_str();
QString message =
QString("<table border=0 cellspacing=0 cellpadding=0><tr><td><font color=grey>%1 </font></td><td bgcolor=%2><font type=courier color=%3>[<code>%4</code>] </font></td><td bgcolor=%2><font color=%3>%5 %6</font></td></tr></table>")
.arg(logRecord.getDateTime()
.toString("yyyy-MM-dd hh:mm:ss.zzz"))
.arg(bgcolor).arg(color)
.arg(level)
.arg(source)
.arg(logRecord.getMessage().c_str());
textEdit->insertHtml(message);
textEdit->ensureCursorVisible();
if (logRecord.getLogLevel() > 2)
emit raiseWidget();
//mutex.unlock();
}
}
|