mirror of
https://github.com/citra-mirror/citra.git
synced 2024-08-20 18:33:24 +02:00
citra_qt/dumping: Add options dialog
This is a simple list of name-value pairs of options. Users can double-click on an option to set or modify its value.
This commit is contained in:
parent
94bc09d3ae
commit
e769d90aa8
59
src/citra_qt/dumping/options_dialog.cpp
Normal file
59
src/citra_qt/dumping/options_dialog.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include "citra_qt/dumping/option_set_dialog.h"
|
||||||
|
#include "citra_qt/dumping/options_dialog.h"
|
||||||
|
#include "ui_options_dialog.h"
|
||||||
|
|
||||||
|
constexpr char UNSET_TEXT[] = QT_TR_NOOP("[not set]");
|
||||||
|
|
||||||
|
void OptionsDialog::PopulateOptions(const std::string& current_value) {
|
||||||
|
for (std::size_t i = 0; i < options.size(); ++i) {
|
||||||
|
const auto& option = options.at(i);
|
||||||
|
auto* item = new QTreeWidgetItem(
|
||||||
|
{QString::fromStdString(option.name), QString::fromStdString(current_values.Get(
|
||||||
|
option.name, tr(UNSET_TEXT).toStdString()))});
|
||||||
|
item->setData(1, Qt::UserRole, static_cast<unsigned long long>(i)); // ID
|
||||||
|
ui->main->addTopLevelItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::OnSetOptionValue(int id) {
|
||||||
|
OptionSetDialog dialog(this, options[id],
|
||||||
|
current_values.Get(options[id].name, options[id].default_value));
|
||||||
|
if (dialog.exec() != QDialog::DialogCode::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& [is_set, value] = dialog.GetCurrentValue();
|
||||||
|
if (is_set) {
|
||||||
|
current_values.Set(options[id].name, value);
|
||||||
|
} else {
|
||||||
|
current_values.Erase(options[id].name);
|
||||||
|
}
|
||||||
|
ui->main->invisibleRootItem()->child(id)->setText(1, is_set ? QString::fromStdString(value)
|
||||||
|
: tr(UNSET_TEXT));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OptionsDialog::GetCurrentValue() const {
|
||||||
|
return current_values.Serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsDialog::OptionsDialog(QWidget* parent, std::vector<VideoDumper::OptionInfo> options_,
|
||||||
|
const std::string& current_value)
|
||||||
|
: QDialog(parent), ui(std::make_unique<Ui::OptionsDialog>()), options(std::move(options_)),
|
||||||
|
current_values(current_value) {
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
PopulateOptions(current_value);
|
||||||
|
|
||||||
|
connect(ui->main, &QTreeWidget::itemDoubleClicked, [this](QTreeWidgetItem* item, int column) {
|
||||||
|
OnSetOptionValue(item->data(1, Qt::UserRole).toInt());
|
||||||
|
});
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &OptionsDialog::accept);
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &OptionsDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsDialog::~OptionsDialog() = default;
|
32
src/citra_qt/dumping/options_dialog.h
Normal file
32
src/citra_qt/dumping/options_dialog.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <QDialog>
|
||||||
|
#include "common/param_package.h"
|
||||||
|
#include "core/dumping/ffmpeg_backend.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class OptionsDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class OptionsDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit OptionsDialog(QWidget* parent, std::vector<VideoDumper::OptionInfo> options,
|
||||||
|
const std::string& current_value);
|
||||||
|
~OptionsDialog() override;
|
||||||
|
|
||||||
|
std::string GetCurrentValue() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void PopulateOptions(const std::string& current_value);
|
||||||
|
void OnSetOptionValue(int id);
|
||||||
|
|
||||||
|
std::unique_ptr<Ui::OptionsDialog> ui;
|
||||||
|
std::vector<VideoDumper::OptionInfo> options;
|
||||||
|
Common::ParamPackage current_values;
|
||||||
|
};
|
50
src/citra_qt/dumping/options_dialog.ui
Normal file
50
src/citra_qt/dumping/options_dialog.ui
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>OptionsDialog</class>
|
||||||
|
<widget class="QDialog" name="OptionsDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Options</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel">
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Double click to see the description and change the values of the options.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="main">
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Value</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user