summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/rbutilqt/encttscfggui.cpp256
-rw-r--r--utils/rbutilqt/encttscfggui.h10
2 files changed, 91 insertions, 175 deletions
diff --git a/utils/rbutilqt/encttscfggui.cpp b/utils/rbutilqt/encttscfggui.cpp
index 51a047da61..cd2cf24f5b 100644
--- a/utils/rbutilqt/encttscfggui.cpp
+++ b/utils/rbutilqt/encttscfggui.cpp
@@ -35,11 +35,10 @@
35#include "Logger.h" 35#include "Logger.h"
36 36
37EncTtsCfgGui::EncTtsCfgGui(QDialog* parent, EncTtsSettingInterface* iface, QString name) 37EncTtsCfgGui::EncTtsCfgGui(QDialog* parent, EncTtsSettingInterface* iface, QString name)
38 : QDialog(parent) 38 : QDialog(parent),
39 m_settingInterface(iface),
40 m_busyCnt(0)
39{ 41{
40 m_settingInterface = iface;
41
42 m_busyCnt=0;
43 // create a busy Dialog 42 // create a busy Dialog
44 m_busyDlg= new QProgressDialog("", "", 0, 0,this); 43 m_busyDlg= new QProgressDialog("", "", 0, 0,this);
45 m_busyDlg->setWindowTitle(tr("Waiting for engine...")); 44 m_busyDlg->setWindowTitle(tr("Waiting for engine..."));
@@ -47,8 +46,8 @@ EncTtsCfgGui::EncTtsCfgGui(QDialog* parent, EncTtsSettingInterface* iface, QStri
47 m_busyDlg->setLabel(nullptr); 46 m_busyDlg->setLabel(nullptr);
48 m_busyDlg->setCancelButton(nullptr); 47 m_busyDlg->setCancelButton(nullptr);
49 m_busyDlg->hide(); 48 m_busyDlg->hide();
50 connect(iface,&EncTtsSettingInterface::busy,this,&EncTtsCfgGui::showBusy); 49 connect(iface, &EncTtsSettingInterface::busy, this, &EncTtsCfgGui::showBusy);
51 connect(iface,&EncTtsSettingInterface::busyEnd,this,&EncTtsCfgGui::hideBusy); 50 connect(iface, &EncTtsSettingInterface::busyEnd, this, &EncTtsCfgGui::hideBusy);
52 51
53 //setup the window 52 //setup the window
54 setWindowTitle(name); 53 setWindowTitle(name);
@@ -88,17 +87,14 @@ void EncTtsCfgGui::setUpWindow()
88 groupBox->setLayout(gridLayout); 87 groupBox->setLayout(gridLayout);
89 mainLayout->addWidget(groupBox); 88 mainLayout->addWidget(groupBox);
90 89
91 // connect browse btn
92 connect(&m_browseBtnMap,SIGNAL(mapped(QObject*)),this,SLOT(browse(QObject*)));
93
94 // ok - cancel buttons 90 // ok - cancel buttons
95 QPushButton* okBtn = new QPushButton(tr("Ok"),this); 91 QPushButton* okBtn = new QPushButton(tr("Ok"),this);
96 okBtn->setDefault(true); 92 okBtn->setDefault(true);
97 okBtn->setIcon(QIcon(":icons/go-next.svg")); 93 okBtn->setIcon(QIcon(":icons/go-next.svg"));
98 QPushButton* cancelBtn = new QPushButton(tr("Cancel"),this); 94 QPushButton* cancelBtn = new QPushButton(tr("Cancel"),this);
99 cancelBtn->setIcon(QIcon(":icons/process-stop.svg")); 95 cancelBtn->setIcon(QIcon(":icons/process-stop.svg"));
100 connect(okBtn,SIGNAL(clicked()),this,SLOT(accept())); 96 connect(okBtn, &QPushButton::clicked, this, &EncTtsCfgGui::accept);
101 connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject())); 97 connect(cancelBtn, &QPushButton::clicked, this, &EncTtsCfgGui::reject);
102 98
103 QHBoxLayout *btnbox = new QHBoxLayout; 99 QHBoxLayout *btnbox = new QHBoxLayout;
104 btnbox->addWidget(okBtn); 100 btnbox->addWidget(okBtn);
@@ -124,8 +120,21 @@ QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
124 spinBox->setMaximum(setting->max().toDouble()); 120 spinBox->setMaximum(setting->max().toDouble());
125 spinBox->setSingleStep(0.01); 121 spinBox->setSingleStep(0.01);
126 spinBox->setValue(setting->current().toDouble()); 122 spinBox->setValue(setting->current().toDouble());
127 connect(spinBox,SIGNAL(valueChanged(double)),this,SLOT(updateSetting())); 123
128 value = spinBox; 124 value = spinBox;
125
126 connect(spinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
127 this, [=](double value) {
128 this->m_settingsWidgetsMap.key(spinBox)->setCurrent(value, false);
129 });
130 connect(setting, &EncTtsSetting::updateGui, this,
131 [spinBox, setting]() {
132 spinBox->setMinimum(setting->min().toDouble());
133 spinBox->setMaximum(setting->max().toDouble());
134 spinBox->blockSignals(true);
135 spinBox->setValue(setting->current().toDouble());
136 spinBox->blockSignals(false);
137 });
129 break; 138 break;
130 } 139 }
131 case EncTtsSetting::eINT: 140 case EncTtsSetting::eINT:
@@ -135,8 +144,19 @@ QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
135 spinBox->setMinimum(setting->min().toInt()); 144 spinBox->setMinimum(setting->min().toInt());
136 spinBox->setMaximum(setting->max().toInt()); 145 spinBox->setMaximum(setting->max().toInt());
137 spinBox->setValue(setting->current().toInt()); 146 spinBox->setValue(setting->current().toInt());
138 connect(spinBox,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
139 value = spinBox; 147 value = spinBox;
148 connect(spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
149 this, [=](int value) {
150 this->m_settingsWidgetsMap.key(spinBox)->setCurrent(value, false);
151 });
152 connect(setting, &EncTtsSetting::updateGui, this,
153 [spinBox, setting]() {
154 spinBox->setMinimum(setting->min().toInt());
155 spinBox->setMaximum(setting->max().toInt());
156 spinBox->blockSignals(true);
157 spinBox->setValue(setting->current().toInt());
158 spinBox->blockSignals(false);
159 });
140 break; 160 break;
141 } 161 }
142 case EncTtsSetting::eSTRING: 162 case EncTtsSetting::eSTRING:
@@ -144,13 +164,31 @@ QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
144 QLineEdit *lineEdit = new QLineEdit(this); 164 QLineEdit *lineEdit = new QLineEdit(this);
145 lineEdit->setAccessibleName(setting->name()); 165 lineEdit->setAccessibleName(setting->name());
146 lineEdit->setText(setting->current().toString()); 166 lineEdit->setText(setting->current().toString());
147 connect(lineEdit,&QLineEdit::textChanged,this,&EncTtsCfgGui::updateSetting);
148 value = lineEdit; 167 value = lineEdit;
168
169 connect(lineEdit, &QLineEdit::textChanged,
170 this, [=](QString value) {
171 this->m_settingsWidgetsMap.key(lineEdit)->setCurrent(value, false);
172 });
173 connect(setting, &EncTtsSetting::updateGui, this,
174 [lineEdit, setting]() {
175 lineEdit->blockSignals(true);
176 lineEdit->setText(setting->current().toString());
177 lineEdit->blockSignals(false);
178 });
149 break; 179 break;
150 } 180 }
151 case EncTtsSetting::eREADONLYSTRING: 181 case EncTtsSetting::eREADONLYSTRING:
152 { 182 {
153 value = new QLabel(setting->current().toString(),this); 183 QLabel *label = new QLabel(setting->current().toString(), this);
184 label->setWordWrap(true);
185 value = label;
186 connect(setting, &EncTtsSetting::updateGui, this,
187 [label, setting]() {
188 label->blockSignals(true);
189 label->setText(setting->current().toString());
190 label->blockSignals(false);
191 });
154 break; 192 break;
155 } 193 }
156 case EncTtsSetting::eSTRINGLIST: 194 case EncTtsSetting::eSTRINGLIST:
@@ -160,17 +198,40 @@ QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
160 comboBox->addItems(setting->list()); 198 comboBox->addItems(setting->list());
161 int index = comboBox->findText(setting->current().toString()); 199 int index = comboBox->findText(setting->current().toString());
162 comboBox->setCurrentIndex(index); 200 comboBox->setCurrentIndex(index);
163 connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateSetting())); 201 connect(comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
202 this, [=](int) {
203 this->m_settingsWidgetsMap.key(comboBox)->setCurrent(comboBox->currentText(), false);
204 });
164 value = comboBox; 205 value = comboBox;
206 connect(setting, &EncTtsSetting::updateGui, this,
207 [comboBox, setting]() {
208 comboBox->blockSignals(true);
209 comboBox->clear();
210 comboBox->addItems(setting->list());
211 comboBox->setCurrentIndex(comboBox->findText(setting->current().toString()));
212 comboBox->blockSignals(false);
213 });
214
165 break; 215 break;
166 } 216 }
167 case EncTtsSetting::eBOOL: 217 case EncTtsSetting::eBOOL:
168 { 218 {
169 QCheckBox *checkbox = new QCheckBox(this); 219 QCheckBox *checkbox = new QCheckBox(this);
170 checkbox->setAccessibleName(setting->name()); 220 checkbox->setAccessibleName(setting->name());
171 checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked); 221 checkbox->setCheckState(setting->current().toBool() == true
172 connect(checkbox,&QCheckBox::stateChanged,this,&EncTtsCfgGui::updateSetting); 222 ? Qt::Checked : Qt::Unchecked);
223 connect(checkbox, &QCheckBox::stateChanged,
224 this, [=](int value) {
225 this->m_settingsWidgetsMap.key(checkbox)->setCurrent(value, false);
226 });
173 value = checkbox; 227 value = checkbox;
228 connect(setting, &EncTtsSetting::updateGui, this,
229 [checkbox, setting]() {
230 checkbox->blockSignals(true);
231 checkbox->setCheckState(setting->current().toBool() == true
232 ? Qt::Checked : Qt::Unchecked);
233 checkbox->blockSignals(false);
234 });
174 break; 235 break;
175 } 236 }
176 default: 237 default:
@@ -183,8 +244,7 @@ QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
183 // remember widget 244 // remember widget
184 if(value != nullptr) 245 if(value != nullptr)
185 { 246 {
186 m_settingsWidgetsMap.insert(setting,value); 247 m_settingsWidgetsMap.insert(setting, value);
187 connect(setting,&EncTtsSetting::updateGui,this,&EncTtsCfgGui::updateWidget);
188 } 248 }
189 249
190 return value; 250 return value;
@@ -196,148 +256,28 @@ QWidget* EncTtsCfgGui::createButton(EncTtsSetting* setting)
196 { 256 {
197 QPushButton* browsebtn = new QPushButton(tr("Browse"),this); 257 QPushButton* browsebtn = new QPushButton(tr("Browse"),this);
198 browsebtn->setIcon(QIcon(":/icons/system-search.svg")); 258 browsebtn->setIcon(QIcon(":/icons/system-search.svg"));
199 m_browseBtnMap.setMapping(browsebtn,setting); 259
200 connect(browsebtn,SIGNAL(clicked()),&m_browseBtnMap,SLOT(map())); 260 connect(browsebtn, &QPushButton::clicked, this,
261 [this, setting]()
262 {
263 QString exe = QFileDialog::getOpenFileName(this, tr("Select executable"),
264 setting->current().toString(), "*");
265 if(QFileInfo(exe).isExecutable())
266 setting->setCurrent(exe);
267 });
201 return browsebtn; 268 return browsebtn;
202 } 269 }
203 else if(setting->button() == EncTtsSetting::eREFRESHBTN) 270 else if(setting->button() == EncTtsSetting::eREFRESHBTN)
204 { 271 {
205 QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this); 272 QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this);
206 refreshbtn->setIcon(QIcon(":/icons/view-refresh.svg")); 273 refreshbtn->setIcon(QIcon(":/icons/view-refresh.svg"));
207 connect(refreshbtn,&QAbstractButton::clicked,setting,&EncTtsSetting::refresh); 274 connect(refreshbtn, &QAbstractButton::clicked, setting, &EncTtsSetting::refresh);
208 return refreshbtn; 275 return refreshbtn;
209 } 276 }
210 else 277 else
211 return nullptr; 278 return nullptr;
212} 279}
213 280
214void EncTtsCfgGui::updateSetting()
215{
216 //cast and get the sender widget
217 QWidget* widget = qobject_cast<QWidget*>(QObject::sender());
218 if(widget == nullptr) return;
219 // get the corresponding setting
220 EncTtsSetting* setting = m_settingsWidgetsMap.key(widget);
221
222 // update widget based on setting type
223 switch(setting->type())
224 {
225 case EncTtsSetting::eDOUBLE:
226 {
227 setting->setCurrent(((QDoubleSpinBox*)widget)->value(),false);
228 break;
229 }
230 case EncTtsSetting::eINT:
231 {
232 setting->setCurrent(((QSpinBox*)widget)->value(),false);
233 break;
234 }
235 case EncTtsSetting::eSTRING:
236 {
237 setting->setCurrent(((QLineEdit*)widget)->text(),false);
238 break;
239 }
240 case EncTtsSetting::eREADONLYSTRING:
241 {
242 setting->setCurrent(((QLabel*)widget)->text(),false);
243 break;
244 }
245 case EncTtsSetting::eSTRINGLIST:
246 {
247 setting->setCurrent(((QComboBox*)widget)->currentText(),false);
248 break;
249 }
250 case EncTtsSetting::eBOOL:
251 {
252 setting->setCurrent(((QCheckBox*)widget)->isChecked(),false);
253 break;
254 }
255 default:
256 {
257 LOG_WARNING() << "unknown setting type!";
258 break;
259 }
260 }
261}
262
263void EncTtsCfgGui::updateWidget()
264{
265 // get sender setting
266 EncTtsSetting* setting = qobject_cast<EncTtsSetting*>(QObject::sender());
267 if(setting == nullptr) return;
268 // get corresponding widget
269 QWidget* widget = m_settingsWidgetsMap.value(setting);
270
271 // update Widget based on setting type
272 switch(setting->type())
273 {
274 case EncTtsSetting::eDOUBLE:
275 {
276 QDoubleSpinBox* spinbox = (QDoubleSpinBox*) widget;
277 spinbox->setMinimum(setting->min().toDouble());
278 spinbox->setMaximum(setting->max().toDouble());
279 spinbox->blockSignals(true);
280 spinbox->setValue(setting->current().toDouble());
281 spinbox->blockSignals(false);
282 break;
283 }
284 case EncTtsSetting::eINT:
285 {
286 QSpinBox* spinbox = (QSpinBox*) widget;
287 spinbox->setMinimum(setting->min().toInt());
288 spinbox->setMaximum(setting->max().toInt());
289 spinbox->blockSignals(true);
290 spinbox->setValue(setting->current().toInt());
291 spinbox->blockSignals(false);
292 break;
293 }
294 case EncTtsSetting::eSTRING:
295 {
296 QLineEdit* lineedit = (QLineEdit*) widget;
297
298 lineedit->blockSignals(true);
299 lineedit->setText(setting->current().toString());
300 lineedit->blockSignals(false);
301 break;
302 }
303 case EncTtsSetting::eREADONLYSTRING:
304 {
305 QLabel* label = (QLabel*) widget;
306
307 label->blockSignals(true);
308 label->setText(setting->current().toString());
309 label->blockSignals(false);
310 break;
311 }
312 case EncTtsSetting::eSTRINGLIST:
313 {
314 QComboBox* combobox = (QComboBox*) widget;
315
316 combobox->blockSignals(true);
317 combobox->clear();
318 combobox->addItems(setting->list());
319 int index = combobox->findText(setting->current().toString());
320 combobox->setCurrentIndex(index);
321 combobox->blockSignals(false);
322
323 break;
324 }
325 case EncTtsSetting::eBOOL:
326 {
327 QCheckBox* checkbox = (QCheckBox*) widget;
328
329 checkbox->blockSignals(true);
330 checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
331 checkbox->blockSignals(false);
332 break;
333 }
334 default:
335 {
336 LOG_WARNING() << "unknown EncTTsSetting";
337 break;
338 }
339 }
340}
341 281
342void EncTtsCfgGui::showBusy() 282void EncTtsCfgGui::showBusy()
343{ 283{
@@ -365,20 +305,4 @@ void EncTtsCfgGui::reject(void)
365 this->done(0); 305 this->done(0);
366} 306}
367 307
368//! takes a QObject because of QsignalMapper
369void EncTtsCfgGui::browse(QObject* settingObj)
370{
371 // cast top setting
372 EncTtsSetting* setting= qobject_cast<EncTtsSetting*>(settingObj);
373 if(setting == nullptr) return;
374
375 //current path
376 QString curPath = setting->current().toString();
377 // show file dialog
378 QString exe = QFileDialog::getOpenFileName(this, tr("Select executable"), curPath, "*");
379 if(!QFileInfo(exe).isExecutable())
380 return;
381 // set new value, gui will update automatically
382 setting->setCurrent(exe);
383}
384 308
diff --git a/utils/rbutilqt/encttscfggui.h b/utils/rbutilqt/encttscfggui.h
index 80af86dabc..bf9f08a384 100644
--- a/utils/rbutilqt/encttscfggui.h
+++ b/utils/rbutilqt/encttscfggui.h
@@ -40,16 +40,10 @@ private slots:
40 void accept(void); 40 void accept(void);
41 //! close window and dont save configuration 41 //! close window and dont save configuration
42 void reject(void); 42 void reject(void);
43 //! updates the corresponding setting from the sending Widget
44 void updateSetting();
45 //! updates corresponding Widget from the sending Setting.
46 void updateWidget();
47 //! shows a busy dialog. counts calls. 43 //! shows a busy dialog. counts calls.
48 void showBusy(); 44 void showBusy();
49 //! hides the busy dialog, counts calls 45 //! hides the busy dialog, counts calls
50 void hideBusy(); 46 void hideBusy();
51 //! used via the SignalMapper for all Browse buttons
52 void browse(QObject*);
53 47
54private: 48private:
55 //! creates all dynamic window content 49 //! creates all dynamic window content
@@ -67,9 +61,7 @@ private:
67 //! List of settings from the TTS or Encoder 61 //! List of settings from the TTS or Encoder
68 QList<EncTtsSetting*> m_settingsList; 62 QList<EncTtsSetting*> m_settingsList;
69 //! Maps settings and the correspondig Widget 63 //! Maps settings and the correspondig Widget
70 QMap<EncTtsSetting*,QWidget*> m_settingsWidgetsMap; 64 QMap<EncTtsSetting*, QWidget*> m_settingsWidgetsMap;
71 //! Maps all browse buttons to the corresponding Setting
72 QSignalMapper m_browseBtnMap;
73 //! counter how often busyShow() is called, 65 //! counter how often busyShow() is called,
74 int m_busyCnt; 66 int m_busyCnt;
75}; 67};