2009-06-09 21:49:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
|
|
|
* $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-01-27 11:01:56 +00:00
|
|
|
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QProgressDialog>
|
2009-06-09 21:49:34 +00:00
|
|
|
#include "encttscfggui.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2009-06-09 21:49:34 +00:00
|
|
|
|
2013-04-03 21:36:13 +00:00
|
|
|
EncTtsCfgGui::EncTtsCfgGui(QDialog* parent, EncTtsSettingInterface* iface, QString name)
|
|
|
|
: QDialog(parent)
|
2009-06-09 21:49:34 +00:00
|
|
|
{
|
2013-04-03 21:36:13 +00:00
|
|
|
m_settingInterface = iface;
|
|
|
|
|
|
|
|
m_busyCnt=0;
|
2009-06-09 21:49:34 +00:00
|
|
|
// create a busy Dialog
|
2009-09-25 15:51:17 +00:00
|
|
|
m_busyDlg= new QProgressDialog("", "", 0, 0,this);
|
2009-06-09 21:49:34 +00:00
|
|
|
m_busyDlg->setWindowTitle(tr("Waiting for engine..."));
|
|
|
|
m_busyDlg->setModal(true);
|
2020-11-19 19:36:57 +00:00
|
|
|
m_busyDlg->setLabel(nullptr);
|
|
|
|
m_busyDlg->setCancelButton(nullptr);
|
2009-06-09 21:49:34 +00:00
|
|
|
m_busyDlg->hide();
|
2013-04-03 21:36:13 +00:00
|
|
|
connect(iface,SIGNAL(busy()),this,SLOT(showBusy()));
|
|
|
|
connect(iface,SIGNAL(busyEnd()),this,SLOT(hideBusy()));
|
2009-06-09 21:49:34 +00:00
|
|
|
|
|
|
|
//setup the window
|
|
|
|
setWindowTitle(name);
|
|
|
|
setUpWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::setUpWindow()
|
|
|
|
{
|
|
|
|
m_settingsList = m_settingInterface->getSettings();
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-10-10 16:52:36 +00:00
|
|
|
// layout
|
2009-06-09 21:49:34 +00:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-10-10 16:52:36 +00:00
|
|
|
// groupbox
|
2009-06-09 21:49:34 +00:00
|
|
|
QGroupBox *groupBox = new QGroupBox(this);
|
2009-10-10 16:52:36 +00:00
|
|
|
QGridLayout *gridLayout = new QGridLayout(groupBox);
|
2009-06-09 21:49:34 +00:00
|
|
|
// setting widgets
|
|
|
|
for(int i = 0; i < m_settingsList.size(); i++)
|
|
|
|
{
|
2009-10-10 16:52:36 +00:00
|
|
|
QLabel *label = new QLabel(m_settingsList.at(i)->name());
|
|
|
|
gridLayout->addWidget(label, i, 0);
|
|
|
|
QWidget *widget = createWidgets(m_settingsList.at(i));
|
|
|
|
gridLayout->addWidget(widget, i, 1);
|
2010-01-03 20:04:45 +00:00
|
|
|
widget->setLayoutDirection(Qt::LeftToRight);
|
2009-10-10 16:52:36 +00:00
|
|
|
QWidget *btn = createButton(m_settingsList.at(i));
|
2020-11-19 19:36:57 +00:00
|
|
|
if(btn != nullptr)
|
2009-10-10 16:52:36 +00:00
|
|
|
{
|
|
|
|
gridLayout->addWidget(btn, i, 2);
|
|
|
|
}
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
2009-10-10 16:52:36 +00:00
|
|
|
// add hidden spacers to make the dialog scale properly
|
|
|
|
QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
|
gridLayout->addItem(spacer, m_settingsList.size(), 0);
|
|
|
|
spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
gridLayout->addItem(spacer, m_settingsList.size(), 1);
|
|
|
|
|
|
|
|
groupBox->setLayout(gridLayout);
|
2009-06-09 21:49:34 +00:00
|
|
|
mainLayout->addWidget(groupBox);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
// connect browse btn
|
|
|
|
connect(&m_browseBtnMap,SIGNAL(mapped(QObject*)),this,SLOT(browse(QObject*)));
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
// ok - cancel buttons
|
|
|
|
QPushButton* okBtn = new QPushButton(tr("Ok"),this);
|
|
|
|
okBtn->setDefault(true);
|
2020-09-27 10:37:28 +00:00
|
|
|
okBtn->setIcon(QIcon(":icons/go-next.svg"));
|
2009-06-09 21:49:34 +00:00
|
|
|
QPushButton* cancelBtn = new QPushButton(tr("Cancel"),this);
|
2020-09-27 10:37:28 +00:00
|
|
|
cancelBtn->setIcon(QIcon(":icons/process-stop.svg"));
|
2009-06-09 21:49:34 +00:00
|
|
|
connect(okBtn,SIGNAL(clicked()),this,SLOT(accept()));
|
|
|
|
connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject()));
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
QHBoxLayout *btnbox = new QHBoxLayout;
|
|
|
|
btnbox->addWidget(okBtn);
|
|
|
|
btnbox->addWidget(cancelBtn);
|
|
|
|
btnbox->insertStretch(0,1);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
mainLayout->addLayout(btnbox);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
this->setLayout(mainLayout);
|
|
|
|
}
|
|
|
|
|
2009-10-10 16:52:36 +00:00
|
|
|
QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
|
2009-06-09 21:49:34 +00:00
|
|
|
{
|
|
|
|
// value display
|
2020-11-19 19:36:57 +00:00
|
|
|
QWidget* value = nullptr;
|
2009-06-09 21:49:34 +00:00
|
|
|
switch(setting->type())
|
|
|
|
{
|
|
|
|
case EncTtsSetting::eDOUBLE:
|
|
|
|
{
|
|
|
|
QDoubleSpinBox *spinBox = new QDoubleSpinBox(this);
|
2009-06-15 19:41:16 +00:00
|
|
|
spinBox->setAccessibleName(setting->name());
|
2009-06-09 21:49:34 +00:00
|
|
|
spinBox->setMinimum(setting->min().toDouble());
|
|
|
|
spinBox->setMaximum(setting->max().toDouble());
|
|
|
|
spinBox->setSingleStep(0.01);
|
|
|
|
spinBox->setValue(setting->current().toDouble());
|
|
|
|
connect(spinBox,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
|
|
|
|
value = spinBox;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eINT:
|
|
|
|
{
|
|
|
|
QSpinBox *spinBox = new QSpinBox(this);
|
2009-06-15 19:41:16 +00:00
|
|
|
spinBox->setAccessibleName(setting->name());
|
2009-06-09 21:49:34 +00:00
|
|
|
spinBox->setMinimum(setting->min().toInt());
|
|
|
|
spinBox->setMaximum(setting->max().toInt());
|
|
|
|
spinBox->setValue(setting->current().toInt());
|
|
|
|
connect(spinBox,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
|
|
|
|
value = spinBox;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRING:
|
|
|
|
{
|
|
|
|
QLineEdit *lineEdit = new QLineEdit(this);
|
2009-06-15 19:41:16 +00:00
|
|
|
lineEdit->setAccessibleName(setting->name());
|
2009-06-09 21:49:34 +00:00
|
|
|
lineEdit->setText(setting->current().toString());
|
|
|
|
connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(updateSetting()));
|
|
|
|
value = lineEdit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eREADONLYSTRING:
|
|
|
|
{
|
|
|
|
value = new QLabel(setting->current().toString(),this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRINGLIST:
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = new QComboBox(this);
|
2009-06-15 19:41:16 +00:00
|
|
|
comboBox->setAccessibleName(setting->name());
|
2009-06-09 21:49:34 +00:00
|
|
|
comboBox->addItems(setting->list());
|
|
|
|
int index = comboBox->findText(setting->current().toString());
|
|
|
|
comboBox->setCurrentIndex(index);
|
|
|
|
connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateSetting()));
|
|
|
|
value = comboBox;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eBOOL:
|
|
|
|
{
|
|
|
|
QCheckBox *checkbox = new QCheckBox(this);
|
2009-06-15 19:41:16 +00:00
|
|
|
checkbox->setAccessibleName(setting->name());
|
2009-06-09 21:49:34 +00:00
|
|
|
checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
|
|
|
|
connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
|
|
|
|
value = checkbox;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_WARNING() << "Warning: unknown EncTTsSetting type" << setting->type();
|
2009-06-09 21:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-10-10 16:52:36 +00:00
|
|
|
// remember widget
|
2020-11-19 19:36:57 +00:00
|
|
|
if(value != nullptr)
|
2013-04-03 21:36:13 +00:00
|
|
|
{
|
2009-06-09 21:49:34 +00:00
|
|
|
m_settingsWidgetsMap.insert(setting,value);
|
|
|
|
connect(setting,SIGNAL(updateGui()),this,SLOT(updateWidget()));
|
|
|
|
}
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-10-10 16:52:36 +00:00
|
|
|
return value;
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* EncTtsCfgGui::createButton(EncTtsSetting* setting)
|
|
|
|
{
|
|
|
|
if(setting->button() == EncTtsSetting::eBROWSEBTN)
|
|
|
|
{
|
|
|
|
QPushButton* browsebtn = new QPushButton(tr("Browse"),this);
|
2020-09-27 10:37:28 +00:00
|
|
|
browsebtn->setIcon(QIcon(":/icons/system-search.svg"));
|
2009-06-09 21:49:34 +00:00
|
|
|
m_browseBtnMap.setMapping(browsebtn,setting);
|
|
|
|
connect(browsebtn,SIGNAL(clicked()),&m_browseBtnMap,SLOT(map()));
|
|
|
|
return browsebtn;
|
|
|
|
}
|
|
|
|
else if(setting->button() == EncTtsSetting::eREFRESHBTN)
|
|
|
|
{
|
|
|
|
QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this);
|
2020-09-27 10:37:28 +00:00
|
|
|
refreshbtn->setIcon(QIcon(":/icons/view-refresh.svg"));
|
2009-06-09 21:49:34 +00:00
|
|
|
connect(refreshbtn,SIGNAL(clicked()),setting,SIGNAL(refresh()));
|
|
|
|
return refreshbtn;
|
|
|
|
}
|
|
|
|
else
|
2020-11-19 19:36:57 +00:00
|
|
|
return nullptr;
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::updateSetting()
|
|
|
|
{
|
|
|
|
//cast and get the sender widget
|
|
|
|
QWidget* widget = qobject_cast<QWidget*>(QObject::sender());
|
2020-11-19 19:36:57 +00:00
|
|
|
if(widget == nullptr) return;
|
2009-06-09 21:49:34 +00:00
|
|
|
// get the corresponding setting
|
|
|
|
EncTtsSetting* setting = m_settingsWidgetsMap.key(widget);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
|
|
|
// update widget based on setting type
|
2009-06-09 21:49:34 +00:00
|
|
|
switch(setting->type())
|
|
|
|
{
|
|
|
|
case EncTtsSetting::eDOUBLE:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QDoubleSpinBox*)widget)->value(),false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eINT:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QSpinBox*)widget)->value(),false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRING:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QLineEdit*)widget)->text(),false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eREADONLYSTRING:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QLabel*)widget)->text(),false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRINGLIST:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QComboBox*)widget)->currentText(),false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eBOOL:
|
|
|
|
{
|
|
|
|
setting->setCurrent(((QCheckBox*)widget)->isChecked(),false);
|
2020-08-20 16:54:23 +00:00
|
|
|
break;
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_WARNING() << "unknown setting type!";
|
2009-06-09 21:49:34 +00:00
|
|
|
break;
|
2013-04-03 21:36:13 +00:00
|
|
|
}
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::updateWidget()
|
|
|
|
{
|
|
|
|
// get sender setting
|
|
|
|
EncTtsSetting* setting = qobject_cast<EncTtsSetting*>(QObject::sender());
|
2020-11-19 19:36:57 +00:00
|
|
|
if(setting == nullptr) return;
|
2009-06-09 21:49:34 +00:00
|
|
|
// get corresponding widget
|
|
|
|
QWidget* widget = m_settingsWidgetsMap.value(setting);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
// update Widget based on setting type
|
|
|
|
switch(setting->type())
|
|
|
|
{
|
|
|
|
case EncTtsSetting::eDOUBLE:
|
|
|
|
{
|
|
|
|
QDoubleSpinBox* spinbox = (QDoubleSpinBox*) widget;
|
|
|
|
spinbox->setMinimum(setting->min().toDouble());
|
|
|
|
spinbox->setMaximum(setting->max().toDouble());
|
|
|
|
spinbox->blockSignals(true);
|
|
|
|
spinbox->setValue(setting->current().toDouble());
|
|
|
|
spinbox->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eINT:
|
|
|
|
{
|
|
|
|
QSpinBox* spinbox = (QSpinBox*) widget;
|
|
|
|
spinbox->setMinimum(setting->min().toInt());
|
|
|
|
spinbox->setMaximum(setting->max().toInt());
|
|
|
|
spinbox->blockSignals(true);
|
|
|
|
spinbox->setValue(setting->current().toInt());
|
|
|
|
spinbox->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRING:
|
|
|
|
{
|
|
|
|
QLineEdit* lineedit = (QLineEdit*) widget;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
lineedit->blockSignals(true);
|
|
|
|
lineedit->setText(setting->current().toString());
|
|
|
|
lineedit->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eREADONLYSTRING:
|
|
|
|
{
|
|
|
|
QLabel* label = (QLabel*) widget;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
label->blockSignals(true);
|
|
|
|
label->setText(setting->current().toString());
|
|
|
|
label->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eSTRINGLIST:
|
|
|
|
{
|
|
|
|
QComboBox* combobox = (QComboBox*) widget;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
combobox->blockSignals(true);
|
|
|
|
combobox->clear();
|
|
|
|
combobox->addItems(setting->list());
|
|
|
|
int index = combobox->findText(setting->current().toString());
|
|
|
|
combobox->setCurrentIndex(index);
|
|
|
|
combobox->blockSignals(false);
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EncTtsSetting::eBOOL:
|
|
|
|
{
|
|
|
|
QCheckBox* checkbox = (QCheckBox*) widget;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
checkbox->blockSignals(true);
|
|
|
|
checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
|
|
|
|
checkbox->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_WARNING() << "unknown EncTTsSetting";
|
2009-06-09 21:49:34 +00:00
|
|
|
break;
|
2013-04-03 21:36:13 +00:00
|
|
|
}
|
2009-06-09 21:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::showBusy()
|
|
|
|
{
|
|
|
|
if(m_busyCnt == 0) m_busyDlg->show();
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
m_busyCnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::hideBusy()
|
|
|
|
{
|
|
|
|
m_busyCnt--;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
if(m_busyCnt == 0) m_busyDlg->hide();
|
|
|
|
}
|
2013-04-03 21:36:13 +00:00
|
|
|
|
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
void EncTtsCfgGui::accept(void)
|
|
|
|
{
|
|
|
|
m_settingInterface->saveSettings();
|
|
|
|
this->done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncTtsCfgGui::reject(void)
|
|
|
|
{
|
|
|
|
this->done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! takes a QObject because of QsignalMapper
|
|
|
|
void EncTtsCfgGui::browse(QObject* settingObj)
|
|
|
|
{
|
|
|
|
// cast top setting
|
|
|
|
EncTtsSetting* setting= qobject_cast<EncTtsSetting*>(settingObj);
|
2020-11-19 19:36:57 +00:00
|
|
|
if(setting == nullptr) return;
|
2013-04-03 21:36:13 +00:00
|
|
|
|
2009-06-09 21:49:34 +00:00
|
|
|
//current path
|
|
|
|
QString curPath = setting->current().toString();
|
|
|
|
// show file dialog
|
2010-11-27 23:18:13 +00:00
|
|
|
QString exe = QFileDialog::getOpenFileName(this, tr("Select executable"), curPath, "*");
|
2009-06-09 21:49:34 +00:00
|
|
|
if(!QFileInfo(exe).isExecutable())
|
|
|
|
return;
|
|
|
|
// set new value, gui will update automatically
|
|
|
|
setting->setCurrent(exe);
|
|
|
|
}
|
|
|
|
|