Example #1
0
QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
{
    // value display
    QWidget* value = NULL;
    switch(setting->type())
    {
        case EncTtsSetting::eDOUBLE:
        {
            QDoubleSpinBox *spinBox = new QDoubleSpinBox(this);
            spinBox->setAccessibleName(setting->name());
            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);
            spinBox->setAccessibleName(setting->name());
            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);
            lineEdit->setAccessibleName(setting->name());
            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);
            comboBox->setAccessibleName(setting->name());
            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);
            checkbox->setAccessibleName(setting->name());
            checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
            connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
            value = checkbox;
            break;
        }
        default:
        {
            LOG_WARNING() << "Warning: unknown EncTTsSetting type" << setting->type();
            break;
        }
    }

    // remember widget
    if(value != NULL)
    {
        m_settingsWidgetsMap.insert(setting,value);
        connect(setting,SIGNAL(updateGui()),this,SLOT(updateWidget()));
    }

    return value;
}