Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/controllersettingswindow.h
4246 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/QList>
13
#include <QtCore/QPair>
14
#include <QtCore/QString>
15
#include <QtCore/QStringList>
16
#include <QtWidgets/QDialog>
17
#include <QtCore/QAbstractListModel>
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
// Helper functions for updating setting values globally or in the profile.
71
bool getBoolValue(const char* section, const char* key, bool default_value) const;
72
s32 getIntValue(const char* section, const char* key, s32 default_value) const;
73
std::string getStringValue(const char* section, const char* key, const char* default_value) const;
74
void setBoolValue(const char* section, const char* key, bool value);
75
void setIntValue(const char* section, const char* key, s32 value);
76
void setStringValue(const char* section, const char* key, const char* value);
77
void clearSettingValue(const char* section, const char* key);
78
void saveAndReloadGameSettings();
79
80
Q_SIGNALS:
81
void windowClosed();
82
void inputProfileSwitched();
83
84
public Q_SLOTS:
85
void setCategory(Category category);
86
87
private Q_SLOTS:
88
void onCategoryCurrentRowChanged(int row);
89
void onCurrentProfileChanged(int index);
90
void onNewProfileClicked();
91
void onApplyProfileClicked();
92
void onDeleteProfileClicked();
93
void onRestoreDefaultsClicked();
94
void onCopyGlobalSettingsClicked();
95
96
void createWidgets();
97
98
protected:
99
void closeEvent(QCloseEvent* event) override;
100
101
private:
102
int getHotkeyCategoryIndex() const;
103
void refreshProfileList();
104
105
std::array<bool, 2> getEnabledMultitaps() const;
106
107
Ui::ControllerSettingsWindow m_ui;
108
109
INISettingsInterface* m_editing_settings_interface = nullptr;
110
111
ControllerGlobalSettingsWidget* m_global_settings = nullptr;
112
std::array<ControllerBindingWidget*, NUM_CONTROLLER_AND_CARD_PORTS> m_port_bindings{};
113
HotkeySettingsWidget* m_hotkey_settings = nullptr;
114
115
QString m_profile_name;
116
std::unique_ptr<INISettingsInterface> m_profile_settings_interface;
117
bool m_editing_input_profiles = false;
118
};
119
120