1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 23:32:28 +00:00

Installs and removes an 'Input' menu where required.

Also ensures safe shutdown of a second machine.
This commit is contained in:
Thomas Harte 2020-07-09 23:47:38 -04:00
parent 56e5491e5c
commit f72570386c
2 changed files with 40 additions and 1 deletions

View File

@ -72,6 +72,8 @@ void MainWindow::deleteMachine() {
if(displayMenu) menuBar()->removeAction(displayMenu->menuAction());
if(enhancementsMenu) menuBar()->removeAction(enhancementsMenu->menuAction());
if(controlsMenu) menuBar()->removeAction(controlsMenu->menuAction());
if(inputMenu) menuBar()->removeAction(inputMenu->menuAction());
displayMenu = enhancementsMenu = controlsMenu = inputMenu = nullptr;
}
MainWindow::~MainWindow() {
@ -360,6 +362,38 @@ void MainWindow::launchMachine() {
insertAction->setEnabled(true);
}
// Add an 'input' menu if justified (i.e. machine has both a keyboard and joystick input, and the keyboard is exclusive).
auto keyboardMachine = machine->keyboard_machine();
auto joystickMachine = machine->joystick_machine();
if(keyboardMachine && joystickMachine && keyboardMachine->get_keyboard().is_exclusive()) {
inputMenu = menuBar()->addMenu(tr("&Input"));
QAction *const asKeyboardAction = new QAction(tr("Use Keyboard as Keyboard"), this);
asKeyboardAction->setCheckable(true);
asKeyboardAction->setChecked(true);
asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
inputMenu->addAction(asKeyboardAction);
QAction *const asJoystickAction = new QAction(tr("Use Keyboard as Joystick"), this);
asJoystickAction->setCheckable(true);
asJoystickAction->setChecked(false);
asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
inputMenu->addAction(asJoystickAction);
connect(asKeyboardAction, &QAction::triggered, this, [=] {
keyboardInputMode = KeyboardInputMode::Keyboard;
asKeyboardAction->setChecked(true);
asJoystickAction->setChecked(false);
});
connect(asJoystickAction, &QAction::triggered, this, [=] {
keyboardInputMode = KeyboardInputMode::Joystick;
asKeyboardAction->setChecked(false);
asJoystickAction->setChecked(true);
});
}
keyboardInputMode = keyboardMachine ? KeyboardInputMode::Keyboard : KeyboardInputMode::Joystick;
// Add machine-specific UI.
const std::string settingsPrefix = Machine::ShortNameForTargetMachine(machineType);
switch(machineType) {
@ -770,7 +804,6 @@ void MainWindow::changeEvent(QEvent *event) {
event->ignore();
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
processEvent(event);
}

View File

@ -91,6 +91,10 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
void start_zx80();
void start_zx81();
enum class KeyboardInputMode {
Keyboard, Joystick
} keyboardInputMode;
QAction *insertAction = nullptr;
void insertFile(const QString &fileName);
@ -132,6 +136,8 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
QMenu *helpMenu = nullptr;
void addHelpMenu();
QMenu *inputMenu = nullptr;
std::optional<Inputs::Keyboard::Key> keyForEvent(QKeyEvent *);
};