UniversalIndentGUI 1.2.0
UiGuiSettingsDialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
00003 *   thomas-schweitzer(at)arcor.de                                         *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU General Public License version 2.0 as   *
00007 *   published by the Free Software Foundation.                            *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU General Public License     *
00015 *   along with this program in the file LICENSE.GPL; if not, write to the *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018 ***************************************************************************/
00019 
00020 #include "UiGuiSettingsDialog.h"
00021 #include "ui_UiGuiSettingsDialog.h"
00022 
00023 #include "UiGuiSettings.h"
00024 
00034 UiGuiSettingsDialog::UiGuiSettingsDialog(QWidget* parent, QSharedPointer<UiGuiSettings> settings) : QDialog(parent) {
00035     // Remember pointer to the UiGuiSettings object.
00036     _settings = settings;
00037 
00038     // Init the user interface created by the UIC.
00039     _settingsDialogForm = new Ui::SettingsDialog();
00040     _settingsDialogForm->setupUi(this);
00041 
00042     //TODO: This call has to be removed when the properties for the highlighters can be set
00043     // with the settings dialog.
00044     _settingsDialogForm->groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + _settingsDialogForm->groupBoxSyntaxHighlighterProperties->toolTip() );
00045 
00046     // Connect the accepted signal to own function, to write values back to the UiGuiSettings object.
00047     connect(this, SIGNAL(accepted()), this, SLOT(writeWidgetValuesToSettings()) );
00048 
00049     // Init the language selection combobox.
00050     initTranslationSelection();
00051 }
00052 
00053 
00060 void UiGuiSettingsDialog::initTranslationSelection() {
00061     // First empty the combo box.
00062     _settingsDialogForm->languageSelectionComboBox->clear();
00063 
00064     // Now add an entry into the box for every language short.
00065     foreach (QString languageShort, _settings->getAvailableTranslations() ) {
00066         // Identify the language mnemonic and set the full name.
00067         if ( languageShort == "en" ) {
00068             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("English") );
00069         }
00070         else if ( languageShort == "fr" ) {
00071             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("French") );
00072         }
00073         else if ( languageShort == "de" ) {
00074             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("German") );
00075         }
00076         else if ( languageShort == "zh_TW" ) {
00077             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Chinese (Taiwan)") );
00078         }
00079         else if ( languageShort == "ja" ) {
00080             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Japanese") );
00081         }
00082         else if ( languageShort == "ru" ) {
00083             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Russian") );
00084         }
00085         else if ( languageShort == "uk" ) {
00086             _settingsDialogForm->languageSelectionComboBox->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Ukrainian") );
00087         }
00088 
00089         else {
00090             _settingsDialogForm->languageSelectionComboBox->addItem( tr("Unknown language mnemonic ") + languageShort );
00091         }
00092     }
00093 }
00094 
00095 
00101 int UiGuiSettingsDialog::showDialog() {
00102     // Init all settings dialog objects with values from settings.
00103     _settings->setObjectPropertyToSettingValueRecursive(this);
00104 
00105     // Execute the dialog.
00106     return exec();
00107 }
00108 
00109 
00115 void UiGuiSettingsDialog::writeWidgetValuesToSettings() {
00116     // Write settings dialog object values to settings.
00117     _settings->setSettingToObjectPropertyValueRecursive(this);
00118 }
00119 
00120 
00124 void UiGuiSettingsDialog::changeEvent(QEvent *event) {
00125     if (event->type() == QEvent::LanguageChange) {
00126         _settingsDialogForm->retranslateUi(this);
00127         // If this is not explicit set here, Qt < 4.3.0 does not translate the buttons.
00128         _settingsDialogForm->buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
00129 
00130         //TODO: This has to be removed when the properties for the highlighters can be set.
00131         _settingsDialogForm->groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + _settingsDialogForm->groupBoxSyntaxHighlighterProperties->toolTip() );
00132 
00133         QStringList languageShortList = _settings->getAvailableTranslations();
00134 
00135         // Now retranslate every entry in the language selection box.
00136         for (int i = 0; i < languageShortList.size(); i++ ) {
00137             QString languageShort = languageShortList.at(i);
00138 
00139             // Identify the language mnemonic and set the full name.
00140             if ( languageShort == "en" ) {
00141                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("English") );
00142             }
00143             else if ( languageShort == "fr" ) {
00144                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("French") );
00145             }
00146             else if ( languageShort == "de" ) {
00147                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("German") );
00148             }
00149             else if ( languageShort == "zh_TW" ) {
00150                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("Chinese (Taiwan)") );
00151             }
00152             else if ( languageShort == "ja" ) {
00153                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("Japanese") );
00154             }
00155             else if ( languageShort == "ru" ) {
00156                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("Russian") );
00157             }
00158             else if ( languageShort == "uk" ) {
00159                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("Ukrainian") );
00160             }
00161             else {
00162                 _settingsDialogForm->languageSelectionComboBox->setItemText( i, tr("Unknown language mnemonic ") + languageShort );
00163             }
00164         }
00165     }
00166     else {
00167         QWidget::changeEvent(event);
00168     }
00169 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines