Qt: make comboboxes in settings dialog translateable

This commit is contained in:
Megamouse 2020-04-06 09:37:36 +02:00
parent b1fdbc7fcc
commit 133e897c8b
3 changed files with 184 additions and 18 deletions

View File

@ -117,7 +117,10 @@ static QStringList getOptions(cfg_location location)
return values; return values;
} }
emu_settings::Render_Creator::Render_Creator() emu_settings::Render_Creator::Render_Creator(const QString& name_null, const QString& name_vulkan, const QString& name_openGL)
: name_Null(name_null)
, name_Vulkan(name_vulkan)
, name_OpenGL(name_openGL)
{ {
#if defined(WIN32) || defined(HAVE_VULKAN) #if defined(WIN32) || defined(HAVE_VULKAN)
// Some drivers can get stuck when checking for vulkan-compatible gpus, f.ex. if they're waiting for one to get // Some drivers can get stuck when checking for vulkan-compatible gpus, f.ex. if they're waiting for one to get
@ -248,7 +251,12 @@ void emu_settings::Microphone_Creator::ParseDevices(std::string list)
} }
} }
emu_settings::emu_settings() : QObject() emu_settings::emu_settings()
: QObject()
, m_render_creator(
GetLocalizedSetting("Null", emu_settings::Renderer, static_cast<int>(video_renderer::null)),
GetLocalizedSetting("Vulkan", emu_settings::Renderer, static_cast<int>(video_renderer::vulkan)),
GetLocalizedSetting("OpenGl", emu_settings::Renderer, static_cast<int>(video_renderer::opengl)))
{ {
} }
@ -360,14 +368,15 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, SettingsType type, bool
{ {
QStringList settings = GetSettingOptions(type); QStringList settings = GetSettingOptions(type);
if (sorted)
{
settings.sort();
}
for (const QString& setting : settings) for (const QString& setting : settings)
{ {
combobox->addItem(tr(setting.toStdString().c_str()), QVariant(setting)); const QString localized_setting = GetLocalizedSetting(setting, type, combobox->count());
combobox->addItem(localized_setting, QVariant(setting));
}
if (sorted)
{
combobox->model()->sort(0, Qt::AscendingOrder);
} }
} }
@ -632,3 +641,163 @@ void emu_settings::OpenCorrectionDialog(QWidget* parent)
cfg_log.success("You need to save the settings in order to make these changes permanent!"); cfg_log.success("You need to save the settings in order to make these changes permanent!");
} }
} }
QString emu_settings::GetLocalizedSetting(const QString& original, SettingsType type, int index) const
{
switch (type)
{
case emu_settings::SPUBlockSize:
switch (static_cast<spu_block_size_type>(index))
{
case spu_block_size_type::safe: return tr("Safe");
case spu_block_size_type::mega: return tr("Mega");
case spu_block_size_type::giga: return tr("Giga");
}
break;
case emu_settings::EnableTSX:
switch (static_cast<tsx_usage>(index))
{
case tsx_usage::disabled: return tr("Disabled");
case tsx_usage::enabled: return tr("Enabled");
case tsx_usage::forced: return tr("Forced");
}
break;
case emu_settings::Renderer:
switch (static_cast<video_renderer>(index))
{
case video_renderer::null: return tr("Disable Video Output");
case video_renderer::opengl: return tr("OpenGL");
case video_renderer::vulkan: return tr("Vulkan");
}
break;
case emu_settings::FrameLimit:
switch (static_cast<frame_limit_type>(index))
{
case frame_limit_type::none: return tr("Off");
case frame_limit_type::_59_94: return tr("59.94");
case frame_limit_type::_50: return tr("50");
case frame_limit_type::_60: return tr("60");
case frame_limit_type::_30: return tr("30");
case frame_limit_type::_auto: return tr("Auto");
}
break;
case emu_settings::MSAA:
switch (static_cast<msaa_level>(index))
{
case msaa_level::none: return tr("Disabled");
case msaa_level::_auto: return tr("Auto");
}
break;
case emu_settings::AudioRenderer:
switch (static_cast<audio_renderer>(index))
{
case audio_renderer::null: return tr("Disable Audio Output");
#ifdef _WIN32
case audio_renderer::xaudio: return tr("XAudio2");
#endif
#ifdef HAVE_ALSA
case audio_renderer::alsa: return tr("ALSA");
#endif
#ifdef HAVE_PULSE
case audio_renderer::pulse: return tr("PulseAudio");
#endif
case audio_renderer::openal: return tr("OpenAL");
#ifdef HAVE_FAUDIO
case audio_renderer::faudio: return tr("FAudio");
#endif
}
break;
case emu_settings::MicrophoneType:
switch (static_cast<microphone_handler>(index))
{
case microphone_handler::null: return tr("Disabled");
case microphone_handler::standard: return tr("Standard");
case microphone_handler::singstar: return tr("SingStar");
case microphone_handler::real_singstar: return tr("Real SingStar");
case microphone_handler::rocksmith: return tr("Rocksmith");
}
break;
case emu_settings::KeyboardHandler:
switch (static_cast<keyboard_handler>(index))
{
case keyboard_handler::null: return tr("Null");
case keyboard_handler::basic: return tr("Basic");
}
break;
case emu_settings::MouseHandler:
switch (static_cast<mouse_handler>(index))
{
case mouse_handler::null: return tr("Null");
case mouse_handler::basic: return tr("Basic");
}
break;
case emu_settings::CameraType:
switch (static_cast<fake_camera_type>(index))
{
case fake_camera_type::unknown: return tr("Unknown");
case fake_camera_type::eyetoy: return tr("EyeToy");
case fake_camera_type::eyetoy2: return tr("PS Eye");
case fake_camera_type::uvc1_1: return tr("UVC 1.1");
}
break;
case emu_settings::Camera:
switch (static_cast<camera_handler>(index))
{
case camera_handler::null: return tr("Null");
case camera_handler::fake: return tr("Fake");
}
break;
case emu_settings::Move:
switch (static_cast<move_handler>(index))
{
case move_handler::null: return tr("Null");
case move_handler::fake: return tr("Fake");
case move_handler::mouse: return tr("Mouse");
}
break;
case emu_settings::InternetStatus:
switch (static_cast<np_internet_status>(index))
{
case np_internet_status::disabled: return tr("Disconnected");
case np_internet_status::enabled: return tr("Connected");
}
break;
case emu_settings::PSNStatus:
switch (static_cast<np_psn_status>(index))
{
case np_psn_status::disabled: return tr("Disconnected");
case np_psn_status::fake: return tr("Simulated");
}
break;
case emu_settings::SleepTimersAccuracy:
switch (static_cast<sleep_timers_accuracy_level>(index))
{
case sleep_timers_accuracy_level::_as_host: return tr("As Host");
case sleep_timers_accuracy_level::_usleep: return tr("Usleep Only");
case sleep_timers_accuracy_level::_all_timers: return tr("All Timers");
}
break;
case emu_settings::PerfOverlayDetailLevel:
switch (static_cast<detail_level>(index))
{
case detail_level::minimal: return tr("Minimal");
case detail_level::low: return tr("Low");
case detail_level::medium: return tr("Medium");
case detail_level::high: return tr("High");
}
break;
case emu_settings::PerfOverlayPosition:
switch (static_cast<screen_quadrant>(index))
{
case screen_quadrant::top_left: return tr("Top Left");
case screen_quadrant::top_right: return tr("Top Right");
case screen_quadrant::bottom_left: return tr("Bottom Left");
case screen_quadrant::bottom_right: return tr("Bottom Right");
}
break;
default:
break;
}
return original;
}

