diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-15 21:04:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-24 18:05:53 +0100 |
commit | c876d3bbefe0dc00c27ca0c12d29da5874946962 (patch) | |
tree | 69f468a185a369b01998314bc3ecc19b70f4fcaa /utils/rbutilqt/encttscfggui.cpp | |
parent | 6c6f0757d7a902feb293be165d1490c42bc8e7ad (diff) | |
download | rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.tar.gz rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.zip |
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be
considered part of utils too. Having it in a separate folder is an
arbitrary split that doesn't help anymore these days, so merge them.
This also allows other utils to easily use libtools.make without the
need to navigate to a different folder.
Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
Diffstat (limited to 'utils/rbutilqt/encttscfggui.cpp')
-rw-r--r-- | utils/rbutilqt/encttscfggui.cpp | 384 |
1 files changed, 384 insertions, 0 deletions
diff --git a/utils/rbutilqt/encttscfggui.cpp b/utils/rbutilqt/encttscfggui.cpp new file mode 100644 index 0000000000..19181c0f8b --- /dev/null +++ b/utils/rbutilqt/encttscfggui.cpp | |||
@@ -0,0 +1,384 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Wenger | ||
10 | * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <QSpacerItem> | ||
23 | #include <QPushButton> | ||
24 | #include <QHBoxLayout> | ||
25 | #include <QDoubleSpinBox> | ||
26 | #include <QSpinBox> | ||
27 | #include <QLineEdit> | ||
28 | #include <QFileDialog> | ||
29 | #include <QComboBox> | ||
30 | #include <QGroupBox> | ||
31 | #include <QLabel> | ||
32 | #include <QCheckBox> | ||
33 | #include <QProgressDialog> | ||
34 | #include "encttscfggui.h" | ||
35 | #include "Logger.h" | ||
36 | |||
37 | EncTtsCfgGui::EncTtsCfgGui(QDialog* parent, EncTtsSettingInterface* iface, QString name) | ||
38 | : QDialog(parent) | ||
39 | { | ||
40 | m_settingInterface = iface; | ||
41 | |||
42 | m_busyCnt=0; | ||
43 | // create a busy Dialog | ||
44 | m_busyDlg= new QProgressDialog("", "", 0, 0,this); | ||
45 | m_busyDlg->setWindowTitle(tr("Waiting for engine...")); | ||
46 | m_busyDlg->setModal(true); | ||
47 | m_busyDlg->setLabel(nullptr); | ||
48 | m_busyDlg->setCancelButton(nullptr); | ||
49 | m_busyDlg->hide(); | ||
50 | connect(iface,SIGNAL(busy()),this,SLOT(showBusy())); | ||
51 | connect(iface,SIGNAL(busyEnd()),this,SLOT(hideBusy())); | ||
52 | |||
53 | //setup the window | ||
54 | setWindowTitle(name); | ||
55 | setUpWindow(); | ||
56 | } | ||
57 | |||
58 | void EncTtsCfgGui::setUpWindow() | ||
59 | { | ||
60 | m_settingsList = m_settingInterface->getSettings(); | ||
61 | |||
62 | // layout | ||
63 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||
64 | |||
65 | // groupbox | ||
66 | QGroupBox *groupBox = new QGroupBox(this); | ||
67 | QGridLayout *gridLayout = new QGridLayout(groupBox); | ||
68 | // setting widgets | ||
69 | for(int i = 0; i < m_settingsList.size(); i++) | ||
70 | { | ||
71 | QLabel *label = new QLabel(m_settingsList.at(i)->name()); | ||
72 | gridLayout->addWidget(label, i, 0); | ||
73 | QWidget *widget = createWidgets(m_settingsList.at(i)); | ||
74 | gridLayout->addWidget(widget, i, 1); | ||
75 | widget->setLayoutDirection(Qt::LeftToRight); | ||
76 | QWidget *btn = createButton(m_settingsList.at(i)); | ||
77 | if(btn != nullptr) | ||
78 | { | ||
79 | gridLayout->addWidget(btn, i, 2); | ||
80 | } | ||
81 | } | ||
82 | // add hidden spacers to make the dialog scale properly | ||
83 | QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | ||
84 | gridLayout->addItem(spacer, m_settingsList.size(), 0); | ||
85 | spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | ||
86 | gridLayout->addItem(spacer, m_settingsList.size(), 1); | ||
87 | |||
88 | groupBox->setLayout(gridLayout); | ||
89 | mainLayout->addWidget(groupBox); | ||
90 | |||
91 | // connect browse btn | ||
92 | connect(&m_browseBtnMap,SIGNAL(mapped(QObject*)),this,SLOT(browse(QObject*))); | ||
93 | |||
94 | // ok - cancel buttons | ||
95 | QPushButton* okBtn = new QPushButton(tr("Ok"),this); | ||
96 | okBtn->setDefault(true); | ||
97 | okBtn->setIcon(QIcon(":icons/go-next.svg")); | ||
98 | QPushButton* cancelBtn = new QPushButton(tr("Cancel"),this); | ||
99 | cancelBtn->setIcon(QIcon(":icons/process-stop.svg")); | ||
100 | connect(okBtn,SIGNAL(clicked()),this,SLOT(accept())); | ||
101 | connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject())); | ||
102 | |||
103 | QHBoxLayout *btnbox = new QHBoxLayout; | ||
104 | btnbox->addWidget(okBtn); | ||
105 | btnbox->addWidget(cancelBtn); | ||
106 | btnbox->insertStretch(0,1); | ||
107 | |||
108 | mainLayout->addLayout(btnbox); | ||
109 | |||
110 | this->setLayout(mainLayout); | ||
111 | } | ||
112 | |||
113 | QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting) | ||
114 | { | ||
115 | // value display | ||
116 | QWidget* value = nullptr; | ||
117 | switch(setting->type()) | ||
118 | { | ||
119 | case EncTtsSetting::eDOUBLE: | ||
120 | { | ||
121 | QDoubleSpinBox *spinBox = new QDoubleSpinBox(this); | ||
122 | spinBox->setAccessibleName(setting->name()); | ||
123 | spinBox->setMinimum(setting->min().toDouble()); | ||
124 | spinBox->setMaximum(setting->max().toDouble()); | ||
125 | spinBox->setSingleStep(0.01); | ||
126 | spinBox->setValue(setting->current().toDouble()); | ||
127 | connect(spinBox,SIGNAL(valueChanged(double)),this,SLOT(updateSetting())); | ||
128 | value = spinBox; | ||
129 | break; | ||
130 | } | ||
131 | case EncTtsSetting::eINT: | ||
132 | { | ||
133 | QSpinBox *spinBox = new QSpinBox(this); | ||
134 | spinBox->setAccessibleName(setting->name()); | ||
135 | spinBox->setMinimum(setting->min().toInt()); | ||
136 | spinBox->setMaximum(setting->max().toInt()); | ||
137 | spinBox->setValue(setting->current().toInt()); | ||
138 | connect(spinBox,SIGNAL(valueChanged(int)),this,SLOT(updateSetting())); | ||
139 | value = spinBox; | ||
140 | break; | ||
141 | } | ||
142 | case EncTtsSetting::eSTRING: | ||
143 | { | ||
144 | QLineEdit *lineEdit = new QLineEdit(this); | ||
145 | lineEdit->setAccessibleName(setting->name()); | ||
146 | lineEdit->setText(setting->current().toString()); | ||
147 | connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(updateSetting())); | ||
148 | value = lineEdit; | ||
149 | break; | ||
150 | } | ||
151 | case EncTtsSetting::eREADONLYSTRING: | ||
152 | { | ||
153 | value = new QLabel(setting->current().toString(),this); | ||
154 | break; | ||
155 | } | ||
156 | case EncTtsSetting::eSTRINGLIST: | ||
157 | { | ||
158 | QComboBox *comboBox = new QComboBox(this); | ||
159 | comboBox->setAccessibleName(setting->name()); | ||
160 | comboBox->addItems(setting->list()); | ||
161 | int index = comboBox->findText(setting->current().toString()); | ||
162 | comboBox->setCurrentIndex(index); | ||
163 | connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateSetting())); | ||
164 | value = comboBox; | ||
165 | break; | ||
166 | } | ||
167 | case EncTtsSetting::eBOOL: | ||
168 | { | ||
169 | QCheckBox *checkbox = new QCheckBox(this); | ||
170 | checkbox->setAccessibleName(setting->name()); | ||
171 | checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked); | ||
172 | connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(updateSetting())); | ||
173 | value = checkbox; | ||
174 | break; | ||
175 | } | ||
176 | default: | ||
177 | { | ||
178 | LOG_WARNING() << "Warning: unknown EncTTsSetting type" << setting->type(); | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | // remember widget | ||
184 | if(value != nullptr) | ||
185 | { | ||
186 | m_settingsWidgetsMap.insert(setting,value); | ||
187 | connect(setting,SIGNAL(updateGui()),this,SLOT(updateWidget())); | ||
188 | } | ||
189 | |||
190 | return value; | ||
191 | } | ||
192 | |||
193 | QWidget* EncTtsCfgGui::createButton(EncTtsSetting* setting) | ||
194 | { | ||
195 | if(setting->button() == EncTtsSetting::eBROWSEBTN) | ||
196 | { | ||
197 | QPushButton* browsebtn = new QPushButton(tr("Browse"),this); | ||
198 | browsebtn->setIcon(QIcon(":/icons/system-search.svg")); | ||
199 | m_browseBtnMap.setMapping(browsebtn,setting); | ||
200 | connect(browsebtn,SIGNAL(clicked()),&m_browseBtnMap,SLOT(map())); | ||
201 | return browsebtn; | ||
202 | } | ||
203 | else if(setting->button() == EncTtsSetting::eREFRESHBTN) | ||
204 | { | ||
205 | QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this); | ||
206 | refreshbtn->setIcon(QIcon(":/icons/view-refresh.svg")); | ||
207 | connect(refreshbtn,SIGNAL(clicked()),setting,SIGNAL(refresh())); | ||
208 | return refreshbtn; | ||
209 | } | ||
210 | else | ||
211 | return nullptr; | ||
212 | } | ||
213 | |||
214 | void 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 | |||
263 | void 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 | |||
342 | void EncTtsCfgGui::showBusy() | ||
343 | { | ||
344 | if(m_busyCnt == 0) m_busyDlg->show(); | ||
345 | |||
346 | m_busyCnt++; | ||
347 | } | ||
348 | |||
349 | void EncTtsCfgGui::hideBusy() | ||
350 | { | ||
351 | m_busyCnt--; | ||
352 | |||
353 | if(m_busyCnt == 0) m_busyDlg->hide(); | ||
354 | } | ||
355 | |||
356 | |||
357 | void EncTtsCfgGui::accept(void) | ||
358 | { | ||
359 | m_settingInterface->saveSettings(); | ||
360 | this->done(0); | ||
361 | } | ||
362 | |||
363 | void EncTtsCfgGui::reject(void) | ||
364 | { | ||
365 | this->done(0); | ||
366 | } | ||
367 | |||
368 | //! takes a QObject because of QsignalMapper | ||
369 | void 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 | |||