|
38 | 38 | */ |
39 | 39 |
|
40 | 40 |
|
| 41 | +#include <QLocale> |
41 | 42 | #include <QFileDialog> |
42 | 43 | #include <QMessageBox> |
43 | 44 | #include <QColorDialog> |
@@ -127,7 +128,7 @@ PreferencesDialog::PreferencesDialog(QWidget* Parent, DisplayMode Mode): |
127 | 128 |
|
128 | 129 | initialize(); |
129 | 130 |
|
130 | | - connect(ui->LangComboBox,SIGNAL(currentIndexChanged(const QString&)),this,SLOT(updateLanguage(const QString&))); |
| 131 | + connect(ui->LangComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(updateLanguage(int))); |
131 | 132 | connect(ui->RecentMaxSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRecentsMax(int))); |
132 | 133 | connect(ui->ClearRecentsButton,SIGNAL(clicked()),this,SLOT(clearRecentsList())); |
133 | 134 | connect(ui->AutoSaveCheckBox,SIGNAL(toggled(bool)),this,SLOT(enableAutoSaveBeforeRun(bool))); |
@@ -208,15 +209,40 @@ PreferencesDialog::~PreferencesDialog() |
208 | 209 | // ===================================================================== |
209 | 210 |
|
210 | 211 |
|
| 212 | +QString PreferencesDialog::getLanguageAsPrettyString(const QString& LangCode) |
| 213 | +{ |
| 214 | + QLocale Loc(LangCode); |
| 215 | + QString LangName; |
| 216 | + |
| 217 | + if (Loc.language() == QLocale::English) |
| 218 | + LangName = QLocale::languageToString(Loc.language()); |
| 219 | + else |
| 220 | + LangName = Loc.nativeLanguageName(); |
| 221 | + |
| 222 | + LangName[0] = LangName[0].toUpper(); |
| 223 | + QString CountryName = Loc.nativeCountryName(); |
| 224 | + |
| 225 | + return QString("%1 (%2)").arg(LangName).arg(Loc.nativeCountryName()); |
| 226 | +} |
| 227 | + |
| 228 | + |
| 229 | +// ===================================================================== |
| 230 | +// ===================================================================== |
| 231 | + |
| 232 | + |
211 | 233 | void PreferencesDialog::initialize() |
212 | 234 | { |
213 | 235 | openfluid::base::PreferencesManager* PrefsMan = openfluid::base::PreferencesManager::instance(); |
214 | 236 |
|
215 | | - // Interface |
216 | | - // TODO set up a fancier languages list |
217 | | - ui->LangComboBox->addItem("default"); |
218 | | - ui->LangComboBox->addItems(openfluid::base::PreferencesManager::getAvailableLangs()); |
219 | | - ui->LangComboBox->setCurrentIndex(ui->LangComboBox->findText(PrefsMan->getLang())); |
| 237 | + // Interface language |
| 238 | + QStringList AvailLangCodes = openfluid::base::PreferencesManager::getAvailableLangs(); |
| 239 | + |
| 240 | + ui->LangComboBox->addItem(getLanguageAsPrettyString("en_GB"),"default"); |
| 241 | + for (auto Code : AvailLangCodes) |
| 242 | + { |
| 243 | + ui->LangComboBox->addItem(getLanguageAsPrettyString(Code),Code); |
| 244 | + } |
| 245 | + ui->LangComboBox->setCurrentIndex(ui->LangComboBox->findData(PrefsMan->getLang())); |
220 | 246 |
|
221 | 247 | m_OriginalLangIndex = ui->LangComboBox->currentIndex(); |
222 | 248 |
|
@@ -298,8 +324,10 @@ void PreferencesDialog::changePage(QTreeWidgetItem* Current, QTreeWidgetItem* Pr |
298 | 324 | // ===================================================================== |
299 | 325 |
|
300 | 326 |
|
301 | | -void PreferencesDialog::updateLanguage(const QString& Lang) |
| 327 | +void PreferencesDialog::updateLanguage(int Index) |
302 | 328 | { |
| 329 | + QString Lang = ui->LangComboBox->itemData(Index).toString(); |
| 330 | + |
303 | 331 | openfluid::base::PreferencesManager::instance()->setLang(Lang); |
304 | 332 |
|
305 | 333 | updateRestartStatus(); |
|
0 commit comments