View File

@ -188,15 +188,15 @@ public:
{ {
bool supportsVulkan = false; bool supportsVulkan = false;
QStringList vulkanAdapters; QStringList vulkanAdapters;
QString name_Null = tr("Disable Video Output"); QString name_Null;
QString name_Vulkan = tr("Vulkan"); QString name_Vulkan;
QString name_OpenGL = tr("OpenGL"); QString name_OpenGL;
Render_Info Vulkan; Render_Info Vulkan;
Render_Info OpenGL; Render_Info OpenGL;
Render_Info NullRender; Render_Info NullRender;
std::vector<Render_Info*> renderers; std::vector<Render_Info*> renderers;
Render_Creator(); Render_Creator(const QString& name_null, const QString& name_vulkan, const QString& name_openGL);
}; };
struct Microphone_Creator struct Microphone_Creator
@ -270,6 +270,9 @@ public Q_SLOTS:
/** Writes the unsaved settings to file. Used in settings dialog on accept.*/ /** Writes the unsaved settings to file. Used in settings dialog on accept.*/
void SaveSettings(); void SaveSettings();
private: private:
/** Get a localized and therefore freely adjustable version of the string used in config.yml.*/
QString GetLocalizedSetting(const QString& original, SettingsType type, int index) const;
/** A helper map that keeps track of where a given setting type is located*/ /** A helper map that keeps track of where a given setting type is located*/
const QMap<SettingsType, cfg_location> m_settings_location = const QMap<SettingsType, cfg_location> m_settings_location =
{ {

View File

@ -320,9 +320,6 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
SubscribeTooltip(ui->gb_renderer, tooltips.settings.renderer); SubscribeTooltip(ui->gb_renderer, tooltips.settings.renderer);
SubscribeTooltip(ui->gb_graphicsAdapter, tooltips.settings.graphics_adapter); SubscribeTooltip(ui->gb_graphicsAdapter, tooltips.settings.graphics_adapter);
// Change displayed renderer names
ui->renderBox->setItemText(ui->renderBox->findData("Null"), render_creator.name_Null);
m_emu_settings->EnhanceComboBox(ui->resBox, emu_settings::Resolution); m_emu_settings->EnhanceComboBox(ui->resBox, emu_settings::Resolution);
SubscribeTooltip(ui->gb_default_resolution, tooltips.settings.resolution); SubscribeTooltip(ui->gb_default_resolution, tooltips.settings.resolution);
// remove unsupported resolutions from the dropdown // remove unsupported resolutions from the dropdown
@ -745,8 +742,6 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
#else #else
SubscribeTooltip(ui->gb_audio_out, tooltips.settings.audio_out_linux); SubscribeTooltip(ui->gb_audio_out, tooltips.settings.audio_out_linux);
#endif #endif
// Change displayed backend names
ui->audioOutBox->setItemText(ui->renderBox->findData("Null"), tr("Disable Audio Output"));
connect(ui->audioOutBox, &QComboBox::currentTextChanged, enable_buffering); connect(ui->audioOutBox, &QComboBox::currentTextChanged, enable_buffering);
// Microphone Comboboxes // Microphone Comboboxes
@ -775,7 +770,6 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
} }
m_emu_settings->EnhanceComboBox(ui->microphoneBox, emu_settings::MicrophoneType); m_emu_settings->EnhanceComboBox(ui->microphoneBox, emu_settings::MicrophoneType);
ui->microphoneBox->setItemText(ui->microphoneBox->findData("Null"), tr("Disabled"));
SubscribeTooltip(ui->microphoneBox, tooltips.settings.microphone); SubscribeTooltip(ui->microphoneBox, tooltips.settings.microphone);
connect(ui->microphoneBox, &QComboBox::currentTextChanged, change_microphone_type); connect(ui->microphoneBox, &QComboBox::currentTextChanged, change_microphone_type);
propagate_used_devices(); // Enables/Disables comboboxes and checks values from config for sanity propagate_used_devices(); // Enables/Disables comboboxes and checks values from config for sanity