configure_hotkeys.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2017 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 <QWidget>
  7. namespace Common {
  8. class ParamPackage;
  9. }
  10. namespace Core::HID {
  11. class HIDCore;
  12. class EmulatedController;
  13. enum class NpadButton : u64;
  14. } // namespace Core::HID
  15. namespace Ui {
  16. class ConfigureHotkeys;
  17. }
  18. class HotkeyRegistry;
  19. class QStandardItemModel;
  20. class ConfigureHotkeys : public QWidget {
  21. Q_OBJECT
  22. public:
  23. explicit ConfigureHotkeys(Core::HID::HIDCore& hid_core_, QWidget* parent = nullptr);
  24. ~ConfigureHotkeys() override;
  25. void ApplyConfiguration(HotkeyRegistry& registry);
  26. /**
  27. * Populates the hotkey list widget using data from the provided registry.
  28. * Called everytime the Configure dialog is opened.
  29. * @param registry The HotkeyRegistry whose data is used to populate the list.
  30. */
  31. void Populate(const HotkeyRegistry& registry);
  32. private:
  33. void changeEvent(QEvent* event) override;
  34. void RetranslateUI();
  35. void Configure(QModelIndex index);
  36. void ConfigureController(QModelIndex index);
  37. std::pair<bool, QString> IsUsedKey(QKeySequence key_sequence) const;
  38. std::pair<bool, QString> IsUsedControllerKey(const QString& key_sequence) const;
  39. void RestoreDefaults();
  40. void ClearAll();
  41. void PopupContextMenu(const QPoint& menu_location);
  42. void RestoreControllerHotkey(QModelIndex index);
  43. void RestoreHotkey(QModelIndex index);
  44. std::unique_ptr<Ui::ConfigureHotkeys> ui;
  45. QStandardItemModel* model;
  46. void SetPollingResult(Core::HID::NpadButton button, bool cancel);
  47. QString GetButtonName(Core::HID::NpadButton button) const;
  48. Core::HID::EmulatedController* controller;
  49. std::unique_ptr<QTimer> timeout_timer;
  50. std::unique_ptr<QTimer> poll_timer;
  51. std::optional<std::function<void(Core::HID::NpadButton, bool)>> input_setter;
  52. };