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"
24 EncTtsCfgGui::EncTtsCfgGui(QDialog
* parent
,EncTtsSettingInterface
* interface
,QString name
) : QDialog(parent
)
26 m_settingInterface
= interface
;
29 // create a busy Dialog
30 m_busyDlg
= new QProgressDialog("", "", 0, 0,this);
31 m_busyDlg
->setWindowTitle(tr("Waiting for engine..."));
32 m_busyDlg
->setModal(true);
33 m_busyDlg
->setLabel(0);
34 m_busyDlg
->setCancelButton(0);
36 connect(interface
,SIGNAL(busy()),this,SLOT(showBusy()));
37 connect(interface
,SIGNAL(busyEnd()),this,SLOT(hideBusy()));
44 void EncTtsCfgGui::setUpWindow()
46 m_settingsList
= m_settingInterface
->getSettings();
49 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
52 QGroupBox
*groupBox
= new QGroupBox(this);
53 QGridLayout
*gridLayout
= new QGridLayout(groupBox
);
55 for(int i
= 0; i
< m_settingsList
.size(); i
++)
57 QLabel
*label
= new QLabel(m_settingsList
.at(i
)->name());
58 gridLayout
->addWidget(label
, i
, 0);
59 QWidget
*widget
= createWidgets(m_settingsList
.at(i
));
60 gridLayout
->addWidget(widget
, i
, 1);
61 widget
->setLayoutDirection(Qt::LeftToRight
);
62 QWidget
*btn
= createButton(m_settingsList
.at(i
));
65 gridLayout
->addWidget(btn
, i
, 2);
68 // add hidden spacers to make the dialog scale properly
69 QSpacerItem
* spacer
= new QSpacerItem(0, 0, QSizePolicy::Minimum
, QSizePolicy::Expanding
);
70 gridLayout
->addItem(spacer
, m_settingsList
.size(), 0);
71 spacer
= new QSpacerItem(0, 0, QSizePolicy::Expanding
, QSizePolicy::Minimum
);
72 gridLayout
->addItem(spacer
, m_settingsList
.size(), 1);
74 groupBox
->setLayout(gridLayout
);
75 mainLayout
->addWidget(groupBox
);
78 connect(&m_browseBtnMap
,SIGNAL(mapped(QObject
*)),this,SLOT(browse(QObject
*)));
80 // ok - cancel buttons
81 QPushButton
* okBtn
= new QPushButton(tr("Ok"),this);
82 okBtn
->setDefault(true);
83 okBtn
->setIcon(QIcon(":icons/go-next.png"));
84 QPushButton
* cancelBtn
= new QPushButton(tr("Cancel"),this);
85 cancelBtn
->setIcon(QIcon(":icons/process-stop.png"));
86 connect(okBtn
,SIGNAL(clicked()),this,SLOT(accept()));
87 connect(cancelBtn
,SIGNAL(clicked()),this,SLOT(reject()));
89 QHBoxLayout
*btnbox
= new QHBoxLayout
;
90 btnbox
->addWidget(okBtn
);
91 btnbox
->addWidget(cancelBtn
);
92 btnbox
->insertStretch(0,1);
94 mainLayout
->addLayout(btnbox
);
96 this->setLayout(mainLayout
);
99 QWidget
* EncTtsCfgGui::createWidgets(EncTtsSetting
* setting
)
102 QWidget
* value
= NULL
;
103 switch(setting
->type())
105 case EncTtsSetting::eDOUBLE
:
107 QDoubleSpinBox
*spinBox
= new QDoubleSpinBox(this);
108 spinBox
->setAccessibleName(setting
->name());
109 spinBox
->setMinimum(setting
->min().toDouble());
110 spinBox
->setMaximum(setting
->max().toDouble());
111 spinBox
->setSingleStep(0.01);
112 spinBox
->setValue(setting
->current().toDouble());
113 connect(spinBox
,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
117 case EncTtsSetting::eINT
:
119 QSpinBox
*spinBox
= new QSpinBox(this);
120 spinBox
->setAccessibleName(setting
->name());
121 spinBox
->setMinimum(setting
->min().toInt());
122 spinBox
->setMaximum(setting
->max().toInt());
123 spinBox
->setValue(setting
->current().toInt());
124 connect(spinBox
,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
128 case EncTtsSetting::eSTRING
:
130 QLineEdit
*lineEdit
= new QLineEdit(this);
131 lineEdit
->setAccessibleName(setting
->name());
132 lineEdit
->setText(setting
->current().toString());
133 connect(lineEdit
,SIGNAL(textChanged(QString
)),this,SLOT(updateSetting()));
137 case EncTtsSetting::eREADONLYSTRING
:
139 value
= new QLabel(setting
->current().toString(),this);
142 case EncTtsSetting::eSTRINGLIST
:
144 QComboBox
*comboBox
= new QComboBox(this);
145 comboBox
->setAccessibleName(setting
->name());
146 comboBox
->addItems(setting
->list());
147 int index
= comboBox
->findText(setting
->current().toString());
148 comboBox
->setCurrentIndex(index
);
149 connect(comboBox
,SIGNAL(currentIndexChanged(QString
)),this,SLOT(updateSetting()));
153 case EncTtsSetting::eBOOL
:
155 QCheckBox
*checkbox
= new QCheckBox(this);
156 checkbox
->setAccessibleName(setting
->name());
157 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
158 connect(checkbox
,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
164 qDebug() << "Warning: unknown EncTTsSetting type" << setting
->type();
172 m_settingsWidgetsMap
.insert(setting
,value
);
173 connect(setting
,SIGNAL(updateGui()),this,SLOT(updateWidget()));
179 QWidget
* EncTtsCfgGui::createButton(EncTtsSetting
* setting
)
181 if(setting
->button() == EncTtsSetting::eBROWSEBTN
)
183 QPushButton
* browsebtn
= new QPushButton(tr("Browse"),this);
184 browsebtn
->setIcon(QIcon(":/icons/system-search.png"));
185 m_browseBtnMap
.setMapping(browsebtn
,setting
);
186 connect(browsebtn
,SIGNAL(clicked()),&m_browseBtnMap
,SLOT(map()));
189 else if(setting
->button() == EncTtsSetting::eREFRESHBTN
)
191 QPushButton
* refreshbtn
= new QPushButton(tr("Refresh"),this);
192 refreshbtn
->setIcon(QIcon(":/icons/view-refresh.png"));
193 connect(refreshbtn
,SIGNAL(clicked()),setting
,SIGNAL(refresh()));
200 void EncTtsCfgGui::updateSetting()
202 //cast and get the sender widget
203 QWidget
* widget
= qobject_cast
<QWidget
*>(QObject::sender());
204 if(widget
== NULL
) return;
205 // get the corresponding setting
206 EncTtsSetting
* setting
= m_settingsWidgetsMap
.key(widget
);
208 // update widget based on setting type
209 switch(setting
->type())
211 case EncTtsSetting::eDOUBLE
:
213 setting
->setCurrent(((QDoubleSpinBox
*)widget
)->value(),false);
216 case EncTtsSetting::eINT
:
218 setting
->setCurrent(((QSpinBox
*)widget
)->value(),false);
221 case EncTtsSetting::eSTRING
:
223 setting
->setCurrent(((QLineEdit
*)widget
)->text(),false);
226 case EncTtsSetting::eREADONLYSTRING
:
228 setting
->setCurrent(((QLabel
*)widget
)->text(),false);
231 case EncTtsSetting::eSTRINGLIST
:
233 setting
->setCurrent(((QComboBox
*)widget
)->currentText(),false);
236 case EncTtsSetting::eBOOL
:
238 setting
->setCurrent(((QCheckBox
*)widget
)->isChecked(),false);
242 qDebug() << "unknown Settingtype !!";
248 void EncTtsCfgGui::updateWidget()
250 // get sender setting
251 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(QObject::sender());
252 if(setting
== NULL
) return;
253 // get corresponding widget
254 QWidget
* widget
= m_settingsWidgetsMap
.value(setting
);
256 // update Widget based on setting type
257 switch(setting
->type())
259 case EncTtsSetting::eDOUBLE
:
261 QDoubleSpinBox
* spinbox
= (QDoubleSpinBox
*) widget
;
262 spinbox
->setMinimum(setting
->min().toDouble());
263 spinbox
->setMaximum(setting
->max().toDouble());
264 spinbox
->blockSignals(true);
265 spinbox
->setValue(setting
->current().toDouble());
266 spinbox
->blockSignals(false);
269 case EncTtsSetting::eINT
:
271 QSpinBox
* spinbox
= (QSpinBox
*) widget
;
272 spinbox
->setMinimum(setting
->min().toInt());
273 spinbox
->setMaximum(setting
->max().toInt());
274 spinbox
->blockSignals(true);
275 spinbox
->setValue(setting
->current().toInt());
276 spinbox
->blockSignals(false);
279 case EncTtsSetting::eSTRING
:
281 QLineEdit
* lineedit
= (QLineEdit
*) widget
;
283 lineedit
->blockSignals(true);
284 lineedit
->setText(setting
->current().toString());
285 lineedit
->blockSignals(false);
288 case EncTtsSetting::eREADONLYSTRING
:
290 QLabel
* label
= (QLabel
*) widget
;
292 label
->blockSignals(true);
293 label
->setText(setting
->current().toString());
294 label
->blockSignals(false);
297 case EncTtsSetting::eSTRINGLIST
:
299 QComboBox
* combobox
= (QComboBox
*) widget
;
301 combobox
->blockSignals(true);
303 combobox
->addItems(setting
->list());
304 int index
= combobox
->findText(setting
->current().toString());
305 combobox
->setCurrentIndex(index
);
306 combobox
->blockSignals(false);
310 case EncTtsSetting::eBOOL
:
312 QCheckBox
* checkbox
= (QCheckBox
*) widget
;
314 checkbox
->blockSignals(true);
315 checkbox
->setCheckState(setting
->current().toBool() == true ? Qt::Checked
: Qt::Unchecked
);
316 checkbox
->blockSignals(false);
321 qDebug() << "unknown EncTTsSetting";
327 void EncTtsCfgGui::showBusy()
329 if(m_busyCnt
== 0) m_busyDlg
->show();
334 void EncTtsCfgGui::hideBusy()
338 if(m_busyCnt
== 0) m_busyDlg
->hide();
342 void EncTtsCfgGui::accept(void)
344 m_settingInterface
->saveSettings();
348 void EncTtsCfgGui::reject(void)
353 //! takes a QObject because of QsignalMapper
354 void EncTtsCfgGui::browse(QObject
* settingObj
)
357 EncTtsSetting
* setting
= qobject_cast
<EncTtsSetting
*>(settingObj
);
358 if(setting
== NULL
) return;
361 QString curPath
= setting
->current().toString();
363 QString exe
= QFileDialog::getOpenFileName(this, tr("Select executable"), curPath
, "*");
364 if(!QFileInfo(exe
).isExecutable())
366 // set new value, gui will update automatically
367 setting
->setCurrent(exe
);