update dict
[QFreeRecite.git] / src / gui / SettingWidget.cpp
blobc13d7d1e7ac85ec2b83932bf07efaeb0d0acf61d
1 #include <QSettings>
2 #include <QFileDialog>
3 #include <QVariant>
4 #include <FCore.h>
6 #include "SettingWidget.h"
8 SettingWidget::SettingWidget(QWidget *parent)
9 : QWidget(parent)
11 setupUi(this);
12 QSettings settings("QFreeRecite");
13 if(settings.value("SoundEffectOpen").toBool())
14 soundRButton->setDown(true);
15 else
16 soundRButton->setDown(false);
17 gPathBox->insertItem(0,settings.value("GlobalPath").toString());
18 gPathBox->setCurrentIndex(0);
19 hPathBox->insertItem(0,settings.value("HomePath").toString());
20 hPathBox->setCurrentIndex(0);
21 pPathBox->insertItem(0,settings.value("PronouncePath").toString());
22 pPathBox->setCurrentIndex(0);
23 fontBox->setCurrentFont(settings.value("FontFamily").toString());
24 boldCheckBox->setDown(settings.value("FontBold").toBool());
25 italicCheckBox->setDown(settings.value("FontItalic").toBool());
26 if(settings.contains("FontSize"))
27 fontSizeSpinBox->setValue(settings.value("FontSize").toInt());
28 connect(gPathBox,SIGNAL(activated(int)),
29 this,SLOT(setPathBox(int)));
30 connect(hPathBox,SIGNAL(activated(int)),
31 this,SLOT(setPathBox(int)));
32 connect(pPathBox,SIGNAL(activated(int)),
33 this,SLOT(setPathBox(int)));
34 connect(okButton,SIGNAL(clicked()),this,SLOT(okPressed()));
35 connect(cancelButton,SIGNAL(clicked()),this,SIGNAL(finished()));
38 SettingWidget::~SettingWidget()
40 D_OUTPUT("~SettingWidget()")
43 void SettingWidget::okPressed() {
44 QSettings settings("QFreeRecite");
45 settings.setValue("HomePath",hPathBox->currentText());
46 settings.setValue("GlobalPath",gPathBox->currentText());
47 settings.setValue("PronouncePath",pPathBox->currentText());
48 settings.setValue("SoundEffectOpen",soundRButton->isChecked());
49 settings.setValue("FontFamily",fontBox->currentFont().family());
50 settings.setValue("FontSize",fontSizeSpinBox->value());
51 settings.setValue("FontBold",boldCheckBox->isChecked());
52 settings.setValue("FontItalic",italicCheckBox->isChecked());
54 freeRecite::configHolder
55 .load( settings.value("HomePath").toString().toStdString().c_str(),
56 settings.value("GlobalPath").toString().toStdString().c_str(),
57 settings.value("PronouncePath").toString().toStdString().c_str() );
58 freeRecite::manager.load();
59 freeRecite::dictionary.load();
60 emit finished();
63 void SettingWidget::setPathBox(int index) {
64 QComboBox *comboBox = qobject_cast<QComboBox *>(sender());
65 if( comboBox == 0 || index != comboBox->count() -1)
66 return;
67 #ifdef WIN32
68 QString dir =
69 QDir::toNativeSeparators(
70 QFileDialog::getExistingDirectory(this,tr("Setting Directory")) + "/"
72 #else
73 QString dir = QFileDialog::getExistingDirectory(this,tr("Setting Directory"));
74 #endif
75 if(!dir.isEmpty())
76 comboBox->insertItem(0,dir);
77 comboBox->setCurrentIndex(0);