blob: 13d855b104d5a9e7c6985c012fc3bfada14eb646 (
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
|
#include <QKeyEvent>
#include <QtCore>
#include "LuaRuntime.hpp"
#include "WindowActionRouter.hpp"
#include "widgets/BrowserApp.hpp"
#include "widgets/BrowserWindow.hpp"
BrowserApp::BrowserApp() {
auto *lua = LuaRuntime::instance();
lua->start_event_loop();
// Router init
auto *router = WindowActionRouter::instance();
router->initialize();
// Global event filter
qApp->installEventFilter(this);
// NOTE: TMP
LuaRuntime::instance()->load_file("./config.lua");
};
BrowserWindow *BrowserApp::create_window() {
auto *win = new BrowserWindow((const Configuration &)configuration);
WindowActionRouter::instance()->add_window(win);
win->setWindowTitle("null-browser");
win->show();
return win;
}
bool BrowserApp::eventFilter(QObject *target, QEvent *event) {
if (event->type() != QEvent::KeyPress)
return false;
for (const auto &match : WindowActionRouter::instance()->windows()) {
auto *win = match.second;
if (auto *target_widget = dynamic_cast<QWidget *>(target);
win->isAncestorOf(target_widget)) {
auto *key_event = static_cast<QKeyEvent *>(event);
const bool should_skip = win->on_window_key_event(key_event);
return should_skip;
}
}
return false;
}
|