controllersettingswindow.h (4111B)
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 6 #include "ui_controllersettingswindow.h" 7 8 #include "util/input_manager.h" 9 10 #include "common/types.h" 11 12 #include <QtCore/QList> 13 #include <QtCore/QPair> 14 #include <QtCore/QString> 15 #include <QtCore/QStringList> 16 #include <QtWidgets/QDialog> 17 18 #include <array> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 class Error; 24 25 class ControllerGlobalSettingsWidget; 26 class ControllerBindingWidget; 27 class HotkeySettingsWidget; 28 29 class SettingsInterface; 30 31 class ControllerSettingsWindow final : public QWidget 32 { 33 Q_OBJECT 34 35 public: 36 enum class Category 37 { 38 GlobalSettings, 39 FirstControllerSettings, 40 HotkeySettings, 41 Count 42 }; 43 44 enum : u32 45 { 46 MAX_PORTS = 8 47 }; 48 49 ControllerSettingsWindow(SettingsInterface* game_sif = nullptr, QWidget* parent = nullptr); 50 ~ControllerSettingsWindow(); 51 52 static void editControllerSettingsForGame(QWidget* parent, SettingsInterface* sif); 53 54 ALWAYS_INLINE HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; } 55 56 ALWAYS_INLINE const std::vector<std::pair<std::string, std::string>>& getDeviceList() const { return m_device_list; } 57 ALWAYS_INLINE const QStringList& getVibrationMotors() const { return m_vibration_motors; } 58 59 ALWAYS_INLINE bool isEditingGlobalSettings() const 60 { 61 return (m_profile_name.isEmpty() && !m_editing_settings_interface); 62 } 63 ALWAYS_INLINE bool isEditingGameSettings() const 64 { 65 return (m_profile_name.isEmpty() && m_editing_settings_interface); 66 } 67 ALWAYS_INLINE bool isEditingProfile() const { return !m_profile_name.isEmpty(); } 68 ALWAYS_INLINE SettingsInterface* getEditingSettingsInterface() { return m_editing_settings_interface; } 69 70 Category getCurrentCategory() const; 71 72 void updateListDescription(u32 global_slot, ControllerBindingWidget* widget); 73 74 void switchProfile(const std::string_view name); 75 76 // Helper functions for updating setting values globally or in the profile. 77 bool getBoolValue(const char* section, const char* key, bool default_value) const; 78 s32 getIntValue(const char* section, const char* key, s32 default_value) const; 79 std::string getStringValue(const char* section, const char* key, const char* default_value) const; 80 void setBoolValue(const char* section, const char* key, bool value); 81 void setIntValue(const char* section, const char* key, s32 value); 82 void setStringValue(const char* section, const char* key, const char* value); 83 void clearSettingValue(const char* section, const char* key); 84 void saveAndReloadGameSettings(); 85 86 Q_SIGNALS: 87 void windowClosed(); 88 void inputProfileSwitched(); 89 90 public Q_SLOTS: 91 void setCategory(Category category); 92 93 private Q_SLOTS: 94 void onCategoryCurrentRowChanged(int row); 95 void onCurrentProfileChanged(int index); 96 void onNewProfileClicked(); 97 void onApplyProfileClicked(); 98 void onDeleteProfileClicked(); 99 void onRestoreDefaultsClicked(); 100 void onCopyGlobalSettingsClicked(); 101 void onRestoreDefaultsForGameClicked(); 102 103 void onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& devices); 104 void onInputDeviceConnected(const std::string& identifier, const std::string& device_name); 105 void onInputDeviceDisconnected(const std::string& identifier); 106 void onVibrationMotorsEnumerated(const QList<InputBindingKey>& motors); 107 108 void createWidgets(); 109 110 protected: 111 void closeEvent(QCloseEvent* event) override; 112 113 private: 114 int getHotkeyCategoryIndex() const; 115 void refreshProfileList(); 116 117 std::array<bool, 2> getEnabledMultitaps() const; 118 119 Ui::ControllerSettingsWindow m_ui; 120 121 SettingsInterface* m_editing_settings_interface = nullptr; 122 123 ControllerGlobalSettingsWidget* m_global_settings = nullptr; 124 std::array<ControllerBindingWidget*, MAX_PORTS> m_port_bindings{}; 125 HotkeySettingsWidget* m_hotkey_settings = nullptr; 126 127 std::vector<std::pair<std::string, std::string>> m_device_list; 128 QStringList m_vibration_motors; 129 130 QString m_profile_name; 131 std::unique_ptr<SettingsInterface> m_profile_settings_interface; 132 };