WidgetParameterBool::WidgetParameterBool(ParameterPtrT<bool> parameter) : WidgetParameter<bool>(parameter) { QCheckBox* checkBox = new QCheckBox(this); checkBox->setChecked(parameter->lastValue()); checkBox->move(0,0); parameter->addNewInternalValueCallback([checkBox, this](bool value){ checkBox->blockSignals(true); checkBox->setChecked(value); checkBox->blockSignals(false); }); BOOST_VERIFY(connect(checkBox, SELECT<bool>::OVERLOAD_OF(&QCheckBox::clicked), [this](bool b) { mParameter->set(b); })); mWidget = checkBox; }
void EncTtsCfgGui::updateWidget() { // get sender setting EncTtsSetting* setting = qobject_cast<EncTtsSetting*>(QObject::sender()); if(setting == NULL) return; // get corresponding widget QWidget* widget = m_settingsWidgetsMap.value(setting); // 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; lineedit->blockSignals(true); lineedit->setText(setting->current().toString()); lineedit->blockSignals(false); break; } case EncTtsSetting::eREADONLYSTRING: { QLabel* label = (QLabel*) widget; label->blockSignals(true); label->setText(setting->current().toString()); label->blockSignals(false); break; } case EncTtsSetting::eSTRINGLIST: { QComboBox* combobox = (QComboBox*) widget; combobox->blockSignals(true); combobox->clear(); combobox->addItems(setting->list()); int index = combobox->findText(setting->current().toString()); combobox->setCurrentIndex(index); combobox->blockSignals(false); break; } case EncTtsSetting::eBOOL: { QCheckBox* checkbox = (QCheckBox*) widget; checkbox->blockSignals(true); checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked); checkbox->blockSignals(false); break; } default: { LOG_WARNING() << "unknown EncTTsSetting"; break; } } }
QWidget* ConstraintTag::createWidget(QList<Tag *> tags, QWidget *parent) { // === Create Widget === QWidget* base = new QWidget(parent); QHBoxLayout* horLayout = new QHBoxLayout(); QStringList comboboxItems = QStringList() << tr("ignore") << tr("local") << tr("global"); QVBoxLayout* posLayout = new QVBoxLayout(); posLayout->setSpacing(0); posLayout->setContentsMargins(0,0,0,0); QComboBox* posComboBox = new QComboBox(base); posComboBox->addItems(comboboxItems); posLayout->addWidget(posComboBox); QCheckBox* affectXCB = new QCheckBox("x", base); QCheckBox* affectYCB = new QCheckBox("y", base); QHBoxLayout* l = new QHBoxLayout(); l->setContentsMargins(0,0,0,0); l->setSpacing(0); l->addWidget(affectXCB); l->addWidget(affectYCB); posLayout->addLayout(l); posLayout->addStretch(); ObjectEdit* posObject = new ObjectEdit(base); posObject->setProject(tags.first()->owner()->project()); posLayout->addWidget(posObject); QVBoxLayout* rotLayout = new QVBoxLayout(); rotLayout->setSpacing(0); rotLayout->setContentsMargins(0,0,0,0); QComboBox* rotComboBox = new QComboBox(base); rotComboBox->addItems(comboboxItems); rotLayout->addWidget(rotComboBox); rotLayout->addStretch(); ObjectEdit* rotObject = new ObjectEdit(base); rotObject->setProject(tags.first()->owner()->project()); rotLayout->addWidget(rotObject); QVBoxLayout* scaleLayout = new QVBoxLayout(); scaleLayout->setSpacing(0); scaleLayout->setContentsMargins(0,0,0,0); QComboBox* scaleComboBox = new QComboBox(base); scaleComboBox->addItems(comboboxItems); scaleLayout->addWidget(scaleComboBox); scaleLayout->addStretch(); ObjectEdit* scaleObject = new ObjectEdit(base); scaleObject->setProject(tags.first()->owner()->project()); scaleLayout->addWidget(scaleObject); horLayout->addLayout(posLayout); horLayout->addLayout(rotLayout); horLayout->addLayout(scaleLayout); // === end create Widget === // === define update function === auto update = [=]() { posComboBox->blockSignals(true); posObject->blockSignals(true); affectXCB->blockSignals(true); affectYCB->blockSignals(true); rotComboBox->blockSignals(true); rotObject->blockSignals(true); scaleComboBox->blockSignals(true); scaleObject->blockSignals(true); bool pModeDifference = false; bool affectXDifference = false; bool affectYDifference = false; bool pIdDifference = false; bool rModeDifference = false; bool rIdDifference = false; bool sModeDifference = false; bool sIdDifference = false; Mode pMode = ((ConstraintTag*) tags.first())->_positionMode; bool affectX = ((ConstraintTag*) tags.first())->_affectX; bool affectY = ((ConstraintTag*) tags.first())->_affectY; quint64 pId = ((ConstraintTag*) tags.first())->_posId; bool hasPId = ((ConstraintTag*) tags.first())->_hasPosId; Mode rMode = ((ConstraintTag*) tags.first())->_rotationMode; quint64 rId = ((ConstraintTag*) tags.first())->_rotId; bool hasRId = ((ConstraintTag*) tags.first())->_hasRotId; Mode sMode = ((ConstraintTag*) tags.first())->_scalationMode; quint64 sId = ((ConstraintTag*) tags.first())->_scaleId; bool hasSId = ((ConstraintTag*) tags.first())->_hasScaleId; foreach (Tag* t, tags) { ConstraintTag* ct = (ConstraintTag*) t; if (ct->_positionMode != pMode) pModeDifference = true; if (ct->_affectX != affectX) affectXDifference = true; if (ct->_affectY != affectY) affectYDifference = true; if ((ct->_hasPosId != hasPId) || (ct->_hasPosId && hasPId && ct->_posId != pId)) pIdDifference = true; if (ct->_rotationMode != rMode) rModeDifference = true; if ((ct->_hasRotId != hasRId) || (ct->_hasRotId && hasRId && ct->_rotId != rId)) rIdDifference = true; if (ct->_scalationMode != sMode) sModeDifference = true; if ((ct->_hasScaleId != hasSId) || (ct->_hasScaleId && hasSId && ct->_scaleId != sId)) sIdDifference = true; } if (pModeDifference) posComboBox->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else posComboBox->setStyleSheet(""); if (affectXDifference) affectXCB->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else affectXCB->setStyleSheet(""); if (affectYDifference) affectYCB->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else affectYCB->setStyleSheet(""); if (pIdDifference) posObject->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else posObject->setStyleSheet(""); posComboBox->setCurrentIndex(modeToIndex(pMode)); affectXCB->setChecked(affectX); affectXCB->setEnabled(pMode != Mode::ignore); affectYCB->setChecked(affectY); affectYCB->setEnabled(pMode != Mode::ignore); posObject->setEnabled(pMode != Mode::ignore); if (hasPId) posObject->setId(pId); else posObject->clear(); if (rModeDifference) rotComboBox->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else rotComboBox->setStyleSheet(""); if (rIdDifference) rotObject->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else rotObject->setStyleSheet(""); rotComboBox->setCurrentIndex(modeToIndex(rMode)); rotObject->setEnabled(rMode != Mode::ignore); if (hasRId) rotObject->setId(rId); else rotObject->clear(); if (sModeDifference) scaleComboBox->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else scaleComboBox->setStyleSheet(""); if (sIdDifference) scaleObject->setStyleSheet(QString("background-color:%1").arg(Property::MULTIPLE_VALUES_COLOR)); else scaleObject->setStyleSheet(""); scaleComboBox->setCurrentIndex(modeToIndex(sMode)); scaleObject->setEnabled(sMode != Mode::ignore); if (hasSId) scaleObject->setId(sId); else scaleObject->clear(); posComboBox->blockSignals(false); posObject->blockSignals(false); affectXCB->blockSignals(false); affectYCB->blockSignals(false); rotComboBox->blockSignals(false); rotObject->blockSignals(false); scaleComboBox->blockSignals(false); scaleObject->blockSignals(false); };
void protoObject::propertyUpdated(QString propertyName){ QObject *receiver = mapper->mapping(propertyName); QWidget *widget; if (receiver) return; //if not binding, just leave widget = qobject_cast<QLabel*>(receiver); if (widget) { QLabel* edit = qobject_cast<QLabel*>(receiver); QString value = this->property(propertyName.toLatin1()).toString(); edit->blockSignals(true); edit->setText(edit->text().arg(value)); edit->blockSignals(false); }; widget = qobject_cast<QLineEdit*>(receiver); if (widget) { QLineEdit* edit = qobject_cast<QLineEdit*>(receiver); QString value = this->property(propertyName.toLatin1()).toString(); edit->blockSignals(true); edit->setText(value); edit->blockSignals(false); }; widget = qobject_cast<QComboBox*>(receiver); if (widget) { QComboBox* edit = qobject_cast<QComboBox*>(receiver); edit->blockSignals(true); edit->setCurrentIndex(edit->findData(this->property(propertyName.toLatin1()), Qt::UserRole)); edit->blockSignals(false); }; widget = qobject_cast<QRadioButton*>(receiver); if (widget) { QRadioButton* edit = qobject_cast<QRadioButton*>(receiver); bool value = this->property(propertyName.toLatin1()).toBool(); edit->blockSignals(true); edit->setChecked(value); edit->blockSignals(false); }; widget = qobject_cast<QCheckBox*>(receiver); if (widget) { QCheckBox* edit = qobject_cast<QCheckBox*>(receiver); bool value = this->property(propertyName.toLatin1()).toBool(); edit->blockSignals(true); edit->setChecked(value); edit->blockSignals(false); }; widget = qobject_cast<QPlainTextEdit*>(receiver); if (widget) { QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(receiver); QString value = this->property(propertyName.toLatin1()).toString(); edit->blockSignals(true); edit->setPlainText(value); edit->blockSignals(false); }; widget = qobject_cast<QSpinBox*>(receiver); if (widget) { QSpinBox* edit = qobject_cast<QSpinBox*>(receiver); int value = this->property(propertyName.toLatin1()).toInt(); edit->blockSignals(true); edit->setValue(value); edit->blockSignals(false); }; widget = qobject_cast<QDoubleSpinBox*>(receiver); if (widget) { QDoubleSpinBox* edit = qobject_cast<QDoubleSpinBox*>(receiver); double value = this->property(propertyName.toLatin1()).toDouble(); edit->blockSignals(true); edit->setValue(value); edit->blockSignals(false); }; widget = qobject_cast<QDateTimeEdit*>(receiver); if (widget) { QDateTimeEdit* edit = qobject_cast<QDateTimeEdit*>(receiver); QDateTime value = this->property(propertyName.toLatin1()).toDateTime(); edit->blockSignals(true); edit->setDateTime(value); edit->blockSignals(false); }; }