From 29d6b443fac1caaa2900d3a09a68cc2a3793b7fd Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 10 Jan 2011 00:21:51 +0200 Subject: [PATCH] GUI: Add language selection panel to settings-dialog. Settings-dialog is more natural place for language selection than the main menu. We also have more space and freedom there to have longer text etc to make the selection easier (menus are quite limited controls). --- gui/mainwindow.cpp | 6 +++++- gui/settings.ui | 14 ++++++++++++++ gui/settingsdialog.cpp | 16 ++++++++++++++++ gui/settingsdialog.h | 12 ++++++++++++ gui/translationhandler.cpp | 3 +-- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 9eede6b97..01fc4356d 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -436,7 +436,7 @@ void MainWindow::CheckDone() void MainWindow::ProgramSettings() { - SettingsDialog dialog(mSettings, mApplications, this); + SettingsDialog dialog(mSettings, mApplications, mTranslation, this); if (dialog.exec() == QDialog::Accepted) { dialog.SaveSettingValues(); @@ -444,6 +444,10 @@ void MainWindow::ProgramSettings() dialog.SaveFullPath(), dialog.SaveAllErrors(), dialog.ShowNoErrorsMessage()); + const int currentLang = mTranslation->GetCurrentLanguage(); + const int newLang = mSettings->value(SETTINGS_LANGUAGE, 0).toInt(); + if (currentLang != newLang) + SetLanguage(newLang); } } diff --git a/gui/settings.ui b/gui/settings.ui index ea1ba274d..ac5f19f33 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -254,6 +254,20 @@ + + + Language + + + + + + QAbstractItemView::SelectRows + + + + + diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 4563b2b27..71f0c34de 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -30,14 +30,17 @@ #include "settingsdialog.h" #include "applicationdialog.h" #include "applicationlist.h" +#include "translationhandler.h" #include "common.h" SettingsDialog::SettingsDialog(QSettings *programSettings, ApplicationList *list, + TranslationHandler *translator, QWidget *parent) : QDialog(parent), mSettings(programSettings), mApplications(list), + mTranslator(translator), mTempApplications(new ApplicationList(this)) { mUI.setupUi(this); @@ -78,6 +81,7 @@ SettingsDialog::SettingsDialog(QSettings *programSettings, mUI.mLblIdealThreads->setText(tr("N/A")); LoadSettings(); + InitTranslationsList(); } SettingsDialog::~SettingsDialog() @@ -85,6 +89,17 @@ SettingsDialog::~SettingsDialog() SaveSettings(); } +void SettingsDialog::InitTranslationsList() +{ + QStringList languages = mTranslator->GetNames(); + foreach(const QString lang, languages) + { + mUI.mListLanguages->addItem(lang); + } + const int current = mTranslator->GetCurrentLanguage(); + mUI.mListLanguages->setCurrentRow(current); +} + Qt::CheckState SettingsDialog::BoolToCheckState(bool yes) const { if (yes) @@ -133,6 +148,7 @@ void SettingsDialog::SaveSettingValues() SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS); SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS); mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text()); + mSettings->setValue(SETTINGS_LANGUAGE, mUI.mListLanguages->currentRow()); } void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index d97591f7c..b99b5c294 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -27,6 +27,7 @@ class QSettings; class QWidget; class ApplicationList; +class TranslationHandler; /// @addtogroup GUI /// @{ @@ -41,6 +42,7 @@ class SettingsDialog : public QDialog public: SettingsDialog(QSettings *programSettings, ApplicationList *list, + TranslationHandler *translator, QWidget *parent = 0); virtual ~SettingsDialog(); @@ -163,6 +165,10 @@ protected: */ bool CheckStateToBool(Qt::CheckState state) const; + /** + * @brief Populate the translations list. + */ + void InitTranslationsList(); /** * @brief Settings @@ -183,6 +189,12 @@ protected: */ ApplicationList *mTempApplications; + /** + * @brief List of translations. + * + */ + TranslationHandler *mTranslator; + /** * @brief Dialog from UI designer * diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 7b9e6e46d..d6b8e9dba 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -16,12 +16,11 @@ * along with this program. If not, see . */ -#include "translationhandler.h" - #include #include #include #include +#include "translationhandler.h" TranslationHandler::TranslationHandler(QObject *parent) : QObject(parent),