Update selected language automatically

This commit is contained in:
Philipp David 2022-01-13 09:41:51 +01:00
parent 126e6d13aa
commit 2dd2555a63
No known key found for this signature in database
GPG Key ID: 967A5D5EB5071577
3 changed files with 14 additions and 1 deletions

View File

@ -179,8 +179,8 @@ void TranslationsModel::translationDirChanged(const QString& path)
if (selectedLanguage() != defaultLangCode)
{
updateLanguage(selectedLanguage());
APPLICATION->settings()->set("Language", selectedLanguage());
}
APPLICATION->settings()->set("Language", selectedLanguage());
d->no_language_set = false;
}
else

View File

@ -6,6 +6,7 @@
#include <QLabel>
#include "Application.h"
#include "translations/TranslationsModel.h"
#include "settings/Setting.h"
LanguageSelectionWidget::LanguageSelectionWidget(QWidget *parent) :
QWidget(parent)
@ -37,6 +38,9 @@ LanguageSelectionWidget::LanguageSelectionWidget(QWidget *parent) :
languageView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
connect(languageView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &LanguageSelectionWidget::languageRowChanged);
verticalLayout->setContentsMargins(0,0,0,0);
auto language_setting = APPLICATION->settings()->getSetting("Language");
connect(language_setting.get(), &Setting::SettingChanged, this, &LanguageSelectionWidget::languageSettingChanged);
}
QString LanguageSelectionWidget::getSelectedLanguageKey() const
@ -64,3 +68,10 @@ void LanguageSelectionWidget::languageRowChanged(const QModelIndex& current, con
translations->selectLanguage(key);
translations->updateLanguage(key);
}
void LanguageSelectionWidget::languageSettingChanged(const Setting &, const QVariant)
{
auto translations = APPLICATION->translations();
auto index = translations->selectedIndex();
languageView->setCurrentIndex(index);
}

View File

@ -20,6 +20,7 @@
class QVBoxLayout;
class QTreeView;
class QLabel;
class Setting;
class LanguageSelectionWidget: public QWidget
{
@ -33,6 +34,7 @@ public:
protected slots:
void languageRowChanged(const QModelIndex &current, const QModelIndex &previous);
void languageSettingChanged(const Setting &, const QVariant);
private:
QVBoxLayout *verticalLayout = nullptr;