-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathFileWindowLogger.h
More file actions
60 lines (44 loc) · 1.77 KB
/
FileWindowLogger.h
File metadata and controls
60 lines (44 loc) · 1.77 KB
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
/* File and Window Logger
*
* From: https://github.com/PokemonAutomation/
*
* Qt-dependent layer that adds GUI window support on top of the Qt-free FileLogger.
* The actual file I/O is handled by Common/Cpp/Logging/FileLogger.
*/
#ifndef PokemonAutomation_Logging_FileWindowLogger_H
#define PokemonAutomation_Logging_FileWindowLogger_H
#include <set>
#include <mutex>
#include <QTextEdit>
#include <QMainWindow>
#include "Common/Cpp/Logging/FileLogger.h"
#include "Common/Cpp/Options/ConfigOption.h"
namespace PokemonAutomation{
// A Qt window that displays log output from a FileWindowLogger.
// Uses Qt signals/slots for thread-safe updates from the logger's background thread.
class FileWindowLoggerWindow : public QMainWindow, public ConfigOption::Listener, public FileLogger::Listener{
Q_OBJECT
public:
FileWindowLoggerWindow(QWidget* parent = nullptr);
virtual ~FileWindowLoggerWindow();
// Called by FileWindowLogger to display a log message.
void log(QString msg);
// Callback function registered to the global logger.
// The global logger's background thread call it to display a log to the window.
// Thread-safe: emits a signal that is handled on the UI thread.
void on_log(const std::string& msg, Color color) override;
virtual void resizeEvent(QResizeEvent* event) override;
virtual void moveEvent(QMoveEvent* event) override;
signals:
void signal_log(QString msg);
private:
virtual void on_config_value_changed(void* object) override;
static QString to_window_str(const std::string& msg, Color color);
FileLogger& m_logger;
QMenuBar* m_menubar;
QTextEdit* m_text;
bool m_pending_resize = false;
bool m_pending_move = false;
};
}
#endif