Qt: add core option sublabels as tooltips, add buttons to reset one/all core options

This commit is contained in:
Brad Parker 2019-08-02 17:48:24 -04:00
parent c82693037f
commit 1580a611d6
6 changed files with 99 additions and 2 deletions

View File

@ -9067,3 +9067,11 @@ MSG_HASH(
MSG_INCOMPATIBLE_CORE_FOR_VIDEO_DRIVER,
"このコアは設定されたビデオドライバに対応しません。"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_QT_RESET,
"リセット"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_QT_RESET_ALL,
"全てをリセット"
)

View File

@ -9043,3 +9043,11 @@ MSG_HASH(
MSG_INCOMPATIBLE_CORE_FOR_VIDEO_DRIVER,
"This core is not compatible with the current video driver."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_QT_RESET,
"Reset"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_QT_RESET_ALL,
"Reset All"
)

View File

@ -2309,6 +2309,8 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_QT_CORE_OPTIONS,
MENU_ENUM_LABEL_VALUE_QT_ITEMS_COUNT,
MENU_ENUM_LABEL_VALUE_QT_DROP_IMAGE_HERE,
MENU_ENUM_LABEL_VALUE_QT_RESET,
MENU_ENUM_LABEL_VALUE_QT_RESET_ALL,
MENU_LABEL(MIDI_INPUT),
MENU_LABEL(MIDI_OUTPUT),

View File

@ -263,11 +263,19 @@ void CoreOptionsDialog::buildLayout()
if (coreopts)
{
QToolButton *resetAllButton = new QToolButton(this);
resetAllButton->setDefaultAction(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL), this));
connect(resetAllButton, SIGNAL(clicked()), this, SLOT(onCoreOptionResetAllClicked()));
for (j = 0; j < opts; j++)
{
QString desc = core_option_manager_get_desc(coreopts, j);
QString val = core_option_manager_get_val(coreopts, j);
QComboBox *comboBox = NULL;
QLabel *descLabel = NULL;
QHBoxLayout *comboLayout = NULL;
QToolButton *resetButton = NULL;
struct core_option *option = NULL;
if (desc.isEmpty() || !coreopts->opts)
@ -278,19 +286,40 @@ void CoreOptionsDialog::buildLayout()
if (!option->vals || option->vals->size == 0)
continue;
comboLayout = new QHBoxLayout();
descLabel = new QLabel(desc, this);
comboBox = new QComboBox(this);
comboBox->setObjectName("coreOptionComboBox");
resetButton = new QToolButton(this);
resetButton->setObjectName("resetButton");
resetButton->setDefaultAction(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET), this));
resetButton->setProperty("comboBox", QVariant::fromValue(comboBox));
connect(resetButton, SIGNAL(clicked()), this, SLOT(onCoreOptionResetClicked()));
if (!string_is_empty(option->info))
{
descLabel->setToolTip(option->info);
comboBox->setToolTip(option->info);
}
for (k = 0; k < option->vals->size; k++)
comboBox->addItem(option->vals->elems[k].data, option->key);
comboBox->setCurrentText(val);
comboBox->setProperty("default_index", static_cast<unsigned>(option->default_index));
/* Only connect the signal after setting the default item */
connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCoreOptionComboBoxCurrentIndexChanged(int)));
form->addRow(desc, comboBox);
comboLayout->addWidget(comboBox);
comboLayout->addWidget(resetButton);
form->addRow(descLabel, comboLayout);
}
form->addRow(resetAllButton, new QWidget(this));
m_layout->addLayout(form);
}
}
@ -310,3 +339,51 @@ void CoreOptionsDialog::buildLayout()
show();
resize(width() - 1, height());
}
void CoreOptionsDialog::onCoreOptionResetClicked()
{
QToolButton *button = qobject_cast<QToolButton*>(sender());
QComboBox *comboBox = NULL;
int default_index = 0;
bool ok = false;
if (!button)
return;
comboBox = qobject_cast<QComboBox*>(button->property("comboBox").value<QComboBox*>());
if (!comboBox)
return;
default_index = comboBox->property("default_index").toInt(&ok);
if (!ok)
return;
if (default_index >= 0 && default_index < comboBox->count())
comboBox->setCurrentIndex(default_index);
}
void CoreOptionsDialog::onCoreOptionResetAllClicked()
{
QList<QComboBox*> comboBoxes = findChildren<QComboBox*>("coreOptionComboBox");
int i;
for (i = 0; i < comboBoxes.count(); i++)
{
QComboBox *comboBox = comboBoxes.at(i);
int default_index = 0;
bool ok = false;
if (!comboBox)
continue;
default_index = comboBox->property("default_index").toInt(&ok);
if (!ok)
continue;
if (default_index >= 0 && default_index < comboBox->count())
comboBox->setCurrentIndex(default_index);
}
}

View File

@ -27,6 +27,8 @@ private slots:
void buildLayout();
void onSaveGameSpecificOptions();
void onCoreOptionComboBoxCurrentIndexChanged(int index);
void onCoreOptionResetClicked();
void onCoreOptionResetAllClicked();
private:
QPointer<QVBoxLayout> m_layout;
QPointer<QScrollArea> m_scrollArea;

View File

@ -1,6 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2018 - Brad Parker
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-