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
->setMinimum(setting
->min().toDouble());
95 spinBox
->setMaximum(setting
->max().toDouble());
96 spinBox
->setSingleStep(0.01);
97 spinBox
->setValue(setting
->current().toDouble());
98 connect(spinBox
,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
102 case EncTtsSetting::eINT
:
104 QSpinBox
*spinBox
= new QSpinBox(this);
105 spinBox
->setMinimum(setting
->min().toInt());
106 spinBox
->setMaximum(setting
->max().toInt());
107 spinBox
->setValue(setting
->current().toInt());
108 connect(spinBox
,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
112 case EncTtsSetting::eSTRING
:
114 QLineEdit
*lineEdit
= new QLineEdit(this);
115 lineEdit
->setText(setting
->current().toString());
116 connect(lineEdit
,SIGNAL(textChanged(QString
)),this,SLOT(updateSetting()));
120 case EncTtsSetting::eREADONLYSTRING
:
122 value
= new QLabel(setting
->current().toString(),this);
125 case EncTtsSetting::eSTRINGLIST
:
127 QComboBox
*comboBox
= new QComboBox(this);
128 comboBox
->addItems(setting
->list());
129 int index
= comboBox
->findText(setting
->current().toString());
130 comboBox
->setCurrentIndex(index
);
131 connect(comboBox
,SIGNAL(currentIndexChanged(QString
)),this,SLOT(updateSetting()));
135 case EncTtsSetting::eBOOL
:
137 QCheckBox
*checkbox
= new QCheckBox(this);
138 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
139 connect(checkbox
,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
145 qDebug() << "Warning: unknown EncTTsSetting type" << setting
->type();
153 m_settingsWidgetsMap
.insert(setting
,value
);
154 connect(setting
,SIGNAL(updateGui()),this,SLOT(updateWidget()));
158 QWidget
* btn
= createButton(setting
);
161 QHBoxLayout
*hbox
= new QHBoxLayout
;
162 if(value
!= NULL
)hbox
->addWidget(value
);
163 if(btn
!= NULL
) hbox
->addWidget(btn
);
169 QWidget
* EncTtsCfgGui::createButton(EncTtsSetting
* setting
)
171 if(setting
->button() == EncTtsSetting::eBROWSEBTN
)
173 QPushButton
* browsebtn
= new QPushButton(tr("Browse"),this);
174 browsebtn
->setFixedWidth(50); //all buttons the same size, or it looks ugly
175 m_browseBtnMap
.setMapping(browsebtn
,setting
);
176 connect(browsebtn
,SIGNAL(clicked()),&m_browseBtnMap
,SLOT(map()));
179 else if(setting
->button() == EncTtsSetting::eREFRESHBTN
)
181 QPushButton
* refreshbtn
= new QPushButton(tr("Refresh"),this);
182 refreshbtn
->setFixedWidth(50); //all buttons the same size, or it looks ugly
183 connect(refreshbtn
,SIGNAL(clicked()),setting
,SIGNAL(refresh()));
190 void EncTtsCfgGui::updateSetting()
192 //cast and get the sender widget
193 QWidget
* widget
= qobject_cast
<QWidget
*>(QObject::sender());
194 if(widget
== NULL
) return;
195 // get the corresponding setting
196 EncTtsSetting
* setting
= m_settingsWidgetsMap
.key(widget
);
198 // update widget based on setting type
199 switch(setting
->type())
201 case EncTtsSetting::eDOUBLE
:
203 setting
->setCurrent(((QDoubleSpinBox
*)widget
)->value(),false);
206 case EncTtsSetting::eINT
:
208 setting
->setCurrent(((QSpinBox
*)widget
)->value(),false);
211 case EncTtsSetting::eSTRING
:
213 setting
->setCurrent(((QLineEdit
*)widget
)->text(),false);
216 case EncTtsSetting::eREADONLYSTRING
:
218 setting
->setCurrent(((QLabel
*)widget
)->text(),false);
221 case EncTtsSetting::eSTRINGLIST
:
223 setting
->setCurrent(((QComboBox
*)widget
)->currentText(),false);
226 case EncTtsSetting::eBOOL
:
228 setting
->setCurrent(((QCheckBox
*)widget
)->isChecked(),false);
232 qDebug() << "unknown Settingtype !!";
238 void EncTtsCfgGui::updateWidget()
240 // get sender setting
241 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(QObject::sender());
242 if(setting
== NULL
) return;
243 // get corresponding widget
244 QWidget
* widget
= m_settingsWidgetsMap
.value(setting
);
246 // update Widget based on setting type
247 switch(setting
->type())
249 case EncTtsSetting::eDOUBLE
:
251 QDoubleSpinBox
* spinbox
= (QDoubleSpinBox
*) widget
;
252 spinbox
->setMinimum(setting
->min().toDouble());
253 spinbox
->setMaximum(setting
->max().toDouble());
254 spinbox
->blockSignals(true);
255 spinbox
->setValue(setting
->current().toDouble());
256 spinbox
->blockSignals(false);
259 case EncTtsSetting::eINT
:
261 QSpinBox
* spinbox
= (QSpinBox
*) widget
;
262 spinbox
->setMinimum(setting
->min().toInt());
263 spinbox
->setMaximum(setting
->max().toInt());
264 spinbox
->blockSignals(true);
265 spinbox
->setValue(setting
->current().toInt());
266 spinbox
->blockSignals(false);
269 case EncTtsSetting::eSTRING
:
271 QLineEdit
* lineedit
= (QLineEdit
*) widget
;
273 lineedit
->blockSignals(true);
274 lineedit
->setText(setting
->current().toString());
275 lineedit
->blockSignals(false);
278 case EncTtsSetting::eREADONLYSTRING
:
280 QLabel
* label
= (QLabel
*) widget
;
282 label
->blockSignals(true);
283 label
->setText(setting
->current().toString());
284 label
->blockSignals(false);
287 case EncTtsSetting::eSTRINGLIST
:
289 QComboBox
* combobox
= (QComboBox
*) widget
;
291 combobox
->blockSignals(true);
293 combobox
->addItems(setting
->list());
294 int index
= combobox
->findText(setting
->current().toString());
295 combobox
->setCurrentIndex(index
);
296 combobox
->blockSignals(false);
300 case EncTtsSetting::eBOOL
:
302 QCheckBox
* checkbox
= (QCheckBox
*) widget
;
304 checkbox
->blockSignals(true);
305 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
306 checkbox
->blockSignals(false);
311 qDebug() << "unknown EncTTsSetting";
317 void EncTtsCfgGui::showBusy()
319 if(m_busyCnt
== 0) m_busyDlg
->show();
324 void EncTtsCfgGui::hideBusy()
328 if(m_busyCnt
== 0) m_busyDlg
->hide();
332 void EncTtsCfgGui::accept(void)
334 m_settingInterface
->saveSettings();
338 void EncTtsCfgGui::reject(void)
343 //! takes a QObject because of QsignalMapper
344 void EncTtsCfgGui::browse(QObject
* settingObj
)
347 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(settingObj
);
348 if(setting
== NULL
) return;
351 QString curPath
= setting
->current().toString();
353 QString exe
= QFileDialog::getOpenFileName(this, tr("Select excutable"), curPath
, "*");
354 if(!QFileInfo(exe
).isExecutable())
356 // set new value, gui will update automatically
357 setting
->setCurrent(exe
);