00001 /*************************************************************************** 00002 * Copyright (c) 2010 Jürgen Riegel <juergen.riegel@web.de> * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This library is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Library General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Library General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Library General Public * 00017 * License along with this library; see the file COPYING.LIB. If not, * 00018 * write to the Free Software Foundation, Inc., 59 Temple Place, * 00019 * Suite 330, Boston, MA 02111-1307, USA * 00020 * * 00021 ***************************************************************************/ 00022 00023 00024 #include "PreCompiled.h" 00025 00026 #ifndef _PreComp_ 00027 # include <QRegExp> 00028 #endif 00029 00030 #include "DlgSettingsUnitsImp.h" 00031 #include "NavigationStyle.h" 00032 #include "PrefWidgets.h" 00033 #include <App/Application.h> 00034 #include <Base/Console.h> 00035 #include <Base/Parameter.h> 00036 #include <Base/UnitsApi.h> 00037 00038 using namespace Gui::Dialog; 00039 using namespace Base; 00040 00041 /* TRANSLATOR Gui::Dialog::DlgSettingsUnitsImp */ 00042 00047 DlgSettingsUnitsImp::DlgSettingsUnitsImp(QWidget* parent) 00048 : PreferencePage( parent ) 00049 { 00050 this->setupUi(this); 00051 //this->setEnabled(false); 00052 retranslate(); 00053 00054 //fillUpListBox(); 00055 00056 QObject::connect(comboBox_ViewSystem, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int))); 00057 00058 } 00059 00063 DlgSettingsUnitsImp::~DlgSettingsUnitsImp() 00064 { 00065 // no need to delete child widgets, Qt does it all for us 00066 } 00067 00068 void DlgSettingsUnitsImp::fillUpListBox() 00069 { 00070 tableWidget->setRowCount(10); 00071 for (int i = 0 ; i<9;i++) { 00072 QTableWidgetItem *newItem = new QTableWidgetItem(UnitsApi::getQuantityName((Base::QuantityType)i)); 00073 tableWidget->setItem(i, 0, newItem); 00074 00075 newItem = new QTableWidgetItem(UnitsApi::getPrefUnitOf((Base::QuantityType)i)); 00076 tableWidget->setItem(i, 1, newItem); 00077 } 00078 } 00079 00080 void DlgSettingsUnitsImp::currentIndexChanged(int index) 00081 { 00082 if (index < 0) 00083 return; // happens when clearing the combo box in retranslateUi() 00084 assert(index>-1 && index <3); 00085 00086 UnitsApi::setSchema((UnitSystem)index); 00087 00088 fillUpListBox(); 00089 } 00090 00091 void DlgSettingsUnitsImp::saveSettings() 00092 { 00093 // must be done as very first because we create a new instance of NavigatorStyle 00094 // where we set some attributes afterwards 00095 ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath 00096 ("User parameter:BaseApp/Preferences/Units"); 00097 hGrp->SetInt("UserSchema", comboBox_ViewSystem->currentIndex()); 00098 } 00099 00100 void DlgSettingsUnitsImp::loadSettings() 00101 { 00102 00103 ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath 00104 ("User parameter:BaseApp/Preferences/Units"); 00105 comboBox_ViewSystem->setCurrentIndex(hGrp->GetInt("UserSchema",0)); 00106 } 00107 00111 void DlgSettingsUnitsImp::changeEvent(QEvent *e) 00112 { 00113 if (e->type() == QEvent::LanguageChange) { 00114 retranslateUi(this); 00115 retranslate(); 00116 } 00117 else { 00118 QWidget::changeEvent(e); 00119 } 00120 } 00121 00122 void DlgSettingsUnitsImp::retranslate() 00123 { 00124 } 00125 00126 #include "moc_DlgSettingsUnitsImp.cpp"