configure_input.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "citra_qt/config.h"
  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. std::map<Settings::NativeInput::Values, QPushButton*> input_mapping;
  26. int key_pressed;
  27. QPushButton* changing_button = nullptr; ///< button currently waiting for key press.
  28. QString previous_mapping;
  29. QTimer* timer;
  30. /// Load configuration settings into button text
  31. void setConfiguration();
  32. /// Check all inputs for duplicate keys. Clears out any other button with the same value as this
  33. /// button's new value.
  34. void removeDuplicates(const QString& newValue);
  35. /// Handle key press event for input tab when a button is 'waiting'.
  36. void keyPressEvent(QKeyEvent* event) override;
  37. /// Convert key ASCII value to its' letter/name
  38. QString getKeyName(int key_code) const;
  39. /// Convert letter/name of key to its ASCII value.
  40. Qt::Key getKeyValue(const QString& text) const;
  41. /// Set button text to name of key pressed.
  42. void setKey();
  43. private slots:
  44. /// Event handler for all button released() event.
  45. void handleClick();
  46. /// Restore all buttons to their default values.
  47. void restoreDefaults();
  48. };