2022-02-07 15:00:02 +06:00
|
|
|
/*
|
2023-01-06 15:36:05 -05:00
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Program settings UI module.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Authors: Cacodemon345
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Copyright 2021-2022 Cacodemon345
|
2022-02-07 15:00:02 +06:00
|
|
|
*/
|
2022-01-08 16:39:51 +06:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2021-12-28 16:47:10 +06:00
|
|
|
#include "qt_progsettings.hpp"
|
|
|
|
|
#include "ui_qt_progsettings.h"
|
|
|
|
|
#include "qt_mainwindow.hpp"
|
|
|
|
|
#include "ui_qt_mainwindow.h"
|
|
|
|
|
#include "qt_machinestatus.hpp"
|
|
|
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
2022-01-08 16:39:51 +06:00
|
|
|
#include <QLibraryInfo>
|
2025-04-17 17:20:08 +05:00
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
|
# include <QSysInfo>
|
|
|
|
|
# include <QVersionNumber>
|
|
|
|
|
#endif
|
2021-12-28 16:47:10 +06:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
extern "C" {
|
2021-12-28 16:47:10 +06:00
|
|
|
#include <86box/86box.h>
|
2022-02-08 16:40:46 +06:00
|
|
|
#include <86box/version.h>
|
2021-12-28 16:47:10 +06:00
|
|
|
#include <86box/config.h>
|
|
|
|
|
#include <86box/plat.h>
|
2022-09-08 11:19:37 -04:00
|
|
|
#include <86box/mem.h>
|
|
|
|
|
#include <86box/rom.h>
|
2021-12-28 16:47:10 +06:00
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
extern MainWindow *main_window;
|
2021-12-28 16:47:10 +06:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
ProgSettings::CustomTranslator *ProgSettings::translator = nullptr;
|
|
|
|
|
QTranslator *ProgSettings::qtTranslator = nullptr;
|
2022-01-08 23:17:20 +06:00
|
|
|
|
2025-04-17 21:52:32 +05:00
|
|
|
QVector<QPair<QString, QString>> ProgSettings::languages = {
|
|
|
|
|
{ "system", "(System Default)" },
|
|
|
|
|
{ "ca-ES", "Catalan (Spain)" },
|
|
|
|
|
{ "zh-CN", "Chinese (Simplified)" },
|
|
|
|
|
{ "zh-TW", "Chinese (Traditional)" },
|
|
|
|
|
{ "hr-HR", "Croatian (Croatia)" },
|
|
|
|
|
{ "cs-CZ", "Czech (Czech Republic)" },
|
|
|
|
|
{ "de-DE", "German (Germany)" },
|
|
|
|
|
{ "en-GB", "English (United Kingdom)" },
|
|
|
|
|
{ "en-US", "English (United States)" },
|
|
|
|
|
{ "fi-FI", "Finnish (Finland)" },
|
|
|
|
|
{ "fr-FR", "French (France)" },
|
|
|
|
|
{ "hu-HU", "Hungarian (Hungary)" },
|
|
|
|
|
{ "it-IT", "Italian (Italy)" },
|
|
|
|
|
{ "ja-JP", "Japanese (Japan)" },
|
|
|
|
|
{ "ko-KR", "Korean (Korea)" },
|
|
|
|
|
{ "nl-NL", "Dutch (Netherlands)" },
|
|
|
|
|
{ "pl-PL", "Polish (Poland)" },
|
|
|
|
|
{ "pt-BR", "Portuguese (Brazil)" },
|
|
|
|
|
{ "pt-PT", "Portuguese (Portugal)" },
|
|
|
|
|
{ "ru-RU", "Russian (Russia)" },
|
|
|
|
|
{ "sk-SK", "Slovak (Slovakia)" },
|
|
|
|
|
{ "sl-SI", "Slovenian (Slovenia)" },
|
|
|
|
|
{ "es-ES", "Spanish (Spain)" },
|
|
|
|
|
{ "tr-TR", "Turkish (Turkey)" },
|
|
|
|
|
{ "uk-UA", "Ukrainian (Ukraine)" },
|
|
|
|
|
{ "vi-VN", "Vietnamese (Vietnam)" },
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
ProgSettings::ProgSettings(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, ui(new Ui::ProgSettings)
|
2021-12-28 16:47:10 +06:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2025-04-17 21:52:32 +05:00
|
|
|
ui->comboBoxLanguage->setItemData(0, 0);
|
|
|
|
|
for (int i = 1; i < languages.length(); i++) {
|
|
|
|
|
ui->comboBoxLanguage->addItem(languages[i].second, i);
|
|
|
|
|
if (i == lang_id) {
|
|
|
|
|
ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i));
|
2022-01-08 16:39:51 +06:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-17 02:39:17 +05:00
|
|
|
ui->comboBoxLanguage->model()->sort(Qt::AscendingOrder);
|
2022-06-01 15:31:58 +06:00
|
|
|
|
|
|
|
|
mouseSensitivity = mouse_sensitivity;
|
|
|
|
|
ui->horizontalSlider->setValue(mouseSensitivity * 100.);
|
2022-07-30 14:56:44 -04:00
|
|
|
ui->openDirUsrPath->setChecked(open_dir_usr_path > 0);
|
2025-03-13 19:55:46 +06:00
|
|
|
ui->checkBoxMultimediaKeys->setChecked(inhibit_multimedia_keys);
|
2025-03-26 16:37:59 +06:00
|
|
|
ui->checkBoxConfirmExit->setChecked(confirm_exit);
|
|
|
|
|
ui->checkBoxConfirmSave->setChecked(confirm_save);
|
2025-03-26 16:52:35 +06:00
|
|
|
ui->checkBoxConfirmHardReset->setChecked(confirm_reset);
|
|
|
|
|
ui->checkBoxFullscreenFirst->setChecked(video_fullscreen_first);
|
|
|
|
|
|
2025-03-13 19:55:46 +06:00
|
|
|
#ifndef Q_OS_WINDOWS
|
|
|
|
|
ui->checkBoxMultimediaKeys->setHidden(true);
|
|
|
|
|
#endif
|
2021-12-28 16:47:10 +06:00
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
ProgSettings::accept()
|
2021-12-28 16:47:10 +06:00
|
|
|
{
|
2025-04-17 21:52:32 +05:00
|
|
|
lang_id = ui->comboBoxLanguage->currentData().toInt();
|
2025-03-13 19:55:46 +06:00
|
|
|
open_dir_usr_path = ui->openDirUsrPath->isChecked() ? 1 : 0;
|
2025-03-26 16:37:59 +06:00
|
|
|
confirm_exit = ui->checkBoxConfirmExit->isChecked() ? 1 : 0;
|
|
|
|
|
confirm_save = ui->checkBoxConfirmSave->isChecked() ? 1 : 0;
|
2025-03-26 16:52:35 +06:00
|
|
|
confirm_reset = ui->checkBoxConfirmHardReset->isChecked() ? 1 : 0;
|
|
|
|
|
video_fullscreen_first = ui->checkBoxFullscreenFirst->isChecked() ? 1 : 0;
|
2025-04-08 15:29:07 +05:00
|
|
|
inhibit_multimedia_keys = ui->checkBoxMultimediaKeys->isChecked() ? 1 : 0;
|
2021-12-28 16:47:10 +06:00
|
|
|
|
2022-01-08 16:39:51 +06:00
|
|
|
loadTranslators(QCoreApplication::instance());
|
|
|
|
|
reloadStrings();
|
|
|
|
|
update_mouse_msg();
|
|
|
|
|
main_window->ui->retranslateUi(main_window);
|
2022-02-10 16:55:38 +06:00
|
|
|
QString vmname(vm_name);
|
2022-11-19 08:49:04 -05:00
|
|
|
if (vmname.at(vmname.size() - 1) == '"' || vmname.at(vmname.size() - 1) == '\'')
|
|
|
|
|
vmname.truncate(vmname.size() - 1);
|
2022-02-10 16:55:38 +06:00
|
|
|
main_window->setWindowTitle(QString("%1 - %2 %3").arg(vmname, EMU_NAME, EMU_VERSION_FULL));
|
2021-12-28 16:47:10 +06:00
|
|
|
QString msg = main_window->status->getMessage();
|
|
|
|
|
main_window->status.reset(new MachineStatus(main_window));
|
|
|
|
|
main_window->refreshMediaMenu();
|
|
|
|
|
main_window->status->message(msg);
|
2021-12-29 23:49:09 +06:00
|
|
|
connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip);
|
2022-03-17 16:31:14 -03:00
|
|
|
connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message, Qt::QueuedConnection);
|
2022-06-01 15:31:58 +06:00
|
|
|
mouse_sensitivity = mouseSensitivity;
|
2021-12-28 16:47:10 +06:00
|
|
|
QDialog::accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProgSettings::~ProgSettings()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 16:48:09 +05:00
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
|
/* Return the standard font name on Windows, which is overridden per-language
|
|
|
|
|
to prevent CJK fonts with embedded bitmaps being chosen as a fallback. */
|
|
|
|
|
QString
|
2025-04-17 21:52:32 +05:00
|
|
|
ProgSettings::getFontName(int langId)
|
2024-03-20 16:48:09 +05:00
|
|
|
{
|
2025-04-17 21:52:32 +05:00
|
|
|
QString langCode = languageIdToCode(lang_id);
|
|
|
|
|
if (langCode == "ja-JP") {
|
|
|
|
|
/* Check for Windows 10 or later to choose the appropriate system font */
|
|
|
|
|
if (QVersionNumber::fromString(QSysInfo::kernelVersion()).majorVersion() >= 10)
|
|
|
|
|
return "Yu Gothic UI";
|
|
|
|
|
else
|
|
|
|
|
return "Meiryo UI";
|
|
|
|
|
} else if (langCode == "ko-KR")
|
|
|
|
|
return "Malgun Gothic";
|
|
|
|
|
else if (langCode == "zh-CN")
|
|
|
|
|
return "Microsoft YaHei";
|
|
|
|
|
else if (langCode == "zh-TW")
|
|
|
|
|
return "Microsoft JhengHei";
|
|
|
|
|
else
|
|
|
|
|
return "Segoe UI";
|
2024-03-20 16:48:09 +05:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-04-17 21:52:32 +05:00
|
|
|
int
|
|
|
|
|
ProgSettings::languageCodeToId(QString langCode)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < languages.length(); i++) {
|
|
|
|
|
if (languages[i].first == langCode) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
|
ProgSettings::languageIdToCode(int id)
|
|
|
|
|
{
|
|
|
|
|
if ((id == 0) || (id >= languages.length())) {
|
|
|
|
|
return "system";
|
|
|
|
|
}
|
|
|
|
|
return languages[id].first;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
ProgSettings::loadTranslators(QObject *parent)
|
2022-01-08 16:39:51 +06:00
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
if (qtTranslator) {
|
2022-01-08 16:39:51 +06:00
|
|
|
QApplication::removeTranslator(qtTranslator);
|
|
|
|
|
qtTranslator = nullptr;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
if (translator) {
|
2022-01-08 16:39:51 +06:00
|
|
|
QApplication::removeTranslator(translator);
|
|
|
|
|
translator = nullptr;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
qtTranslator = new QTranslator(parent);
|
|
|
|
|
translator = new CustomTranslator(parent);
|
2022-01-08 16:39:51 +06:00
|
|
|
QString localetofilename = "";
|
2025-04-17 21:52:32 +05:00
|
|
|
if (lang_id == 0 || lang_id >= languages.length()) {
|
2022-11-19 08:49:04 -05:00
|
|
|
for (int i = 0; i < QLocale::system().uiLanguages().size(); i++) {
|
2022-01-08 16:39:51 +06:00
|
|
|
localetofilename = QLocale::system().uiLanguages()[i];
|
2022-11-19 08:49:04 -05:00
|
|
|
if (translator->load(QLatin1String("86box_") + localetofilename, QLatin1String(":/"))) {
|
2022-01-08 16:39:51 +06:00
|
|
|
qDebug() << "Translations loaded.\n";
|
|
|
|
|
QCoreApplication::installTranslator(translator);
|
2022-02-04 15:27:53 +06:00
|
|
|
if (!qtTranslator->load(QLatin1String("qtbase_") + localetofilename.replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
2024-11-18 02:33:55 +05:00
|
|
|
if (!qtTranslator->load(QLatin1String("qtbase_") + localetofilename.left(localetofilename.indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
|
|
|
|
if (!qtTranslator->load(QLatin1String("qt_") + localetofilename.replace('-', '_'), QApplication::applicationDirPath() + "/./translations/"))
|
|
|
|
|
qtTranslator->load(QLatin1String("qt_") + localetofilename.replace('-', '_'), QLatin1String(":/"));
|
2022-11-19 08:49:04 -05:00
|
|
|
if (QApplication::installTranslator(qtTranslator)) {
|
|
|
|
|
qDebug() << "Qt translations loaded."
|
|
|
|
|
<< "\n";
|
2022-01-08 16:39:51 +06:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
} else {
|
2025-04-17 21:52:32 +05:00
|
|
|
translator->load(QLatin1String("86box_") + languages[lang_id].first, QLatin1String(":/"));
|
2022-01-08 16:39:51 +06:00
|
|
|
QCoreApplication::installTranslator(translator);
|
2025-04-17 21:52:32 +05:00
|
|
|
if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
|
|
|
|
if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).left(QString(languages[lang_id].first).indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
|
|
|
|
if(!qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QApplication::applicationDirPath() + "/./translations/"))
|
|
|
|
|
qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QLatin1String(":/"));
|
2024-11-18 02:33:55 +05:00
|
|
|
|
2022-01-08 16:39:51 +06:00
|
|
|
QCoreApplication::installTranslator(qtTranslator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
ProgSettings::on_pushButtonLanguage_released()
|
2022-01-08 16:39:51 +06:00
|
|
|
{
|
|
|
|
|
ui->comboBoxLanguage->setCurrentIndex(0);
|
|
|
|
|
}
|
2022-06-01 15:31:58 +06:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
ProgSettings::on_horizontalSlider_valueChanged(int value)
|
2022-06-01 15:31:58 +06:00
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
mouseSensitivity = (double) value / 100.;
|
2022-06-01 15:31:58 +06:00
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
ProgSettings::on_pushButton_2_clicked()
|
2022-06-01 16:31:06 +06:00
|
|
|
{
|
|
|
|
|
mouseSensitivity = 1.0;
|
|
|
|
|
ui->horizontalSlider->setValue(100);
|
|
|
|
|
}
|