From e769d90aa8fbf73fff7a710f0e2cf8c494115d24 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 1 Feb 2020 12:35:00 +0800 Subject: [PATCH] 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. --- src/citra_qt/dumping/options_dialog.cpp | 59 +++++++++++++++++++++++++ src/citra_qt/dumping/options_dialog.h | 32 ++++++++++++++ src/citra_qt/dumping/options_dialog.ui | 50 +++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/citra_qt/dumping/options_dialog.cpp create mode 100644 src/citra_qt/dumping/options_dialog.h create mode 100644 src/citra_qt/dumping/options_dialog.ui diff --git a/src/citra_qt/dumping/options_dialog.cpp b/src/citra_qt/dumping/options_dialog.cpp new file mode 100644 index 000000000..419272dd1 --- /dev/null +++ b/src/citra_qt/dumping/options_dialog.cpp @@ -0,0 +1,59 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#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(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 options_, + const std::string& current_value) + : QDialog(parent), ui(std::make_unique()), 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; diff --git a/src/citra_qt/dumping/options_dialog.h b/src/citra_qt/dumping/options_dialog.h new file mode 100644 index 000000000..9c6f92112 --- /dev/null +++ b/src/citra_qt/dumping/options_dialog.h @@ -0,0 +1,32 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#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 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; + std::vector options; + Common::ParamPackage current_values; +}; diff --git a/src/citra_qt/dumping/options_dialog.ui b/src/citra_qt/dumping/options_dialog.ui new file mode 100644 index 000000000..21c7c6676 --- /dev/null +++ b/src/citra_qt/dumping/options_dialog.ui @@ -0,0 +1,50 @@ + + + OptionsDialog + + + + 0 + 0 + 600 + 300 + + + + Options + + + + + + true + + + Double click to see the description and change the values of the options. + + + + + + + + Name + + + + + Value + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + +