DlgSettings3DViewImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 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 # include <memory>
00029 #endif
00030 
00031 #include "DlgSettings3DViewImp.h"
00032 #include "NavigationStyle.h"
00033 #include "PrefWidgets.h"
00034 #include "ui_MouseButtons.h"
00035 #include <App/Application.h>
00036 #include <Base/Console.h>
00037 #include <Base/Parameter.h>
00038 #include <Base/Tools.h>
00039 
00040 using namespace Gui::Dialog;
00041 
00042 /* TRANSLATOR Gui::Dialog::DlgSettings3DViewImp */
00043 
00048 DlgSettings3DViewImp::DlgSettings3DViewImp(QWidget* parent)
00049     : PreferencePage( parent )
00050 {
00051     this->setupUi(this);
00052     retranslate();
00053 }
00054 
00058 DlgSettings3DViewImp::~DlgSettings3DViewImp()
00059 {
00060     // no need to delete child widgets, Qt does it all for us
00061 }
00062 
00063 void DlgSettings3DViewImp::saveSettings()
00064 {
00065     // must be done as very first because we create a new instance of NavigatorStyle
00066     // where we set some attributes afterwards
00067     ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
00068         ("User parameter:BaseApp/Preferences/View");
00069     QVariant data = comboNavigationStyle->itemData(comboNavigationStyle->currentIndex(), Qt::UserRole);
00070     hGrp->SetASCII("NavigationStyle", (const char*)data.toByteArray());
00071 
00072     int index = comboOrbitStyle->currentIndex();
00073     hGrp->SetInt("OrbitStyle", index);
00074 
00075     checkBoxInvertZoom->onSave();
00076     checkBoxAntiAliasing->onSave();
00077     CheckBox_CornerCoordSystem->onSave();
00078     CheckBox_ShowFPS->onSave();
00079     CheckBox_UseAutoRotation->onSave();
00080     FloatSpinBox_EyeDistance->onSave();
00081     checkBoxBacklight->onSave();
00082     backlightColor->onSave();
00083     sliderIntensity->onSave();
00084     radioPerspective->onSave();
00085     radioOrthographic->onSave();
00086 }
00087 
00088 void DlgSettings3DViewImp::loadSettings()
00089 {
00090     checkBoxInvertZoom->onRestore();
00091     checkBoxAntiAliasing->onRestore();
00092     CheckBox_CornerCoordSystem->onRestore();
00093     CheckBox_ShowFPS->onRestore();
00094     CheckBox_UseAutoRotation->onRestore();
00095     FloatSpinBox_EyeDistance->onRestore();
00096     checkBoxBacklight->onRestore();
00097     backlightColor->onRestore();
00098     sliderIntensity->onRestore();
00099     radioPerspective->onRestore();
00100     radioOrthographic->onRestore();
00101 
00102     ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
00103         ("User parameter:BaseApp/Preferences/View");
00104     std::string model = hGrp->GetASCII("NavigationStyle",CADNavigationStyle::getClassTypeId().getName());
00105     int index = comboNavigationStyle->findData(QByteArray(model.c_str()));
00106     if (index > -1) comboNavigationStyle->setCurrentIndex(index);
00107 
00108     index = comboOrbitStyle->currentIndex();
00109     index = hGrp->GetInt("OrbitStyle", index);
00110     index = Base::clamp(index, 0, comboOrbitStyle->count()-1);
00111     comboOrbitStyle->setCurrentIndex(index);
00112 }
00113 
00114 void DlgSettings3DViewImp::on_mouseButton_clicked()
00115 {
00116     QDialog dlg(this);
00117     Ui_MouseButtons ui;
00118     ui.setupUi(&dlg);
00119 
00120     QVariant data = comboNavigationStyle->itemData(comboNavigationStyle->currentIndex(), Qt::UserRole);
00121     void* instance = Base::Type::createInstanceByName((const char*)data.toByteArray());
00122     std::auto_ptr<UserNavigationStyle> ns(static_cast<UserNavigationStyle*>(instance));
00123     ui.groupBox->setTitle(ui.groupBox->title()+QString::fromAscii(" ")+comboNavigationStyle->currentText());
00124     QString descr;
00125     descr = qApp->translate((const char*)data.toByteArray(),ns->mouseButtons(NavigationStyle::SELECTION));
00126     ui.selectionLabel->setText(QString::fromAscii("<b>%1</b>").arg(descr));
00127     descr = qApp->translate((const char*)data.toByteArray(),ns->mouseButtons(NavigationStyle::PANNING));
00128     ui.panningLabel->setText(QString::fromAscii("<b>%1</b>").arg(descr));
00129     descr = qApp->translate((const char*)data.toByteArray(),ns->mouseButtons(NavigationStyle::DRAGGING));
00130     ui.rotationLabel->setText(QString::fromAscii("<b>%1</b>").arg(descr));
00131     descr = qApp->translate((const char*)data.toByteArray(),ns->mouseButtons(NavigationStyle::ZOOMING));
00132     ui.zoomingLabel->setText(QString::fromAscii("<b>%1</b>").arg(descr));
00133     dlg.exec();
00134 }
00135 
00139 void DlgSettings3DViewImp::changeEvent(QEvent *e)
00140 {
00141     if (e->type() == QEvent::LanguageChange) {
00142         int navigation = comboNavigationStyle->currentIndex();
00143         int orbit = comboOrbitStyle->currentIndex();
00144         retranslateUi(this);
00145         retranslate();
00146         comboNavigationStyle->setCurrentIndex(navigation);
00147         comboOrbitStyle->setCurrentIndex(orbit);
00148     }
00149     else {
00150         QWidget::changeEvent(e);
00151     }
00152 }
00153 
00154 void DlgSettings3DViewImp::retranslate()
00155 {
00156     std::vector<Base::Type> types;
00157     Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types);
00158     comboNavigationStyle->clear();
00159 
00160     QRegExp rx(QString::fromAscii("^\\w+::(\\w+)Navigation\\w+$"));
00161     for (std::vector<Base::Type>::iterator it = types.begin(); it != types.end(); ++it) {
00162         if (*it != UserNavigationStyle::getClassTypeId()) {
00163             QString data = QString::fromAscii(it->getName());
00164             QString name = data.mid(data.indexOf(QLatin1String("::"))+2);
00165             if (rx.indexIn(data) > -1) {
00166                 name = tr("%1 navigation").arg(rx.cap(1));
00167             }
00168             comboNavigationStyle->addItem(name, data);
00169         }
00170     }
00171 }
00172 
00173 #include "moc_DlgSettings3DViewImp.cpp"
00174 

Generated on Wed Nov 23 19:00:07 2011 for FreeCAD by  doxygen 1.6.1