inputbindingdialog.h (1970B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 #include "common/types.h" 6 #include "ui_inputbindingdialog.h" 7 #include "util/input_manager.h" 8 #include <QtWidgets/QDialog> 9 #include <optional> 10 #include <string> 11 #include <vector> 12 13 class SettingsInterface; 14 15 class InputBindingDialog : public QDialog 16 { 17 Q_OBJECT 18 19 public: 20 InputBindingDialog(SettingsInterface* sif, InputBindingInfo::Type bind_type, std::string section_name, 21 std::string key_name, std::vector<std::string> bindings, QWidget* parent); 22 ~InputBindingDialog(); 23 24 protected Q_SLOTS: 25 void onAddBindingButtonClicked(); 26 void onRemoveBindingButtonClicked(); 27 void onClearBindingsButtonClicked(); 28 void onInputListenTimerTimeout(); 29 void inputManagerHookCallback(InputBindingKey key, float value); 30 31 protected: 32 enum : u32 33 { 34 TIMEOUT_FOR_BINDING = 5 35 }; 36 37 virtual bool eventFilter(QObject* watched, QEvent* event) override; 38 39 virtual void startListeningForInput(u32 timeout_in_seconds); 40 virtual void stopListeningForInput(); 41 42 bool isListeningForInput() const { return m_input_listen_timer != nullptr; } 43 void addNewBinding(); 44 45 void updateList(); 46 void saveListToSettings(); 47 48 void hookInputManager(); 49 void unhookInputManager(); 50 51 void onSensitivityChanged(int value); 52 void onResetDeadzoneClicked(); 53 void onDeadzoneChanged(int value); 54 void onResetSensitivityClicked(); 55 56 Ui::InputBindingDialog m_ui; 57 58 SettingsInterface* m_sif; 59 InputBindingInfo::Type m_bind_type; 60 std::string m_section_name; 61 std::string m_key_name; 62 std::vector<std::string> m_bindings; 63 std::vector<InputBindingKey> m_new_bindings; 64 std::vector<std::pair<InputBindingKey, std::pair<float, float>>> m_value_ranges; 65 66 QTimer* m_input_listen_timer = nullptr; 67 u32 m_input_listen_remaining_seconds = 0; 68 QPoint m_input_listen_start_position{}; 69 bool m_mouse_mapping_enabled = false; 70 };