| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <string> |
| 7 |
#include <utility> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include "DolphinQt/Config/ConfigControls/ConfigControl.h" |
| 11 |
#include "DolphinQt/Config/ToolTipControls/ToolTipComboBox.h" |
| 12 |
|
| 13 |
#include "Common/Config/ConfigInfo.h" |
| 14 |
|
| 15 |
class ConfigChoice final : public ConfigControl<ToolTipComboBox> |
| 16 |
{ |
| 17 |
Q_OBJECT |
| 18 |
public: |
| 19 |
ConfigChoice(const QStringList& options, const Config::Info<int>& setting, |
| 20 |
Config::Layer* layer = nullptr); |
| 21 |
|
| 22 |
protected: |
| 23 |
void OnConfigChanged() override; |
| 24 |
|
| 25 |
private: |
| 26 |
void Update(int choice); |
| 27 |
|
| 28 |
Config::Info<int> m_setting; |
| 29 |
}; |
| 30 |
|
| 31 |
class ConfigChoiceU32 final : public ConfigControl<ToolTipComboBox> |
| 32 |
{ |
| 33 |
Q_OBJECT |
| 34 |
public: |
| 35 |
ConfigChoiceU32(const QStringList& options, const Config::Info<u32>& setting, |
| 36 |
Config::Layer* layer = nullptr); |
| 37 |
|
| 38 |
protected: |
| 39 |
void OnConfigChanged() override; |
| 40 |
|
| 41 |
private: |
| 42 |
void Update(int choice); |
| 43 |
|
| 44 |
Config::Info<u32> m_setting; |
| 45 |
}; |
| 46 |
|
| 47 |
template <typename T> |
| 48 |
class ConfigChoiceMap final : public ConfigControl<ToolTipComboBox> |
| 49 |
{ |
| 50 |
public: |
| 51 |
ConfigChoiceMap(const std::vector<std::pair<QString, T>>& options, const Config::Info<T>& setting, |
| 52 |
Config::Layer* layer = nullptr) |
| 53 |
: ConfigControl<ToolTipComboBox>(setting.GetLocation(), layer), m_setting(setting), |
| 54 |
m_options(options) |
| 55 |
{ |
| 56 |
for (const auto& [option_text, option_data] : options) |
| 57 |
addItem(option_text); |
| 58 |
|
| 59 |
OnConfigChanged(); |
| 60 |
connect(this, &QComboBox::currentIndexChanged, this, &ConfigChoiceMap::Update); |
| 61 |
} |
| 62 |
|
| 63 |
protected: |
| 64 |
void OnConfigChanged() override |
| 65 |
{ |
| 66 |
const T value = ReadValue(m_setting); |
| 67 |
const auto it = std::find_if(m_options.begin(), m_options.end(), |
| 68 |
[&value](const auto& pair) { return pair.second == value; }); |
| 69 |
|
| 70 |
int index = |
| 71 |
(it != m_options.end()) ? static_cast<int>(std::distance(m_options.begin(), it)) : -1; |
| 72 |
|
| 73 |
const QSignalBlocker blocker(this); |
| 74 |
setCurrentIndex(index); |
| 75 |
} |
| 76 |
|
| 77 |
private: |
| 78 |
void Update(int choice) { SaveValue(m_setting, m_options[choice].second); } |
| 79 |
|
| 80 |
const Config::Info<T> m_setting; |
| 81 |
const std::vector<std::pair<QString, T>> m_options; |
| 82 |
}; |
| 83 |
|
| 84 |
class ConfigStringChoice final : public ConfigControl<ToolTipComboBox> |
| 85 |
{ |
| 86 |
Q_OBJECT |
| 87 |
public: |
| 88 |
ConfigStringChoice(std::span<const std::string> options, const Config::Info<std::string>& setting, |
| 89 |
Config::Layer* layer = nullptr); |
| 90 |
ConfigStringChoice(std::span<const std::pair<QString, QString>> options, |
| 91 |
const Config::Info<std::string>& setting, Config::Layer* layer = nullptr); |
| 92 |
void Load(); |
| 93 |
|
| 94 |
protected: |
| 95 |
void OnConfigChanged() override; |
| 96 |
|
| 97 |
private: |
| 98 |
void Update(int index); |
| 99 |
|
| 100 |
const Config::Info<std::string> m_setting; |
| 101 |
bool m_text_is_data = false; |
| 102 |
}; |
| 103 |
|
| 104 |
class ConfigComplexChoice final : public ToolTipComboBox |
| 105 |
{ |
| 106 |
Q_OBJECT |
| 107 |
|
| 108 |
using InfoVariant = std::variant<Config::Info<u32>, Config::Info<int>, Config::Info<bool>>; |
| 109 |
using OptionVariant = std::variant<Config::DefaultState, u32, int, bool>; |
| 110 |
|
| 111 |
public: |
| 112 |
ConfigComplexChoice(const InfoVariant& setting1, const InfoVariant& setting2, |
| 113 |
Config::Layer* layer = nullptr); |
| 114 |
|
| 115 |
void Add(const QString& name, const OptionVariant option1, const OptionVariant option2); |
| 116 |
void Refresh(); |
| 117 |
void Reset(); |
| 118 |
void SetDefault(int index); |
| 119 |
const std::pair<Config::Location, Config::Location> GetLocation() const; |
| 120 |
|
| 121 |
private: |
| 122 |
void SaveValue(int choice); |
| 123 |
void UpdateComboIndex(); |
| 124 |
void mousePressEvent(QMouseEvent* event) override; |
| 125 |
|
| 126 |
Config::Layer* m_layer; |
| 127 |
const InfoVariant m_setting1; |
| 128 |
const InfoVariant m_setting2; |
| 129 |
std::vector<std::pair<OptionVariant, OptionVariant>> m_options; |
| 130 |
int m_default_index = -1; |
| 131 |
}; |