configure_ringcon.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2022 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <functional>
  6. #include <memory>
  7. #include <QDialog>
  8. namespace InputCommon {
  9. class InputSubsystem;
  10. } // namespace InputCommon
  11. namespace Core::HID {
  12. class HIDCore;
  13. class EmulatedDevices;
  14. } // namespace Core::HID
  15. namespace Ui {
  16. class ConfigureRingController;
  17. } // namespace Ui
  18. class ConfigureRingController : public QDialog {
  19. Q_OBJECT
  20. public:
  21. explicit ConfigureRingController(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_,
  22. Core::HID::HIDCore& hid_core_);
  23. ~ConfigureRingController() override;
  24. void ApplyConfiguration();
  25. private:
  26. void changeEvent(QEvent* event) override;
  27. void RetranslateUI();
  28. void UpdateUI();
  29. /// Load configuration settings.
  30. void LoadConfiguration();
  31. /// Restore all buttons to their default values.
  32. void RestoreDefaults();
  33. /// Called when the button was pressed.
  34. void HandleClick(QPushButton* button,
  35. std::function<void(const Common::ParamPackage&)> new_input_setter,
  36. InputCommon::Polling::InputType type);
  37. /// Finish polling and configure input using the input_setter.
  38. void SetPollingResult(const Common::ParamPackage& params, bool abort);
  39. /// Checks whether a given input can be accepted.
  40. bool IsInputAcceptable(const Common::ParamPackage& params) const;
  41. /// Handle mouse button press events.
  42. void mousePressEvent(QMouseEvent* event) override;
  43. /// Handle key press events.
  44. void keyPressEvent(QKeyEvent* event) override;
  45. QString ButtonToText(const Common::ParamPackage& param);
  46. QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
  47. static constexpr int ANALOG_SUB_BUTTONS_NUM = 2;
  48. // A group of four QPushButtons represent one analog input. The buttons each represent left,
  49. // right, respectively.
  50. std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM> analog_map_buttons;
  51. static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
  52. std::unique_ptr<QTimer> timeout_timer;
  53. std::unique_ptr<QTimer> poll_timer;
  54. /// This will be the the setting function when an input is awaiting configuration.
  55. std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
  56. InputCommon::InputSubsystem* input_subsystem;
  57. Core::HID::EmulatedDevices* emulated_device;
  58. std::unique_ptr<Ui::ConfigureRingController> ui;
  59. };