aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/debugconsole.cpp
blob: 47387e6aa48b2fd9b33393c963e5335e593f1fc7 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "debugconsole.h"
#include "ui_debugconsole.h"
#include "iconmanager.h"
#include <QPushButton>

DebugConsole::DebugConsole(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DebugConsole)
{
    ui->setupUi(this);
    ui->textEdit->setReadOnly(true);

    QPushButton* resetBtn = ui->buttonBox->button(QDialogButtonBox::Reset);
    connect(resetBtn, SIGNAL(clicked()), this, SLOT(reset()));

    initFormats();
}

DebugConsole::~DebugConsole()
{
    delete ui;
}

void DebugConsole::debug(const QString &msg)
{
    message(msg, dbgFormat);
}

void DebugConsole::warning(const QString &msg)
{
    message(msg, wrnFormat);
}

void DebugConsole::critical(const QString &msg)
{
    message(msg, criFormat);
}

void DebugConsole::fatal(const QString &msg)
{
    message(msg, fatFormat);
}

void DebugConsole::initFormats()
{
    dbgFormat.setForeground(Qt::blue);
    wrnFormat.setForeground(Qt::darkRed);
    criFormat.setForeground(Qt::red);
    criFormat.setFontUnderline(true);
    fatFormat.setForeground(Qt::red);
    fatFormat.setFontUnderline(true);

    QFontMetrics fm(ui->textEdit->font());
    int indent = fm.horizontalAdvance(QString("X").repeated(25));
    ui->textEdit->document()->setIndentWidth(indent);

    blockFormat.setIndent(1);
    blockFormat.setTextIndent(-indent);
}

void DebugConsole::message(const QString &msg, const QTextCharFormat &format)
{
    ui->textEdit->setCurrentCharFormat(format);
    QTextCursor cur = ui->textEdit->textCursor();

    cur.insertText(msg);
    cur.mergeBlockFormat(blockFormat);
    cur.insertBlock(blockFormat);
}

void DebugConsole::reset()
{
    ui->textEdit->clear();
}

void DebugConsole::showEvent(QShowEvent*)
{
    setWindowIcon(ICONS.SQLITESTUDIO_APP);
}