diff --git a/sources/configpages.cpp b/sources/configpages.cpp index cb541dd1c..5aad01784 100644 --- a/sources/configpages.cpp +++ b/sources/configpages.cpp @@ -51,7 +51,7 @@ NewDiagramPage::NewDiagramPage(QWidget *parent) : ConfigPage(parent) { // default propertie of report label rpw = new ReportPropertieWidget(QETDiagramEditor::defaultReportProperties()); - tab_widget->addTab(rpw, ("Report de folio")); + tab_widget->addTab(rpw, tr("Report de folio")); QVBoxLayout *vlayout1 = new QVBoxLayout(); vlayout1->addWidget(tab_widget); @@ -156,6 +156,15 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ConfigPage elements_management_layout -> addWidget(default_element_infos_label_); elements_management_layout -> addWidget(default_element_infos_textfield_); elements_management_ -> setLayout(elements_management_layout); + + //setup lang combo box selection widget + lang_group_box = new QGroupBox(tr("Langue"), this); + QHBoxLayout *lang_layout = new QHBoxLayout(lang_group_box); + lang_combo_box = new QComboBox(); + lang_label = new QLabel(tr("La nouvelle langue sera pris en compte au prochain lancement de QElectroTech.")); + lang_layout->addWidget(lang_combo_box); + lang_layout->addWidget(lang_label); + fillLang(settings); QVBoxLayout *vlayout1 = new QVBoxLayout(); @@ -169,6 +178,7 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ConfigPage vlayout1 -> addWidget(appearance_); vlayout1 -> addWidget(projects_view_mode_); vlayout1 -> addWidget(elements_management_); + vlayout1 -> addWidget(lang_group_box); vlayout1 -> addStretch(); setLayout(vlayout1); @@ -179,8 +189,9 @@ GeneralConfigurationPage::~GeneralConfigurationPage() { } /** - Applique la configuration de cette page -*/ + * @brief GeneralConfigurationPage::applyConf + * Write all configuration in settings file + */ void GeneralConfigurationPage::applyConf() { QSettings &settings = QETApp::settings(); @@ -190,6 +201,8 @@ void GeneralConfigurationPage::applyConf() { if (was_using_system_colors != must_use_system_colors) { QETApp::instance() -> useSystemPalette(must_use_system_colors); } + + settings.setValue("lang", lang_combo_box->itemData(lang_combo_box->currentIndex()).toString()); QString view_mode = tabbed_mode_ -> isChecked() ? "tabbed" : "windowed"; settings.setValue("diagrameditor/viewmode", view_mode) ; @@ -209,6 +222,42 @@ QString GeneralConfigurationPage::title() const { return(tr("G\351n\351ral", "configuration page title")); } +/** + * @brief GeneralConfigurationPage::fillLang + * fill all available lang in @lang_combo_box + */ +void GeneralConfigurationPage::fillLang(QSettings &settings) { + lang_combo_box->addItem(tr("Syst\350me"), "system"); + lang_combo_box->insertSeparator(1); + + // all lang available on lang directory + lang_combo_box->addItem(tr("Arabe"), "ar"); + lang_combo_box->addItem(tr("Catalan"), "ca"); + lang_combo_box->addItem(tr("Tch\350que"), "cs"); + lang_combo_box->addItem(tr("Allemand"), "de"); + lang_combo_box->addItem(tr("Grec"), "el"); + lang_combo_box->addItem(tr("Anglais"), "en"); + lang_combo_box->addItem(tr("Espagnol"), "es"); + lang_combo_box->addItem(tr("Fran\347ais"), "fr"); + lang_combo_box->addItem(tr("Croate"), "hr"); + lang_combo_box->addItem(tr("Italien"), "it"); + lang_combo_box->addItem(tr("Polonais"), "pl"); + lang_combo_box->addItem(tr("Portugais"), "pt"); + lang_combo_box->addItem(tr("Roumains"), "ro"); + lang_combo_box->addItem(tr("Russe"), "ru"); + lang_combo_box->addItem(tr("Slov\350ne"), "sl"); + + //set curent index to the lang found in setting file + //if lang doesn't exist set to system + for (int i=0; icount(); i++) { + if (lang_combo_box->itemData(i).toString() == settings.value("lang").toString()) { + lang_combo_box->setCurrentIndex(i); + return; + } + } + lang_combo_box->setCurrentIndex(0); +} + /** Constructeur @param parent QWidget parent diff --git a/sources/configpages.h b/sources/configpages.h index 004ef3960..23564de73 100644 --- a/sources/configpages.h +++ b/sources/configpages.h @@ -70,9 +70,12 @@ class GeneralConfigurationPage : public ConfigPage { void applyConf(); QString title() const; QIcon icon() const; + + private: + void fillLang(QSettings &); // attributes - public: + private: QLabel *title_label_; QFrame *horiz_line_; QGroupBox *appearance_; @@ -86,6 +89,9 @@ class GeneralConfigurationPage : public ConfigPage { QCheckBox *highlight_integrated_elements_; QLabel *default_element_infos_label_; QTextEdit *default_element_infos_textfield_; + QGroupBox *lang_group_box; + QComboBox *lang_combo_box; + QLabel *lang_label; }; /** diff --git a/sources/genericpanel.cpp b/sources/genericpanel.cpp index ea23e7718..ae55d4370 100644 --- a/sources/genericpanel.cpp +++ b/sources/genericpanel.cpp @@ -48,8 +48,7 @@ ElementsCollectionCache *GenericPanel::getElementsCache() { // build a default cache QString cache_path = "./genericpanel.sqlite"; cache_ = new ElementsCollectionCache(cache_path, this); - /// @todo we need a unique function to get the good language - cache_ -> setLocale(QLocale::system().name().left(2)); + cache_->setLocale(QETApp::langFromSetting()); } return(cache_); } diff --git a/sources/nameslist.cpp b/sources/nameslist.cpp index 99bc7c977..3c813e898 100644 --- a/sources/nameslist.cpp +++ b/sources/nameslist.cpp @@ -16,6 +16,8 @@ along with QElectroTech. If not, see . */ #include "nameslist.h" +#include "qetapp.h" + // make this class usable with QVariant int NamesList::MetaTypeId = qRegisterMetaType("NamesList"); @@ -201,8 +203,7 @@ bool NamesList::operator==(const NamesList &nl) const { @return The adequate name regarding the current system locale. */ QString NamesList::name(const QString &fallback_name) const { - // recupere les deux premiers caracteres de la locale en cours du systeme - QString system_language = QLocale::system().name().left(2); + QString system_language = QETApp::langFromSetting(); QString returned_name; if (!hash_names[system_language].isEmpty()) { returned_name = hash_names[system_language]; diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index 377f353d1..d0eedb98c 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -281,7 +281,7 @@ void ProjectNewDiagramConfigPage::initLayout() { tab_widget->addTab(conductor_, tr("Conducteur")); - tab_widget->addTab(report_, ("Report de folio")); + tab_widget->addTab(report_, tr("Report de folio")); QVBoxLayout *vlayout1 = new QVBoxLayout(); vlayout1->addWidget(tab_widget); diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index ce8f1f1ba..de9309182 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -71,9 +71,9 @@ QETApp::QETApp(int &argc, char **argv) : non_interactive_execution_(false) { parseArguments(); + initConfiguration(); initLanguage(); QET::Icons::initIcons(); - initConfiguration(); initStyle(); if (!non_interactive_execution_ && isRunning()) { @@ -107,7 +107,7 @@ QETApp::QETApp(int &argc, char **argv) : if (!collections_cache_) { QString cache_path = QETApp::configDir() + "/elements_cache.sqlite"; collections_cache_ = new ElementsCollectionCache(cache_path, this); - collections_cache_ -> setLocale(QLocale::system().name().left(2)); // @todo we need a unique function to get the good language + collections_cache_->setLocale(langFromSetting()); } // loads known collections into memory (this does not include items rendering made in elements panels) @@ -183,6 +183,16 @@ void QETApp::setLanguage(const QString &desired_language) { if (ltr_special_string == "RTL") switchLayout(Qt::RightToLeft); } +/** + * @brief QETApp::langFromSetting + * @return the langage found in setting file + * if nothing was found return the system local. + */ +QString QETApp::langFromSetting() { + QString system_language = settings().value("lang", "system").toString(); + if(system_language == "system") {system_language = QLocale::system().name().left(2);} + return system_language; +} /** Switches the application to the provided layout. */ @@ -1300,9 +1310,7 @@ void QETApp::setSplashScreenStep(const QString &message) { Determine et applique le langage a utiliser pour l'application */ void QETApp::initLanguage() { - // selectionne le langage du systeme - QString system_language = QLocale::system().name().left(2); - setLanguage(system_language); + setLanguage(langFromSetting()); } /** diff --git a/sources/qetapp.h b/sources/qetapp.h index 3c907ff8a..b7a7c5cfb 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -61,6 +61,7 @@ class QETApp : public QETSingleApplication { public: static QETApp *instance(); void setLanguage(const QString &); + static QString langFromSetting (); void switchLayout(Qt::LayoutDirection); static void printHelp(); static void printVersion();