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("", "", 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 QGridLayout
*gridLayout
= new QGridLayout(groupBox
);
56 for(int i
= 0; i
< m_settingsList
.size(); i
++)
58 QLabel
*label
= new QLabel(m_settingsList
.at(i
)->name());
59 gridLayout
->addWidget(label
, i
, 0);
60 QWidget
*widget
= createWidgets(m_settingsList
.at(i
));
61 gridLayout
->addWidget(widget
, i
, 1);
62 widget
->setLayoutDirection(Qt::LeftToRight
);
63 QWidget
*btn
= createButton(m_settingsList
.at(i
));
66 gridLayout
->addWidget(btn
, i
, 2);
69 // add hidden spacers to make the dialog scale properly
70 QSpacerItem
* spacer
= new QSpacerItem(0, 0, QSizePolicy::Minimum
, QSizePolicy::Expanding
);
71 gridLayout
->addItem(spacer
, m_settingsList
.size(), 0);
72 spacer
= new QSpacerItem(0, 0, QSizePolicy::Expanding
, QSizePolicy::Minimum
);
73 gridLayout
->addItem(spacer
, m_settingsList
.size(), 1);
75 groupBox
->setLayout(gridLayout
);
76 mainLayout
->addWidget(groupBox
);
79 connect(&m_browseBtnMap
,SIGNAL(mapped(QObject
*)),this,SLOT(browse(QObject
*)));
81 // ok - cancel buttons
82 QPushButton
* okBtn
= new QPushButton(tr("Ok"),this);
83 okBtn
->setDefault(true);
84 okBtn
->setIcon(QIcon(":icons/go-next.png"));
85 QPushButton
* cancelBtn
= new QPushButton(tr("Cancel"),this);
86 cancelBtn
->setIcon(QIcon(":icons/process-stop.png"));
87 connect(okBtn
,SIGNAL(clicked()),this,SLOT(accept()));
88 connect(cancelBtn
,SIGNAL(clicked()),this,SLOT(reject()));
90 QHBoxLayout
*btnbox
= new QHBoxLayout
;
91 btnbox
->addWidget(okBtn
);
92 btnbox
->addWidget(cancelBtn
);
93 btnbox
->insertStretch(0,1);
95 mainLayout
->addLayout(btnbox
);
97 this->setLayout(mainLayout
);
100 QWidget
* EncTtsCfgGui::createWidgets(EncTtsSetting
* setting
)
103 QWidget
* value
= NULL
;
104 switch(setting
->type())
106 case EncTtsSetting::eDOUBLE
:
108 QDoubleSpinBox
*spinBox
= new QDoubleSpinBox(this);
109 spinBox
->setAccessibleName(setting
->name());
110 spinBox
->setMinimum(setting
->min().toDouble());
111 spinBox
->setMaximum(setting
->max().toDouble());
112 spinBox
->setSingleStep(0.01);
113 spinBox
->setValue(setting
->current().toDouble());
114 connect(spinBox
,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
118 case EncTtsSetting::eINT
:
120 QSpinBox
*spinBox
= new QSpinBox(this);
121 spinBox
->setAccessibleName(setting
->name());
122 spinBox
->setMinimum(setting
->min().toInt());
123 spinBox
->setMaximum(setting
->max().toInt());
124 spinBox
->setValue(setting
->current().toInt());
125 connect(spinBox
,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
129 case EncTtsSetting::eSTRING
:
131 QLineEdit
*lineEdit
= new QLineEdit(this);
132 lineEdit
->setAccessibleName(setting
->name());
133 lineEdit
->setText(setting
->current().toString());
134 connect(lineEdit
,SIGNAL(textChanged(QString
)),this,SLOT(updateSetting()));
138 case EncTtsSetting::eREADONLYSTRING
:
140 value
= new QLabel(setting
->current().toString(),this);
143 case EncTtsSetting::eSTRINGLIST
:
145 QComboBox
*comboBox
= new QComboBox(this);
146 comboBox
->setAccessibleName(setting
->name());
147 comboBox
->addItems(setting
->list());
148 int index
= comboBox
->findText(setting
->current().toString());
149 comboBox
->setCurrentIndex(index
);
150 connect(comboBox
,SIGNAL(currentIndexChanged(QString
)),this,SLOT(updateSetting()));
154 case EncTtsSetting::eBOOL
:
156 QCheckBox
*checkbox
= new QCheckBox(this);
157 checkbox
->setAccessibleName(setting
->name());
158 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
159 connect(checkbox
,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
165 qDebug() << "Warning: unknown EncTTsSetting type" << setting
->type();
173 m_settingsWidgetsMap
.insert(setting
,value
);
174 connect(setting
,SIGNAL(updateGui()),this,SLOT(updateWidget()));
180 QWidget
* EncTtsCfgGui::createButton(EncTtsSetting
* setting
)
182 if(setting
->button() == EncTtsSetting::eBROWSEBTN
)
184 QPushButton
* browsebtn
= new QPushButton(tr("Browse"),this);
185 browsebtn
->setIcon(QIcon(":/icons/system-search.png"));
186 m_browseBtnMap
.setMapping(browsebtn
,setting
);
187 connect(browsebtn
,SIGNAL(clicked()),&m_browseBtnMap
,SLOT(map()));
190 else if(setting
->button() == EncTtsSetting::eREFRESHBTN
)
192 QPushButton
* refreshbtn
= new QPushButton(tr("Refresh"),this);
193 refreshbtn
->setIcon(QIcon(":/icons/view-refresh.png"));
194 connect(refreshbtn
,SIGNAL(clicked()),setting
,SIGNAL(refresh()));
201 void EncTtsCfgGui::updateSetting()
203 //cast and get the sender widget
204 QWidget
* widget
= qobject_cast
<QWidget
*>(QObject::sender());
205 if(widget
== NULL
) return;
206 // get the corresponding setting
207 EncTtsSetting
* setting
= m_settingsWidgetsMap
.key(widget
);
209 // update widget based on setting type
210 switch(setting
->type())
212 case EncTtsSetting::eDOUBLE
:
214 setting
->setCurrent(((QDoubleSpinBox
*)widget
)->value(),false);
217 case EncTtsSetting::eINT
:
219 setting
->setCurrent(((QSpinBox
*)widget
)->value(),false);
222 case EncTtsSetting::eSTRING
:
224 setting
->setCurrent(((QLineEdit
*)widget
)->text(),false);
227 case EncTtsSetting::eREADONLYSTRING
:
229 setting
->setCurrent(((QLabel
*)widget
)->text(),false);
232 case EncTtsSetting::eSTRINGLIST
:
234 setting
->setCurrent(((QComboBox
*)widget
)->currentText(),false);
237 case EncTtsSetting::eBOOL
:
239 setting
->setCurrent(((QCheckBox
*)widget
)->isChecked(),false);
243 qDebug() << "unknown Settingtype !!";
249 void EncTtsCfgGui::updateWidget()
251 // get sender setting
252 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(QObject::sender());
253 if(setting
== NULL
) return;
254 // get corresponding widget
255 QWidget
* widget
= m_settingsWidgetsMap
.value(setting
);
257 // update Widget based on setting type
258 switch(setting
->type())
260 case EncTtsSetting::eDOUBLE
:
262 QDoubleSpinBox
* spinbox
= (QDoubleSpinBox
*) widget
;
263 spinbox
->setMinimum(setting
->min().toDouble());
264 spinbox
->setMaximum(setting
->max().toDouble());
265 spinbox
->blockSignals(true);
266 spinbox
->setValue(setting
->current().toDouble());
267 spinbox
->blockSignals(false);
270 case EncTtsSetting::eINT
:
272 QSpinBox
* spinbox
= (QSpinBox
*) widget
;
273 spinbox
->setMinimum(setting
->min().toInt());
274 spinbox
->setMaximum(setting
->max().toInt());
275 spinbox
->blockSignals(true);
276 spinbox
->setValue(setting
->current().toInt());
277 spinbox
->blockSignals(false);
280 case EncTtsSetting::eSTRING
:
282 QLineEdit
* lineedit
= (QLineEdit
*) widget
;
284 lineedit
->blockSignals(true);
285 lineedit
->setText(setting
->current().toString());
286 lineedit
->blockSignals(false);
289 case EncTtsSetting::eREADONLYSTRING
:
291 QLabel
* label
= (QLabel
*) widget
;
293 label
->blockSignals(true);
294 label
->setText(setting
->current().toString());
295 label
->blockSignals(false);
298 case EncTtsSetting::eSTRINGLIST
:
300 QComboBox
* combobox
= (QComboBox
*) widget
;
302 combobox
->blockSignals(true);
304 combobox
->addItems(setting
->list());
305 int index
= combobox
->findText(setting
->current().toString());
306 combobox
->setCurrentIndex(index
);
307 combobox
->blockSignals(false);
311 case EncTtsSetting::eBOOL
:
313 QCheckBox
* checkbox
= (QCheckBox
*) widget
;
315 checkbox
->blockSignals(true);
316 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
317 checkbox
->blockSignals(false);
322 qDebug() << "unknown EncTTsSetting";
328 void EncTtsCfgGui::showBusy()
330 if(m_busyCnt
== 0) m_busyDlg
->show();
335 void EncTtsCfgGui::hideBusy()
339 if(m_busyCnt
== 0) m_busyDlg
->hide();
343 void EncTtsCfgGui::accept(void)
345 m_settingInterface
->saveSettings();
349 void EncTtsCfgGui::reject(void)
354 //! takes a QObject because of QsignalMapper
355 void EncTtsCfgGui::browse(QObject
* settingObj
)
358 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(settingObj
);
359 if(setting
== NULL
) return;
362 QString curPath
= setting
->current().toString();
364 QString exe
= QFileDialog::getOpenFileName(this, tr("Select excutable"), curPath
, "*");
365 if(!QFileInfo(exe
).isExecutable())
367 // set new value, gui will update automatically
368 setting
->setCurrent(exe
);