2024-09-17 23:29:13 -07:00
|
|
|
// Copyright 2024 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QFont>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QSignalBlocker>
|
|
|
|
|
|
|
|
#include "Common/Config/Enums.h"
|
2024-09-17 23:29:13 -07:00
|
|
|
#include "Common/Config/Layer.h"
|
2024-09-17 23:29:13 -07:00
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
|
|
|
namespace Config
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
class Info;
|
|
|
|
struct Location;
|
|
|
|
} // namespace Config
|
|
|
|
|
|
|
|
template <class Derived>
|
|
|
|
class ConfigControl : public Derived
|
|
|
|
{
|
|
|
|
public:
|
2024-09-17 23:29:13 -07:00
|
|
|
ConfigControl(const Config::Location& location, Config::Layer* layer)
|
|
|
|
: m_location(location), m_layer(layer)
|
2024-09-17 23:29:13 -07:00
|
|
|
{
|
|
|
|
ConnectConfig();
|
|
|
|
}
|
2024-09-17 23:29:13 -07:00
|
|
|
ConfigControl(const QString& label, const Config::Location& location, Config::Layer* layer)
|
|
|
|
: Derived(label), m_location(location), m_layer(layer)
|
|
|
|
{
|
|
|
|
ConnectConfig();
|
|
|
|
}
|
|
|
|
ConfigControl(const Qt::Orientation& orient, const Config::Location& location,
|
|
|
|
Config::Layer* layer)
|
|
|
|
: Derived(orient), m_location(location), m_layer(layer)
|
2024-09-17 23:29:13 -07:00
|
|
|
{
|
|
|
|
ConnectConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Config::Location GetLocation() const { return m_location; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void ConnectConfig()
|
|
|
|
{
|
|
|
|
Derived::connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] {
|
|
|
|
QFont bf = Derived::font();
|
|
|
|
bf.setBold(IsConfigLocal());
|
|
|
|
Derived::setFont(bf);
|
|
|
|
|
|
|
|
const QSignalBlocker blocker(this);
|
|
|
|
OnConfigChanged();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void SaveValue(const Config::Info<T>& setting, const T& value)
|
|
|
|
{
|
2024-09-17 23:29:13 -07:00
|
|
|
if (m_layer != nullptr)
|
|
|
|
{
|
|
|
|
m_layer->Set(m_location, value);
|
|
|
|
Config::OnConfigChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-17 23:29:13 -07:00
|
|
|
Config::SetBaseOrCurrent(setting, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T ReadValue(const Config::Info<T>& setting) const
|
|
|
|
{
|
2024-09-17 23:29:13 -07:00
|
|
|
if (m_layer != nullptr)
|
|
|
|
return m_layer->Get(setting);
|
|
|
|
|
2024-09-17 23:29:13 -07:00
|
|
|
return Config::Get(setting);
|
|
|
|
}
|
|
|
|
|
2024-09-17 23:29:13 -07:00
|
|
|
virtual void OnConfigChanged(){};
|
2024-09-17 23:29:13 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsConfigLocal() const
|
|
|
|
{
|
2024-09-17 23:29:13 -07:00
|
|
|
if (m_layer != nullptr)
|
|
|
|
return m_layer->Exists(m_location);
|
|
|
|
else
|
|
|
|
return Config::GetActiveLayerForConfig(m_location) != Config::LayerType::Base;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent* event) override
|
|
|
|
{
|
|
|
|
if (m_layer != nullptr && event->button() == Qt::RightButton)
|
|
|
|
{
|
|
|
|
m_layer->DeleteKey(m_location);
|
|
|
|
Config::OnConfigChanged();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Derived::mousePressEvent(event);
|
|
|
|
}
|
2024-09-17 23:29:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const Config::Location m_location;
|
2024-09-17 23:29:13 -07:00
|
|
|
Config::Layer* m_layer;
|
2024-09-17 23:29:13 -07:00
|
|
|
};
|