aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/BrowserApp.cpp
blob: 0a82de0939e10cfbd54ba99db1522bb962a859a4 (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
#include <QKeyEvent>
#include <QtCore>

#include "LuaRuntime.hpp"
#include "widgets/BrowserApp.hpp"
#include "widgets/MainWindow.hpp"

BrowserApp::BrowserApp() {
  auto *lua = LuaRuntime::instance();
  lua->start_event_loop();

  // Global event filter
  qApp->installEventFilter(this);

  // NOTE: TMP
  lua->load_file("./config.lua");
};

MainWindow *BrowserApp::create_window() {
  auto *win = new MainWindow((const Configuration &)configuration);
  win->setWindowTitle("null-browser");
  windows.insert({last_id, win});
  last_id++;
  win->show();
  return win;
}

bool BrowserApp::eventFilter(QObject *target, QEvent *event) {
  if (event->type() != QEvent::KeyPress)
    return false;

  for (auto &match : 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;
}