Add new widget ToolButtonBox. Add setting to prevent display blanking.
[dorian] / trace.h
1 #ifndef TRACE_H
2 #define TRACE_H
3
4 #include <QtDebug>
5 #include <QString>
6 #include <QTime>
7 #include <QEvent>
8
9 class Trace
10 {
11 public:
12     Trace(const QString &s): name(s) {
13         qDebug() << prefix() + ">" + name;
14         indent++;
15     }
16
17     ~Trace() {
18         if (--indent < 0) {
19             indent = 0;
20         }
21         qDebug() << prefix() + "<" + name;
22     }
23
24     static void trace(const QString &s) {
25         qDebug() << prefix() + s;
26     }
27
28     static QString event(QEvent::Type t) {
29         for (int i = 0; eventTab[i].name; i++) {
30             if (eventTab[i].type == t) {
31                 return eventTab[i].name;
32             }
33         }
34         if (t >= QEvent::User) {
35             return QString("QEvent::User+%1").arg(t - QEvent::User);
36         } else {
37             return QString("Unknown event %1").arg(t);
38         }
39     }
40
41     static void messageHandler(QtMsgType type, const char *msg);
42
43     static QtMsgType level;
44
45 protected:
46     static QString prefix() {
47         return QTime::currentTime().toString("hh:mm:ss.zzz ") +
48             QString(" ").repeated(indent);
49     }
50     QString name;
51     static int indent;
52     typedef struct {int type; const char *name;} EventName;
53     static EventName eventTab[];
54 };
55
56 #endif // TRACE_H