DlgGeneralImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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 #ifndef _PreComp_
00026 # include <QApplication>
00027 # include <QLocale>
00028 # include <QStyleFactory>
00029 #endif
00030 
00031 #include "DlgGeneralImp.h"
00032 #include "Action.h"
00033 #include "Application.h"
00034 #include "DockWindowManager.h"
00035 #include "MainWindow.h"
00036 #include "PrefWidgets.h"
00037 #include "Language/Translator.h"
00038 
00039 using namespace Gui::Dialog;
00040 
00041 /* TRANSLATOR Gui::Dialog::DlgGeneralImp */
00042 
00050 DlgGeneralImp::DlgGeneralImp( QWidget* parent )
00051   : PreferencePage( parent ), watched(0)
00052 {
00053     this->setupUi(this);
00054     // hide to fix 0000375: Mac Interface window style setting not saved
00055     windowStyleLabel->hide();
00056     WindowStyle->hide();
00057     
00058     // fills the combo box with all available workbenches
00059     // sorted by their menu text
00060     QStringList work = Application::Instance->workbenches();
00061     QMap<QString, QString> menuText;
00062     for (QStringList::Iterator it = work.begin(); it != work.end(); ++it) {
00063         QString text = Application::Instance->workbenchMenuText(*it);
00064         menuText[text] = *it;
00065     }
00066 
00067     for (QMap<QString, QString>::Iterator it = menuText.begin(); it != menuText.end(); ++it) {
00068         QPixmap px = Application::Instance->workbenchIcon(it.value());
00069         if (px.isNull())
00070             AutoloadModuleCombo->addItem(it.key(), QVariant(it.value()));
00071         else
00072             AutoloadModuleCombo->addItem(px, it.key(), QVariant(it.value()));
00073     }
00074 
00075     // do not save the content but the current item only
00076     QWidget* dw = DockWindowManager::instance()->getDockWindow("Report view");
00077     if (dw)
00078     {
00079         watched = dw->findChild<QTabWidget*>();
00080         if (watched)
00081         {
00082             for (int i=0; i<watched->count(); i++)
00083                 AutoloadTabCombo->addItem( watched->tabText(i) );
00084             watched->installEventFilter(this);
00085         }
00086     }
00087     if (!watched) {
00088         // use separate dock widgets instead of the old tab widget
00089         tabReportLabel->hide();
00090         AutoloadTabCombo->hide();
00091     }
00092 }
00093 
00097 DlgGeneralImp::~DlgGeneralImp()
00098 {
00099     // no need to delete child widgets, Qt does it all for us
00100     if (watched)
00101         watched->removeEventFilter(this);
00102 }
00103 
00108 void DlgGeneralImp::setRecentFileSize()
00109 {
00110     RecentFilesAction *recent = getMainWindow()->findChild<RecentFilesAction *>(QLatin1String("recentFiles"));
00111     if (recent) {
00112         ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentFiles");
00113         recent->resizeList(hGrp->GetInt("RecentFiles", 4));
00114     }
00115 }
00116 
00117 void DlgGeneralImp::saveSettings()
00118 {
00119     int index = AutoloadModuleCombo->currentIndex();
00120     QVariant data = AutoloadModuleCombo->itemData(index);
00121     QString startWbName = data.toString();
00122     App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
00123                           SetASCII("AutoloadModule", startWbName.toAscii());
00124     
00125     AutoloadTabCombo->onSave();
00126     RecentFiles->onSave();
00127     SplashScreen->onSave();
00128 
00129     // set new user defined style
00130     (void)QApplication::setStyle(WindowStyle->currentText());
00131 
00132     setRecentFileSize();
00133     ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
00134     QString lang = QLocale::languageToString(QLocale::system().language());
00135     QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toAscii()).c_str();
00136     QByteArray current = Languages->itemData(Languages->currentIndex()).toByteArray();
00137     if (current != language)
00138     {
00139         hGrp->SetASCII("Language", current.constData());
00140         Translator::instance()->activateLanguage(current.constData());
00141     }
00142 
00143     QVariant size = this->toolbarIconSize->itemData(this->toolbarIconSize->currentIndex());
00144     int pixel = size.toInt();
00145     hGrp->SetInt("ToolbarIconSize", pixel);
00146     getMainWindow()->setIconSize(QSize(pixel,pixel));
00147 }
00148 
00149 void DlgGeneralImp::loadSettings()
00150 {
00151     std::string start = App::Application::Config()["StartWorkbench"];
00152     start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
00153                                   GetASCII("AutoloadModule", start.c_str());
00154     QString startWbName = QLatin1String(start.c_str());
00155     AutoloadModuleCombo->setCurrentIndex(AutoloadModuleCombo->findData(startWbName));
00156 
00157     AutoloadTabCombo->onRestore();
00158     RecentFiles->onRestore();
00159     SplashScreen->onRestore();
00160 
00161     // fill up styles
00162     //
00163     QStringList styles = QStyleFactory::keys();
00164     WindowStyle->addItems(styles);
00165     QString style = QApplication::style()->objectName().toLower();
00166     int i=0;
00167     for (QStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it, i++) {
00168         if (style == (*it).toLower()) {
00169             WindowStyle->setCurrentIndex( i );
00170             break;
00171         }
00172     }
00173 
00174     // search for the language files
00175     ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
00176     QString lang = QLocale::languageToString(QLocale::system().language());
00177     QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toAscii()).c_str();
00178     Languages->addItem(Gui::Translator::tr("English"), QByteArray("English"));
00179     int index = 1;
00180     TStringList list = Translator::instance()->supportedLanguages();
00181     for (TStringList::iterator it = list.begin(); it != list.end(); ++it, index++) {
00182         QByteArray lang = it->c_str();
00183         Languages->addItem(Gui::Translator::tr(lang.constData()), lang);
00184         if (language == lang) {
00185             Languages->setCurrentIndex(index);
00186         }
00187     }
00188 
00189     int size = QApplication::style()->pixelMetric(QStyle::PM_ToolBarIconSize);
00190     int current = getMainWindow()->iconSize().width();
00191     this->toolbarIconSize->addItem(tr("Default (%1 x %1)").arg(size), QVariant((int)size));
00192     this->toolbarIconSize->addItem(tr("Small (%1 x %1)").arg(16), QVariant((int)16));
00193     this->toolbarIconSize->addItem(tr("Large (%1 x %1)").arg(32), QVariant((int)32));
00194     this->toolbarIconSize->addItem(tr("Extra large (%1 x %1)").arg(48), QVariant((int)48));
00195     index = this->toolbarIconSize->findData(QVariant(current));
00196     if (index > -1) this->toolbarIconSize->setCurrentIndex(index);
00197 }
00198 
00199 void DlgGeneralImp::changeEvent(QEvent *e)
00200 {
00201     if (e->type() == QEvent::LanguageChange) {
00202         retranslateUi(this);
00203         for (int i = 0; i < Languages->count(); i++) {
00204             QByteArray lang = Languages->itemData(i).toByteArray();
00205             Languages->setItemText(i, Gui::Translator::tr(lang.constData()));
00206         }
00207     } else {
00208         QWidget::changeEvent(e);
00209     }
00210 }
00211 
00212 bool DlgGeneralImp::eventFilter(QObject* o, QEvent* e)
00213 {
00214     // make sure that report tabs have been translated
00215     if (o == watched && e->type() == QEvent::LanguageChange) {
00216         for (int i=0; i<watched->count(); i++)
00217             AutoloadTabCombo->setItemText( i, watched->tabText(i) );
00218     }
00219 
00220     return QWidget::eventFilter(o, e);
00221 }
00222 
00223 #include "moc_DlgGeneralImp.cpp"

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