1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Ensures keyboard events are restricted to single windows.

This commit is contained in:
Thomas Harte 2020-07-02 22:03:12 -04:00
parent b850183a1e
commit 8bf5ed52ea
2 changed files with 15 additions and 21 deletions

View File

@ -1,7 +1,9 @@
#include <QtWidgets>
#include <QObject>
#include <QStandardPaths>
#include <QtWidgets>
#include <QtGlobal>
#include "mainwindow.h"
#include "settings.h"
#include "timer.h"
@ -217,7 +219,9 @@ void MainWindow::tile(const QMainWindow *previous) {
topFrameWidth = 40;
const QPoint pos = previous->pos() + 2 * QPoint(topFrameWidth, topFrameWidth);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (screen()->availableGeometry().contains(rect().bottomRight() + pos))
#endif
move(pos);
}
@ -687,25 +691,6 @@ void MainWindow::dropEvent(QDropEvent* event) {
}
}
// 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);
if(!processEvent(keyEvent)) {
return false;
}
} break;
default:
break;
}
return QObject::eventFilter(obj, event);
}
void MainWindow::setUIPhase(UIPhase phase) {
uiPhase = phase;
@ -750,6 +735,14 @@ void MainWindow::setUIPhase(UIPhase phase) {
// MARK: - Event Processing
void MainWindow::keyPressEvent(QKeyEvent *event) {
processEvent(event);
}
void MainWindow::keyReleaseEvent(QKeyEvent *event) {
processEvent(event);
}
bool MainWindow::processEvent(QKeyEvent *event) {
if(!machine) return true;

View File

@ -32,7 +32,8 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
explicit MainWindow(const QString &fileName);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
private:
std::unique_ptr<Ui::MainWindow> ui;