summaryrefslogtreecommitdiffstats
path: root/src/trace.cpp
blob: c41247eca1b2785e999bc4a902ecc53b80235b39 (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
#ifdef ENABLE_TRACING
#include <qapplication.h>
#include <qtextedit.h>
#include <qfile.h>
#include <stdio.h>

static QTextEdit *tracer = NULL;

void TRACER(QtMsgType, const char *msg)
{
  tracer->append(&msg[*msg == '~' ? 1 : 0]);
  if (msg[0] != '~')
  {
    fprintf(stderr, msg);
    fprintf(stderr, "\r\n");
  }
}

void INIT_TRACE()
{
  if (tracer) return;     // de javu
  tracer = new QTextEdit();
  tracer->setTextFormat(Qt::LogText);
  tracer->setMaxLogLines(10000);
  tracer->resize(750, 300);
  qInstallMsgHandler(TRACER);
}

void SHOW_TRACE()
{
  tracer->show();
}

void DUMP_TRACE(const char *f)
{
  QFile file(f); // Write the text to a file
  if (file.open(IO_WriteOnly))
  {
    QTextStream stream(&file);
    stream << tracer->text();
  }
}

#endif // ENABLE_TRACER