[qet] [2762] Add widget to select langage, must relauch qet for make change

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2762
Author:   blacksun
Date:     2014-01-21 20:23:44 +0100 (Tue, 21 Jan 2014)
Log Message:
-----------
Add widget to select langage, must relauch qet for make change

Modified Paths:
--------------
    trunk/sources/configpages.cpp
    trunk/sources/configpages.h
    trunk/sources/genericpanel.cpp
    trunk/sources/nameslist.cpp
    trunk/sources/projectconfigpages.cpp
    trunk/sources/qetapp.cpp
    trunk/sources/qetapp.h

Modified: trunk/sources/configpages.cpp
===================================================================
--- trunk/sources/configpages.cpp	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/configpages.cpp	2014-01-21 19:23:44 UTC (rev 2762)
@@ -51,7 +51,7 @@
 
 	// 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 @@
 	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 @@
 	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 @@
 }
 
 /**
-	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 @@
 	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) ;
@@ -210,6 +223,42 @@
 }
 
 /**
+ * @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; i<lang_combo_box->count(); 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
 */

Modified: trunk/sources/configpages.h
===================================================================
--- trunk/sources/configpages.h	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/configpages.h	2014-01-21 19:23:44 UTC (rev 2762)
@@ -70,9 +70,12 @@
 	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 @@
 	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;
 };
 
 /**

Modified: trunk/sources/genericpanel.cpp
===================================================================
--- trunk/sources/genericpanel.cpp	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/genericpanel.cpp	2014-01-21 19:23:44 UTC (rev 2762)
@@ -48,8 +48,7 @@
 		// 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_);
 }

Modified: trunk/sources/nameslist.cpp
===================================================================
--- trunk/sources/nameslist.cpp	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/nameslist.cpp	2014-01-21 19:23:44 UTC (rev 2762)
@@ -16,6 +16,8 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "nameslist.h"
+#include "qetapp.h"
+
 // make this class usable with QVariant
 int NamesList::MetaTypeId = qRegisterMetaType<NamesList>("NamesList");
 
@@ -201,8 +203,7 @@
 	@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];

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/projectconfigpages.cpp	2014-01-21 19:23:44 UTC (rev 2762)
@@ -281,7 +281,7 @@
 
 	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);

Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/qetapp.cpp	2014-01-21 19:23:44 UTC (rev 2762)
@@ -71,9 +71,9 @@
 	non_interactive_execution_(false)
 {
 	parseArguments();
+	initConfiguration();
 	initLanguage();
 	QET::Icons::initIcons();
-	initConfiguration();
 	initStyle();
 	
 	if (!non_interactive_execution_ && isRunning()) {
@@ -107,7 +107,7 @@
 	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)
@@ -184,6 +184,16 @@
 }
 
 /**
+ * @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.
 */
 void QETApp::switchLayout(Qt::LayoutDirection direction) {
@@ -1300,9 +1310,7 @@
 	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());
 }
 
 /**

Modified: trunk/sources/qetapp.h
===================================================================
--- trunk/sources/qetapp.h	2014-01-20 19:30:20 UTC (rev 2761)
+++ trunk/sources/qetapp.h	2014-01-21 19:23:44 UTC (rev 2762)
@@ -61,6 +61,7 @@
 	public:
 	static QETApp *instance();
 	void setLanguage(const QString &);
+	static QString langFromSetting ();
 	void switchLayout(Qt::LayoutDirection);
 	static void printHelp();
 	static void printVersion();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/