GameCubePane: Use ConfigControls where applicable

This commit is contained in:
Joshua Vandaële committed 2025-10-27 16:21:59 +01:00
1 parent 1e227bd736
commit b6766e1ca0
9 files changed
+194 -91

No files matched your search

@@ -0,0 +1,39 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/ConfigControls/ConfigText.h"
#include <QLineEdit>
ConfigText::ConfigText(const Config::Info<std::string>& setting) : ConfigText(setting, nullptr)
{
}
ConfigText::ConfigText(const Config::Info<std::string>& setting, Config::Layer* layer)
: ConfigControl(setting.GetLocation(), layer), m_setting(setting)
{
setText(QString::fromStdString(ReadValue(setting)));
connect(this, &QLineEdit::editingFinished, this, &ConfigText::Update);
}
void ConfigText::SetTextAndUpdate(const QString& text)
{
if (text == this->text())
return;
setText(text);
Update();
}
void ConfigText::Update()
{
const std::string value = text().toStdString();
SaveValue(m_setting, value);
}
void ConfigText::OnConfigChanged()
{
setText(QString::fromStdString(ReadValue(m_setting)));
}
@@ -0,0 +1,28 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QLineEdit>
#include "DolphinQt/Config/ConfigControls/ConfigControl.h"
#include "Common/Config/ConfigInfo.h"
class ConfigText : public ConfigControl<QLineEdit>
{
Q_OBJECT
public:
ConfigText(const Config::Info<std::string>& setting);
ConfigText(const Config::Info<std::string>& setting, Config::Layer* layer);
void SetTextAndUpdate(const QString& text);
protected:
void OnConfigChanged() override;
const Config::Info<std::string> m_setting;
private:
void Update();
};
@@ -0,0 +1,59 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/ConfigControls/ConfigUserPath.h"
#include <QLineEdit>
#include <QString>
#include "Common/FileUtil.h"
#include "DolphinQt/Config/ConfigControls/ConfigText.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
const Config::Info<std::string>& setting)
: ConfigUserPath(dir_index, setting, nullptr)
{
}
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
const Config::Info<std::string>& setting, Config::Layer* layer)
: ConfigText(setting, layer), m_dir_index(dir_index)
{
OnConfigChanged();
connect(this, &QLineEdit::editingFinished, this, &ConfigUserPath::Update);
}
// Display the effective path: if Config has a value, use it; otherwise fall back to UserPath.
// Config values only serve to initialize UserPath at startup, an empty config meaning "use the
// current UserPath".
void ConfigUserPath::RefreshText()
{
const std::string config_value = ReadValue(m_setting);
const std::string userpath_value = File::GetUserPath(m_dir_index);
const QString text = QString::fromStdString(config_value.empty() ? userpath_value : config_value);
setText(text);
}
void ConfigUserPath::Update()
{
const QString new_text = text().trimmed();
if (new_text.isEmpty())
{
ModalMessageBox::warning(this, tr("Empty Value"),
tr("This field cannot be left empty. Please enter a value."));
RefreshText();
return;
}
const std::string value = new_text.toStdString();
File::SetUserPath(m_dir_index, value);
SaveValue(m_setting, value);
}
void ConfigUserPath::OnConfigChanged()
{
RefreshText();
}
@@ -0,0 +1,28 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QLineEdit>
#include "Common/Config/ConfigInfo.h"
#include "DolphinQt/Config/ConfigControls/ConfigText.h"
class ConfigUserPath final : public ConfigText
{
Q_OBJECT
public:
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting);
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting,
Config::Layer* layer);
protected:
void OnConfigChanged() override;
private:
void RefreshText();
void Update();
const unsigned int m_dir_index;
};