DlgGeneralImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00042
00050 DlgGeneralImp::DlgGeneralImp( QWidget* parent )
00051 : PreferencePage( parent ), watched(0)
00052 {
00053 this->setupUi(this);
00054
00055 windowStyleLabel->hide();
00056 WindowStyle->hide();
00057
00058
00059
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
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
00089 tabReportLabel->hide();
00090 AutoloadTabCombo->hide();
00091 }
00092 }
00093
00097 DlgGeneralImp::~DlgGeneralImp()
00098 {
00099
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
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
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
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
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"