configure_input.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <QKeyEvent>
  7. #include <QWidget>
  8. #include <boost/optional.hpp>
  9. #include "core/settings.h"
  10. #include "ui_configure_input.h"
  11. class QPushButton;
  12. class QString;
  13. class QTimer;
  14. namespace Ui {
  15. class ConfigureInput;
  16. }
  17. class ConfigureInput : public QWidget {
  18. Q_OBJECT
  19. public:
  20. explicit ConfigureInput(QWidget* parent = nullptr);
  21. /// Save all button configurations to settings file
  22. void applyConfiguration();
  23. private:
  24. std::unique_ptr<Ui::ConfigureInput> ui;
  25. /// This input is currently awaiting configuration.
  26. /// (i.e.: its corresponding QPushButton has been pressed.)
  27. boost::optional<Settings::NativeInput::Values> current_input_id;
  28. std::unique_ptr<QTimer> timer;
  29. /// Each input is represented by a QPushButton.
  30. std::map<Settings::NativeInput::Values, QPushButton*> button_map;
  31. /// Each input is configured to respond to the press of a Qt::Key.
  32. std::map<Settings::NativeInput::Values, Qt::Key> key_map;
  33. /// Load configuration settings.
  34. void loadConfiguration();
  35. /// Restore all buttons to their default values.
  36. void restoreDefaults();
  37. /// Update UI to reflect current configuration.
  38. void updateButtonLabels();
  39. /// Called when the button corresponding to input_id was pressed.
  40. void handleClick(Settings::NativeInput::Values input_id);
  41. /// Handle key press events.
  42. void keyPressEvent(QKeyEvent* event) override;
  43. /// Configure input input_id to respond to key key_pressed.
  44. void setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed);
  45. };