Qt: rework input configuration for new input system
This commit is contained in:
parent
51b1c1f211
commit
e7a602fe16
2 changed files with 144 additions and 68 deletions
|
@ -4,10 +4,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <QKeyEvent>
|
||||
#include <QWidget>
|
||||
#include <boost/optional.hpp>
|
||||
#include "common/param_package.h"
|
||||
#include "core/settings.h"
|
||||
#include "ui_configure_input.h"
|
||||
|
||||
|
@ -31,15 +35,25 @@ public:
|
|||
private:
|
||||
std::unique_ptr<Ui::ConfigureInput> ui;
|
||||
|
||||
/// This input is currently awaiting configuration.
|
||||
/// (i.e.: its corresponding QPushButton has been pressed.)
|
||||
boost::optional<Settings::NativeInput::Values> current_input_id;
|
||||
std::unique_ptr<QTimer> timer;
|
||||
|
||||
/// Each input is represented by a QPushButton.
|
||||
std::map<Settings::NativeInput::Values, QPushButton*> button_map;
|
||||
/// Each input is configured to respond to the press of a Qt::Key.
|
||||
std::map<Settings::NativeInput::Values, Qt::Key> key_map;
|
||||
/// This will be the the setting function when an input is awaiting configuration.
|
||||
boost::optional<std::function<void(int)>> key_setter;
|
||||
|
||||
std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
|
||||
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
|
||||
|
||||
static constexpr int ANALOG_SUB_BUTTONS_NUM = 5;
|
||||
|
||||
/// Each button input is represented by a QPushButton.
|
||||
std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
|
||||
|
||||
/// Each analog input is represented by five QPushButtons which represents up, down, left, right
|
||||
/// and modifier
|
||||
std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
|
||||
analog_map;
|
||||
|
||||
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
|
||||
|
||||
/// Load configuration settings.
|
||||
void loadConfiguration();
|
||||
|
@ -48,10 +62,8 @@ private:
|
|||
/// Update UI to reflect current configuration.
|
||||
void updateButtonLabels();
|
||||
|
||||
/// Called when the button corresponding to input_id was pressed.
|
||||
void handleClick(Settings::NativeInput::Values input_id);
|
||||
/// Called when the button was pressed.
|
||||
void handleClick(QPushButton* button, std::function<void(int)> new_key_setter);
|
||||
/// Handle key press events.
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
/// Configure input input_id to respond to key key_pressed.
|
||||
void setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue