-
Notifications
You must be signed in to change notification settings - Fork 5
/
logger.cpp
38 lines (30 loc) · 839 Bytes
/
logger.cpp
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
/*
* This application is free software and is released under the terms of
* the BSD license. See LICENSE file for details.
*
* Copyright (c) 2013 Volker Poplawski ([email protected])
*/
#include "logger.h"
const QString typeStrs[]{"INFO", "WARN", "ERROR"};
class MyTextEdit : public QTextEdit
{
protected:
virtual void contextMenuEvent(QContextMenuEvent *e) override
{
QMenu *menu = createStandardContextMenu();
menu->addAction("Clear", this, SLOT(clear()));
menu->exec(e->globalPos());
delete menu;
}
};
Logger::Logger(QObject *parent) :
QObject(parent)
{
m_textEdit = new MyTextEdit;
m_textEdit->setReadOnly(true);
// m_textEdit->setFontFamily("monospace");
}
void Logger::log(Logger::Type type, const QString& msg)
{
m_textEdit->append(typeStrs[(int)type] + ": " + msg);
}