citra-emu
/
citra-canary
Archived
1
0
Fork 0

citra_qt: Split options into 'Specific' and 'Generic'

For easier usage. Also made the option list sortable.
This commit is contained in:
zhupengfei 2020-02-28 18:26:20 +08:00
parent f3e9780d10
commit a50ba7192b
No known key found for this signature in database
GPG Key ID: DD129E108BD09378
7 changed files with 76 additions and 34 deletions

View File

@ -15,6 +15,9 @@ DumpingDialog::DumpingDialog(QWidget* parent)
ui->setupUi(this);
format_generic_options = VideoDumper::GetFormatGenericOptions();
encoder_generic_options = VideoDumper::GetEncoderGenericOptions();
connect(ui->pathExplore, &QToolButton::clicked, this, &DumpingDialog::OnToolButtonClicked);
connect(ui->buttonBox, &QDialogButtonBox::accepted, [this] {
if (ui->pathLineEdit->text().isEmpty()) {
@ -27,17 +30,17 @@ DumpingDialog::DumpingDialog(QWidget* parent)
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &DumpingDialog::reject);
connect(ui->formatOptionsButton, &QToolButton::clicked, [this] {
OpenOptionsDialog(formats.at(ui->formatComboBox->currentData().toUInt()).options,
ui->formatOptionsLineEdit);
format_generic_options, ui->formatOptionsLineEdit);
});
connect(ui->videoEncoderOptionsButton, &QToolButton::clicked, [this] {
OpenOptionsDialog(
video_encoders.at(ui->videoEncoderComboBox->currentData().toUInt()).options,
ui->videoEncoderOptionsLineEdit);
encoder_generic_options, ui->videoEncoderOptionsLineEdit);
});
connect(ui->audioEncoderOptionsButton, &QToolButton::clicked, [this] {
OpenOptionsDialog(
audio_encoders.at(ui->audioEncoderComboBox->currentData().toUInt()).options,
ui->audioEncoderOptionsLineEdit);
encoder_generic_options, ui->audioEncoderOptionsLineEdit);
});
SetConfiguration();
@ -177,9 +180,10 @@ void DumpingDialog::OnToolButtonClicked() {
}
}
void DumpingDialog::OpenOptionsDialog(const std::vector<VideoDumper::OptionInfo>& options,
void DumpingDialog::OpenOptionsDialog(const std::vector<VideoDumper::OptionInfo>& specific_options,
const std::vector<VideoDumper::OptionInfo>& generic_options,
QLineEdit* line_edit) {
OptionsDialog dialog(this, options, line_edit->text().toStdString());
OptionsDialog dialog(this, specific_options, generic_options, line_edit->text().toStdString());
if (dialog.exec() != QDialog::DialogCode::Accepted) {
return;
}

View File

@ -27,7 +27,8 @@ private:
void PopulateEncoders();
void SetConfiguration();
void OnToolButtonClicked();
void OpenOptionsDialog(const std::vector<VideoDumper::OptionInfo>& options,
void OpenOptionsDialog(const std::vector<VideoDumper::OptionInfo>& specific_options,
const std::vector<VideoDumper::OptionInfo>& generic_options,
QLineEdit* line_edit);
std::unique_ptr<Ui::DumpingDialog> ui;
@ -35,6 +36,8 @@ private:
QString last_path;
std::vector<VideoDumper::FormatInfo> formats;
std::vector<VideoDumper::OptionInfo> format_generic_options;
std::vector<VideoDumper::EncoderInfo> video_encoders;
std::vector<VideoDumper::EncoderInfo> audio_encoders;
std::vector<VideoDumper::OptionInfo> encoder_generic_options;
};

View File

@ -9,7 +9,10 @@
constexpr char UNSET_TEXT[] = QT_TR_NOOP("[not set]");
void OptionsDialog::PopulateOptions(const std::string& current_value) {
void OptionsDialog::PopulateOptions() {
const auto& options = ui->specificRadioButton->isChecked() ? specific_options : generic_options;
ui->main->clear();
ui->main->setSortingEnabled(false);
for (std::size_t i = 0; i < options.size(); ++i) {
const auto& option = options.at(i);
auto* item = new QTreeWidgetItem(
@ -18,9 +21,13 @@ void OptionsDialog::PopulateOptions(const std::string& current_value) {
item->setData(1, Qt::UserRole, static_cast<unsigned long long>(i)); // ID
ui->main->addTopLevelItem(item);
}
ui->main->setSortingEnabled(true);
ui->main->sortItems(0, Qt::AscendingOrder);
}
void OptionsDialog::OnSetOptionValue(int id) {
void OptionsDialog::OnSetOptionValue(QTreeWidgetItem* item) {
const auto& options = ui->specificRadioButton->isChecked() ? specific_options : generic_options;
const int id = item->data(1, Qt::UserRole).toInt();
OptionSetDialog dialog(this, options[id],
current_values.Get(options[id].name, options[id].default_value));
if (dialog.exec() != QDialog::DialogCode::Accepted) {
@ -33,27 +40,29 @@ void OptionsDialog::OnSetOptionValue(int id) {
} else {
current_values.Erase(options[id].name);
}
ui->main->invisibleRootItem()->child(id)->setText(1, is_set ? QString::fromStdString(value)
: tr(UNSET_TEXT));
item->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_,
OptionsDialog::OptionsDialog(QWidget* parent,
std::vector<VideoDumper::OptionInfo> specific_options_,
std::vector<VideoDumper::OptionInfo> generic_options_,
const std::string& current_value)
: QDialog(parent), ui(std::make_unique<Ui::OptionsDialog>()), options(std::move(options_)),
: QDialog(parent), ui(std::make_unique<Ui::OptionsDialog>()),
specific_options(std::move(specific_options_)), generic_options(std::move(generic_options_)),
current_values(current_value) {
ui->setupUi(this);
PopulateOptions(current_value);
PopulateOptions();
connect(ui->main, &QTreeWidget::itemDoubleClicked, [this](QTreeWidgetItem* item, int column) {
OnSetOptionValue(item->data(1, Qt::UserRole).toInt());
});
connect(ui->main, &QTreeWidget::itemDoubleClicked,
[this](QTreeWidgetItem* item, int column) { OnSetOptionValue(item); });
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &OptionsDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &OptionsDialog::reject);
connect(ui->specificRadioButton, &QRadioButton::toggled, this, &OptionsDialog::PopulateOptions);
}
OptionsDialog::~OptionsDialog() = default;

View File

@ -8,6 +8,8 @@
#include "common/param_package.h"
#include "core/dumping/ffmpeg_backend.h"
class QTreeWidgetItem;
namespace Ui {
class OptionsDialog;
}
@ -16,17 +18,19 @@ class OptionsDialog : public QDialog {
Q_OBJECT
public:
explicit OptionsDialog(QWidget* parent, std::vector<VideoDumper::OptionInfo> options,
explicit OptionsDialog(QWidget* parent, std::vector<VideoDumper::OptionInfo> specific_options,
std::vector<VideoDumper::OptionInfo> generic_options,
const std::string& current_value);
~OptionsDialog() override;
std::string GetCurrentValue() const;
private:
void PopulateOptions(const std::string& current_value);
void OnSetOptionValue(int id);
void PopulateOptions();
void OnSetOptionValue(QTreeWidgetItem* item);
std::unique_ptr<Ui::OptionsDialog> ui;
std::vector<VideoDumper::OptionInfo> options;
std::vector<VideoDumper::OptionInfo> specific_options;
std::vector<VideoDumper::OptionInfo> generic_options;
Common::ParamPackage current_values;
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>300</height>
<width>650</width>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
@ -24,6 +24,27 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QRadioButton" name="specificRadioButton">
<property name="text">
<string>Specific</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="genericRadioButton">
<property name="text">
<string>Generic</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="main">
<column>

View File

@ -754,8 +754,6 @@ std::vector<OptionInfo> GetOptionList(const AVClass* av_class, bool search_child
std::vector<EncoderInfo> ListEncoders(AVMediaType type) {
InitializeFFmpegLibraries();
const auto general_options = GetOptionList(avcodec_get_class(), false);
std::vector<EncoderInfo> out;
const AVCodec* current = nullptr;
@ -768,19 +766,19 @@ std::vector<EncoderInfo> ListEncoders(AVMediaType type) {
if (!av_codec_is_encoder(current) || current->type != type) {
continue;
}
auto options = GetOptionList(current->priv_class, true);
options.insert(options.end(), general_options.begin(), general_options.end());
out.push_back(
{current->name, ToStdString(current->long_name), current->id, std::move(options)});
out.push_back({current->name, ToStdString(current->long_name), current->id,
GetOptionList(current->priv_class, true)});
}
return out;
}
std::vector<OptionInfo> GetEncoderGenericOptions() {
return GetOptionList(avcodec_get_class(), false);
}
std::vector<FormatInfo> ListFormats() {
InitializeFFmpegLibraries();
const auto general_options = GetOptionList(avformat_get_class(), false);
std::vector<FormatInfo> out;
const AVOutputFormat* current = nullptr;
@ -790,9 +788,6 @@ std::vector<FormatInfo> ListFormats() {
void* data = nullptr; // For libavformat to save the iteration state
while ((current = av_muxer_iterate(&data))) {
#endif
auto options = GetOptionList(current->priv_class, true);
options.insert(options.end(), general_options.begin(), general_options.end());
std::vector<std::string> extensions;
Common::SplitString(ToStdString(current->extensions), ',', extensions);
@ -816,9 +811,13 @@ std::vector<FormatInfo> ListFormats() {
out.push_back({current->name, ToStdString(current->long_name), std::move(extensions),
std::move(supported_video_codecs), std::move(supported_audio_codecs),
std::move(options)});
GetOptionList(current->priv_class, true)});
}
return out;
}
std::vector<OptionInfo> GetFormatGenericOptions() {
return GetOptionList(avformat_get_class(), false);
}
} // namespace VideoDumper

View File

@ -227,6 +227,8 @@ struct FormatInfo {
};
std::vector<EncoderInfo> ListEncoders(AVMediaType type);
std::vector<OptionInfo> GetEncoderGenericOptions();
std::vector<FormatInfo> ListFormats();
std::vector<OptionInfo> GetFormatGenericOptions();
} // namespace VideoDumper