Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/controllersettingswindow.h
4802 views
1
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: 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 "core/types.h"
11
12
#include <QtCore/QAbstractListModel>
13
#include <QtCore/QList>
14
#include <QtCore/QPair>
15
#include <QtCore/QString>
16
#include <QtCore/QStringList>
17
#include <QtWidgets/QDialog>
18
19
#include <array>
20
#include <string>
21
#include <utility>
22
#include <vector>
23
24
class Error;
25
26
class ControllerGlobalSettingsWidget;
27
class ControllerBindingWidget;
28
class HotkeySettingsWidget;
29
30
class INISettingsInterface;
31
32
class ControllerSettingsWindow final : public QWidget
33
{
34
Q_OBJECT
35
36
public:
37
enum class Category
38
{
39
GlobalSettings,
40
FirstControllerSettings,
41
HotkeySettings,
42
Count
43
};
44
45
ControllerSettingsWindow(INISettingsInterface* game_sif = nullptr, bool edit_profiles = false,
46
QWidget* parent = nullptr);
47
~ControllerSettingsWindow();
48
49
static void editControllerSettingsForGame(QWidget* parent, INISettingsInterface* sif);
50
51
ALWAYS_INLINE HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; }
52
53
ALWAYS_INLINE bool isEditingGlobalSettings() const
54
{
55
return (!m_editing_input_profiles && !m_editing_settings_interface);
56
}
57
ALWAYS_INLINE bool isEditingGameSettings() const
58
{
59
return (!m_editing_input_profiles && m_editing_settings_interface);
60
}
61
ALWAYS_INLINE bool isEditingProfile() const { return m_editing_input_profiles; }
62
ALWAYS_INLINE INISettingsInterface* getEditingSettingsInterface() { return m_editing_settings_interface; }
63
64
Category getCurrentCategory() const;
65
66
void updateListDescription(u32 global_slot, ControllerBindingWidget* widget);
67
68
void switchProfile(const std::string_view name);
69
70
void setCategory(Category category);
71
72
// Helper functions for updating setting values globally or in the profile.
73
bool getBoolValue(const char* section, const char* key, bool default_value) const;
74
s32 getIntValue(const char* section, const char* key, s32 default_value) const;
75
std::string getStringValue(const char* section, const char* key, const char* default_value) const;
76
void setBoolValue(const char* section, const char* key, bool value);
77
void setIntValue(const char* section, const char* key, s32 value);
78
void setStringValue(const char* section, const char* key, const char* value);
79
void clearSettingValue(const char* section, const char* key);
80
void saveAndReloadGameSettings();
81
82
Q_SIGNALS:
83
void windowClosed();
84
void inputProfileSwitched();
85
86
protected:
87
void closeEvent(QCloseEvent* event) override;
88
89
private:
90
int getHotkeyCategoryIndex() const;
91
void refreshProfileList();
92
93
std::array<bool, 2> getEnabledMultitaps() const;
94
95
void createWidgets();
96
97
void onCategoryCurrentRowChanged(int row);
98
void onCurrentProfileChanged(int index);
99
void onNewProfileClicked();
100
void onApplyProfileClicked();
101
void onDeleteProfileClicked();
102
void onRestoreDefaultsClicked();
103
void onCopyGlobalSettingsClicked();
104
105
Ui::ControllerSettingsWindow m_ui;
106
107
INISettingsInterface* m_editing_settings_interface = nullptr;
108
109
ControllerGlobalSettingsWidget* m_global_settings = nullptr;
110
std::array<ControllerBindingWidget*, NUM_CONTROLLER_AND_CARD_PORTS> m_port_bindings{};
111
HotkeySettingsWidget* m_hotkey_settings = nullptr;
112
113
QString m_profile_name;
114
std::unique_ptr<INISettingsInterface> m_profile_settings_interface;
115
bool m_editing_input_profiles = false;
116
};
117
118