yuzu-fork/src/yuzu/configuration/shared_widget.h

107 lines
3.7 KiB
C++
Raw Normal View History

2023-06-10 05:45:04 +01:00
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2023-05-09 06:36:05 +01:00
#pragma once
#include <forward_list>
#include <functional>
#include <string>
#include <QString>
#include <QStringLiteral>
#include <QWidget>
#include <qobjectdefs.h>
#include "yuzu/configuration/shared_translation.h"
class QCheckBox;
class QComboBox;
class QDateTimeEdit;
class QLabel;
class QLineEdit;
class QObject;
class QPushButton;
class QSlider;
class QSpinBox;
namespace Settings {
class BasicSetting;
} // namespace Settings
namespace ConfigurationShared {
enum class RequestType {
Default,
ComboBox,
SpinBox,
Slider,
ReverseSlider,
LineEdit,
HexEdit,
DateTimeEdit,
MaxEnum,
};
class Widget : public QWidget {
Q_OBJECT
public:
Widget(Settings::BasicSetting* setting, const TranslationMap& translations,
const ComboboxTranslationMap& combobox_translations, QWidget* parent, bool runtime_lock,
std::forward_list<std::function<void(bool)>>& apply_funcs_,
RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f,
Settings::BasicSetting* other_setting = nullptr,
const QString& string = QStringLiteral(""));
virtual ~Widget();
bool Valid() const;
[[nodiscard]] static QPushButton* CreateRestoreGlobalButton(bool using_global, QWidget* parent);
QPushButton* restore_button{};
QLineEdit* line_edit{};
QSpinBox* spinbox{};
QCheckBox* checkbox{};
QSlider* slider{};
QComboBox* combobox{};
QDateTimeEdit* date_time_edit{};
private:
void SetupComponent(const QString& label, std::function<void()>& load_func, bool managed,
RequestType request, float multiplier,
Settings::BasicSetting* other_setting, const QString& string);
QLabel* CreateLabel(const QString& text);
QWidget* CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label,
std::function<std::string()>& serializer,
std::function<void()>& restore_func,
const std::function<void()>& touch);
QWidget* CreateCombobox(std::function<std::string()>& serializer,
std::function<void()>& restore_func,
const std::function<void()>& touch);
QWidget* CreateLineEdit(std::function<std::string()>& serializer,
std::function<void()>& restore_func, const std::function<void()>& touch,
bool managed = true);
QWidget* CreateHexEdit(std::function<std::string()>& serializer,
std::function<void()>& restore_func, const std::function<void()>& touch);
QWidget* CreateSlider(bool reversed, float multiplier, const QString& format,
std::function<std::string()>& serializer,
std::function<void()>& restore_func, const std::function<void()>& touch);
QWidget* CreateDateTimeEdit(bool disabled, bool restrict,
std::function<std::string()>& serializer,
std::function<void()>& restore_func,
const std::function<void()>& touch);
QWidget* CreateSpinBox(const QString& suffix, std::function<std::string()>& serializer,
std::function<void()>& restore_func, const std::function<void()>& touch);
QWidget* parent;
const TranslationMap& translations;
const ComboboxTranslationMap& combobox_enumerations;
Settings::BasicSetting& setting;
std::forward_list<std::function<void(bool)>>& apply_funcs;
bool created{false};
bool runtime_lock{false};
};
} // namespace ConfigurationShared