Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/controllersettingswindow.h
7540 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
ControllerSettingsWindow(INISettingsInterface* game_sif = nullptr, bool edit_profiles = false,
38
QWidget* parent = nullptr);
39
~ControllerSettingsWindow();
40
41
static void editControllerSettingsForGame(QWidget* parent, INISettingsInterface* sif);
42
43
ALWAYS_INLINE HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; }
44
45
ALWAYS_INLINE bool isEditingGlobalSettings() const
46
{
47
return (!m_editing_input_profiles && !m_editing_settings_interface);
48
}
49
ALWAYS_INLINE bool isEditingGameSettings() const
50
{
51
return (!m_editing_input_profiles && m_editing_settings_interface);
52
}
53
ALWAYS_INLINE bool isEditingProfile() const { return m_editing_input_profiles; }
54
ALWAYS_INLINE INISettingsInterface* getEditingSettingsInterface() { return m_editing_settings_interface; }
55
56
int getCategoryRow() const;
57
void setCategoryRow(int row);
58
void setCategory(u32 category);
59
60
void updateListDescription(u32 global_slot, ControllerBindingWidget* widget);
61
62
void switchProfile(const std::string_view name);
63
64
// Helper functions for updating setting values globally or in the profile.
65
bool getBoolValue(const char* section, const char* key, bool default_value) const;
66
s32 getIntValue(const char* section, const char* key, s32 default_value) const;
67
std::string getStringValue(const char* section, const char* key, const char* default_value) const;
68
void setBoolValue(const char* section, const char* key, bool value);
69
void setIntValue(const char* section, const char* key, s32 value);
70
void setStringValue(const char* section, const char* key, const char* value);
71
void clearSettingValue(const char* section, const char* key);
72
void saveAndReloadGameSettings();
73
74
static constexpr u32 CATEGORY_GLOBAL_SETTINGS = 0;
75
static constexpr u32 CATEGORY_FIRST_CONTROLLER_SETTINGS = 1;
76
static constexpr u32 CATEGORY_HOTKEY_SETTINGS = 2;
77
78
protected:
79
void closeEvent(QCloseEvent* event) override;
80
81
private:
82
int getHotkeyCategoryIndex() const;
83
void refreshProfileList();
84
85
std::array<bool, 2> getEnabledMultitaps() const;
86
87
void createWidgets();
88
89
void onCategoryCurrentRowChanged(int row);
90
void onCurrentProfileChanged(int index);
91
void onNewProfileClicked();
92
void onApplyProfileClicked();
93
void onDeleteProfileClicked();
94
void onRestoreDefaultsClicked();
95
void onCopyGlobalSettingsClicked();
96
97
Ui::ControllerSettingsWindow m_ui;
98
99
INISettingsInterface* m_editing_settings_interface = nullptr;
100
101
ControllerGlobalSettingsWidget* m_global_settings = nullptr;
102
std::array<ControllerBindingWidget*, NUM_CONTROLLER_AND_CARD_PORTS> m_port_bindings{};
103
HotkeySettingsWidget* m_hotkey_settings = nullptr;
104
105
QString m_profile_name;
106
std::unique_ptr<INISettingsInterface> m_profile_settings_interface;
107
bool m_editing_input_profiles = false;
108
};
109
110