1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "encttscfggui.h"
23 #include "browsedirtree.h"
25 EncTtsCfgGui::EncTtsCfgGui(QDialog
* parent
,EncTtsSettingInterface
* interface
,QString name
) : QDialog(parent
)
27 m_settingInterface
= interface
;
30 // create a busy Dialog
31 m_busyDlg
= new QProgressDialog(tr(""), tr(""), 0, 0,this);
32 m_busyDlg
->setWindowTitle(tr("Waiting for engine..."));
33 m_busyDlg
->setModal(true);
34 m_busyDlg
->setLabel(0);
35 m_busyDlg
->setCancelButton(0);
37 connect(interface
,SIGNAL(busy()),this,SLOT(showBusy()));
38 connect(interface
,SIGNAL(busyEnd()),this,SLOT(hideBusy()));
45 void EncTtsCfgGui::setUpWindow()
47 m_settingsList
= m_settingInterface
->getSettings();
50 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
53 QGroupBox
*groupBox
= new QGroupBox(this);
54 QFormLayout
*formlayout
= new QFormLayout
;
56 for(int i
= 0; i
< m_settingsList
.size(); i
++)
58 formlayout
->addRow(m_settingsList
.at(i
)->name(),createWidgets(m_settingsList
.at(i
)));
60 groupBox
->setLayout(formlayout
);
61 mainLayout
->addWidget(groupBox
);
64 connect(&m_browseBtnMap
,SIGNAL(mapped(QObject
*)),this,SLOT(browse(QObject
*)));
66 // ok - cancel buttons
67 QPushButton
* okBtn
= new QPushButton(tr("Ok"),this);
68 okBtn
->setDefault(true);
69 okBtn
->setIcon(QIcon(":icons/go-next.png"));
70 QPushButton
* cancelBtn
= new QPushButton(tr("Cancel"),this);
71 cancelBtn
->setIcon(QIcon(":icons/process-stop.png"));
72 connect(okBtn
,SIGNAL(clicked()),this,SLOT(accept()));
73 connect(cancelBtn
,SIGNAL(clicked()),this,SLOT(reject()));
75 QHBoxLayout
*btnbox
= new QHBoxLayout
;
76 btnbox
->addWidget(okBtn
);
77 btnbox
->addWidget(cancelBtn
);
78 btnbox
->insertStretch(0,1);
80 mainLayout
->addLayout(btnbox
);
82 this->setLayout(mainLayout
);
85 QLayout
* EncTtsCfgGui::createWidgets(EncTtsSetting
* setting
)
88 QWidget
* value
= NULL
;
89 switch(setting
->type())
91 case EncTtsSetting::eDOUBLE
:
93 QDoubleSpinBox
*spinBox
= new QDoubleSpinBox(this);
94 spinBox
->setAccessibleName(setting
->name());
95 spinBox
->setMinimum(setting
->min().toDouble());
96 spinBox
->setMaximum(setting
->max().toDouble());
97 spinBox
->setSingleStep(0.01);
98 spinBox
->setValue(setting
->current().toDouble());
99 connect(spinBox
,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
103 case EncTtsSetting::eINT
:
105 QSpinBox
*spinBox
= new QSpinBox(this);
106 spinBox
->setAccessibleName(setting
->name());
107 spinBox
->setMinimum(setting
->min().toInt());
108 spinBox
->setMaximum(setting
->max().toInt());
109 spinBox
->setValue(setting
->current().toInt());
110 connect(spinBox
,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
114 case EncTtsSetting::eSTRING
:
116 QLineEdit
*lineEdit
= new QLineEdit(this);
117 lineEdit
->setAccessibleName(setting
->name());
118 lineEdit
->setText(setting
->current().toString());
119 connect(lineEdit
,SIGNAL(textChanged(QString
)),this,SLOT(updateSetting()));
123 case EncTtsSetting::eREADONLYSTRING
:
125 value
= new QLabel(setting
->current().toString(),this);
128 case EncTtsSetting::eSTRINGLIST
:
130 QComboBox
*comboBox
= new QComboBox(this);
131 comboBox
->setAccessibleName(setting
->name());
132 comboBox
->addItems(setting
->list());
133 int index
= comboBox
->findText(setting
->current().toString());
134 comboBox
->setCurrentIndex(index
);
135 connect(comboBox
,SIGNAL(currentIndexChanged(QString
)),this,SLOT(updateSetting()));
139 case EncTtsSetting::eBOOL
:
141 QCheckBox
*checkbox
= new QCheckBox(this);
142 checkbox
->setAccessibleName(setting
->name());
143 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
144 connect(checkbox
,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
150 qDebug() << "Warning: unknown EncTTsSetting type" << setting
->type();
158 m_settingsWidgetsMap
.insert(setting
,value
);
159 connect(setting
,SIGNAL(updateGui()),this,SLOT(updateWidget()));
163 QWidget
* btn
= createButton(setting
);
166 QHBoxLayout
*hbox
= new QHBoxLayout
;
167 if(value
!= NULL
)hbox
->addWidget(value
);
168 if(btn
!= NULL
) hbox
->addWidget(btn
);
174 QWidget
* EncTtsCfgGui::createButton(EncTtsSetting
* setting
)
176 if(setting
->button() == EncTtsSetting::eBROWSEBTN
)
178 QPushButton
* browsebtn
= new QPushButton(tr("Browse"),this);
179 browsebtn
->setFixedWidth(50); //all buttons the same size, or it looks ugly
180 m_browseBtnMap
.setMapping(browsebtn
,setting
);
181 connect(browsebtn
,SIGNAL(clicked()),&m_browseBtnMap
,SLOT(map()));
184 else if(setting
->button() == EncTtsSetting::eREFRESHBTN
)
186 QPushButton
* refreshbtn
= new QPushButton(tr("Refresh"),this);
187 refreshbtn
->setFixedWidth(50); //all buttons the same size, or it looks ugly
188 connect(refreshbtn
,SIGNAL(clicked()),setting
,SIGNAL(refresh()));
195 void EncTtsCfgGui::updateSetting()
197 //cast and get the sender widget
198 QWidget
* widget
= qobject_cast
<QWidget
*>(QObject::sender());
199 if(widget
== NULL
) return;
200 // get the corresponding setting
201 EncTtsSetting
* setting
= m_settingsWidgetsMap
.key(widget
);
203 // update widget based on setting type
204 switch(setting
->type())
206 case EncTtsSetting::eDOUBLE
:
208 setting
->setCurrent(((QDoubleSpinBox
*)widget
)->value(),false);
211 case EncTtsSetting::eINT
:
213 setting
->setCurrent(((QSpinBox
*)widget
)->value(),false);
216 case EncTtsSetting::eSTRING
:
218 setting
->setCurrent(((QLineEdit
*)widget
)->text(),false);
221 case EncTtsSetting::eREADONLYSTRING
:
223 setting
->setCurrent(((QLabel
*)widget
)->text(),false);
226 case EncTtsSetting::eSTRINGLIST
:
228 setting
->setCurrent(((QComboBox
*)widget
)->currentText(),false);
231 case EncTtsSetting::eBOOL
:
233 setting
->setCurrent(((QCheckBox
*)widget
)->isChecked(),false);
237 qDebug() << "unknown Settingtype !!";
243 void EncTtsCfgGui::updateWidget()
245 // get sender setting
246 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(QObject::sender());
247 if(setting
== NULL
) return;
248 // get corresponding widget
249 QWidget
* widget
= m_settingsWidgetsMap
.value(setting
);
251 // update Widget based on setting type
252 switch(setting
->type())
254 case EncTtsSetting::eDOUBLE
:
256 QDoubleSpinBox
* spinbox
= (QDoubleSpinBox
*) widget
;
257 spinbox
->setMinimum(setting
->min().toDouble());
258 spinbox
->setMaximum(setting
->max().toDouble());
259 spinbox
->blockSignals(true);
260 spinbox
->setValue(setting
->current().toDouble());
261 spinbox
->blockSignals(false);
264 case EncTtsSetting::eINT
:
266 QSpinBox
* spinbox
= (QSpinBox
*) widget
;
267 spinbox
->setMinimum(setting
->min().toInt());
268 spinbox
->setMaximum(setting
->max().toInt());
269 spinbox
->blockSignals(true);
270 spinbox
->setValue(setting
->current().toInt());
271 spinbox
->blockSignals(false);
274 case EncTtsSetting::eSTRING
:
276 QLineEdit
* lineedit
= (QLineEdit
*) widget
;
278 lineedit
->blockSignals(true);
279 lineedit
->setText(setting
->current().toString());
280 lineedit
->blockSignals(false);
283 case EncTtsSetting::eREADONLYSTRING
:
285 QLabel
* label
= (QLabel
*) widget
;
287 label
->blockSignals(true);
288 label
->setText(setting
->current().toString());
289 label
->blockSignals(false);
292 case EncTtsSetting::eSTRINGLIST
:
294 QComboBox
* combobox
= (QComboBox
*) widget
;
296 combobox
->blockSignals(true);
298 combobox
->addItems(setting
->list());
299 int index
= combobox
->findText(setting
->current().toString());
300 combobox
->setCurrentIndex(index
);
301 combobox
->blockSignals(false);
305 case EncTtsSetting::eBOOL
:
307 QCheckBox
* checkbox
= (QCheckBox
*) widget
;
309 checkbox
->blockSignals(true);
310 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
311 checkbox
->blockSignals(false);
316 qDebug() << "unknown EncTTsSetting";
322 void EncTtsCfgGui::showBusy()
324 if(m_busyCnt
== 0) m_busyDlg
->show();
329 void EncTtsCfgGui::hideBusy()
333 if(m_busyCnt
== 0) m_busyDlg
->hide();
337 void EncTtsCfgGui::accept(void)
339 m_settingInterface
->saveSettings();
343 void EncTtsCfgGui::reject(void)
348 //! takes a QObject because of QsignalMapper
349 void EncTtsCfgGui::browse(QObject
* settingObj
)
352 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(settingObj
);
353 if(setting
== NULL
) return;
356 QString curPath
= setting
->current().toString();
358 QString exe
= QFileDialog::getOpenFileName(this, tr("Select excutable"), curPath
, "*");
359 if(!QFileInfo(exe
).isExecutable())
361 // set new value, gui will update automatically
362 setting
->setCurrent(exe
);