Qt: Allow rebinding keyboard controls (#779)
* Initial input UI draft Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * More keybinding work Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * Nit Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * More nits Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> --------- Co-authored-by: Paris Oplopoios <parisoplop@gmail.com>
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "frontend_settings.hpp"
|
||||
#include "input_mappings.hpp"
|
||||
#include "panda_qt/input_window.hpp"
|
||||
|
||||
class ConfigWindow : public QDialog {
|
||||
Q_OBJECT
|
||||
@@ -30,8 +32,9 @@ class ConfigWindow : public QDialog {
|
||||
QTextEdit* helpText = nullptr;
|
||||
QListWidget* widgetList = nullptr;
|
||||
QStackedWidget* widgetContainer = nullptr;
|
||||
InputWindow* inputWindow = nullptr;
|
||||
|
||||
static constexpr size_t settingWidgetCount = 6;
|
||||
static constexpr size_t settingWidgetCount = 7;
|
||||
std::array<QString, settingWidgetCount> helpTexts;
|
||||
|
||||
// The config class holds a copy of the emulator config which it edits and sends
|
||||
@@ -52,6 +55,7 @@ class ConfigWindow : public QDialog {
|
||||
~ConfigWindow();
|
||||
|
||||
EmulatorConfig& getConfig() { return config; }
|
||||
InputWindow* getInputWindow() { return inputWindow; }
|
||||
|
||||
private:
|
||||
Emulator* emu;
|
||||
|
||||
32
include/panda_qt/input_window.hpp
Normal file
32
include/panda_qt/input_window.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QKeySequence>
|
||||
#include <QMap>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "input_mappings.hpp"
|
||||
|
||||
class InputWindow : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InputWindow(QWidget* parent = nullptr);
|
||||
|
||||
void loadFromMappings(const InputMappings& mappings);
|
||||
void applyToMappings(InputMappings& mappings) const;
|
||||
|
||||
signals:
|
||||
void mappingsChanged();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
QMap<QString, QPushButton*> buttonMap;
|
||||
QMap<QString, QKeySequence> keyMappings;
|
||||
|
||||
QString waitingForAction;
|
||||
|
||||
void startKeyCapture(const QString& action);
|
||||
};
|
||||
@@ -43,7 +43,6 @@ class MainWindow : public QMainWindow {
|
||||
Pause,
|
||||
Resume,
|
||||
TogglePause,
|
||||
DumpRomFS,
|
||||
PressKey,
|
||||
ReleaseKey,
|
||||
SetCirclePadX,
|
||||
@@ -134,6 +133,9 @@ class MainWindow : public QMainWindow {
|
||||
void dispatchMessage(const EmulatorMessage& message);
|
||||
void loadTranslation();
|
||||
|
||||
void loadKeybindings();
|
||||
void saveKeybindings();
|
||||
|
||||
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
|
||||
bool usingGL = false;
|
||||
bool usingVk = false;
|
||||
@@ -145,6 +147,9 @@ class MainWindow : public QMainWindow {
|
||||
bool keyboardAnalogX = false;
|
||||
bool keyboardAnalogY = false;
|
||||
|
||||
// Tracks if keybindings changed, in which case we should update the keybindings file when closing the emulator
|
||||
bool keybindingsChanged = false;
|
||||
|
||||
public:
|
||||
MainWindow(QApplication* app, QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
Reference in New Issue
Block a user