From d62fb16a5884ee4e338e095a0b864184e6cbdfc2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 5 Jun 2020 22:11:17 -0400 Subject: [PATCH] Adds an eventFilter, in order to steal keypresses. --- OSBindings/Qt/mainwindow.cpp | 19 +++++++++++++++++++ OSBindings/Qt/mainwindow.h | 3 +++ OSBindings/Qt/scantargetwidget.cpp | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index e32cbc2c1..ffb646bc4 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -22,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); createActions(); + qApp->installEventFilter(this); // Set up the emulation timer. Bluffer's guide: the QTimer will post an // event to an event loop. QThread is a thread with an event loop. @@ -250,3 +251,21 @@ void MainWindow::dropEvent(QDropEvent* event) { break; } } + +// MARK: Input capture. + +bool MainWindow::eventFilter(QObject *obj, QEvent *event) { + switch(event->type()) { + case QEvent::KeyPress: + case QEvent::KeyRelease: { + const auto keyEvent = static_cast(event); + qDebug() << keyEvent->key() << " " << (event->type() == QEvent::KeyPress); + } break; + + default: + break; + } + + return QObject::eventFilter(obj, event); +} + diff --git a/OSBindings/Qt/mainwindow.h b/OSBindings/Qt/mainwindow.h index 66d600154..970f439bb 100644 --- a/OSBindings/Qt/mainwindow.h +++ b/OSBindings/Qt/mainwindow.h @@ -22,6 +22,9 @@ class MainWindow : public QMainWindow { MainWindow(QWidget *parent = nullptr); ~MainWindow(); + protected: + bool eventFilter(QObject *obj, QEvent *event) override; + private: std::unique_ptr ui; std::unique_ptr qTimer; diff --git a/OSBindings/Qt/scantargetwidget.cpp b/OSBindings/Qt/scantargetwidget.cpp index ce77e8585..33c133425 100644 --- a/OSBindings/Qt/scantargetwidget.cpp +++ b/OSBindings/Qt/scantargetwidget.cpp @@ -10,7 +10,7 @@ ScanTargetWidget::~ScanTargetWidget() {} void ScanTargetWidget::initializeGL() { glClearColor(0.5, 0.5, 1.0, 1.0); - qDebug() << "share context: " << bool(context()->shareGroup()); +// qDebug() << "share context: " << bool(context()->shareGroup()); } void ScanTargetWidget::paintGL() {