1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Adds an eventFilter, in order to steal keypresses.

This commit is contained in:
Thomas Harte 2020-06-05 22:11:17 -04:00
parent 235efcb2d4
commit d62fb16a58
3 changed files with 23 additions and 1 deletions

View File

@ -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<QKeyEvent *>(event);
qDebug() << keyEvent->key() << " " << (event->type() == QEvent::KeyPress);
} break;
default:
break;
}
return QObject::eventFilter(obj, event);
}

View File

@ -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::MainWindow> ui;
std::unique_ptr<QTimer> qTimer;

View File

@ -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() {