void PropertyWidgetBuilder::visitValue(ValueProperty<int> & property) { QSpinBox * spinbox = new QSpinBox(m_active_widget); m_active_layout->addRow(property.description(), spinbox); QObject::connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [&property] (int i) { property.setValue(i); qDebug("Set Property %s = %i", qPrintable(property.name()), i); } ); }
void PropertyWidgetBuilder::visitValue(ValueProperty<QString> & property) { QLineEdit * lineEdit = new QLineEdit(property.value(), m_active_widget); m_active_layout->addRow(property.description(), lineEdit); QObject::connect(lineEdit, &QLineEdit::textChanged, [&property] (QString text) { property.setValue(text); qDebug("Set Property %s = \"%s\"", qPrintable(property.name()), qPrintable(text)); } ); }
void PropertyWidgetBuilder::visitValue(ValueProperty<float> & property) { QSlider * slider = new QSlider(m_active_widget); slider->setOrientation(Qt::Horizontal); m_active_layout->addRow(property.description(), slider); QObject::connect(slider, &QSlider::valueChanged, [&property] (int i) { property.setValue(i); qDebug("Set Property %s = %i", qPrintable(property.name()), i); } ); }
void PropertyWidgetBuilder::visitValue(ValueProperty<QColor> & property) { QHBoxLayout * layout = new QHBoxLayout(m_active_widget); QLabel * label = new QLabel("R: 0.1 G: 0.9 B: 0.22", m_active_widget); QPushButton * button = new QPushButton("Pick Color", m_active_widget); layout->addWidget(label); layout->addWidget(button); m_active_layout->addRow(property.description(), layout); QObject::connect(button, &QPushButton::clicked, [&property, label] (bool) { property.setValue(QColorDialog::getColor(property.value())); QString newlabel = QString("R: %1 G: %2 B: %3") .arg(property.value().red()) .arg(property.value().green()) .arg(property.value().blue()); label->setText(newlabel); qDebug("Set Property %s = %s", qPrintable(property.name()), qPrintable(newlabel)); } ); }
gluit::Component::Ptr createPropertyUI<ValueProperty<bool> >(ValueProperty<bool>& property) { gluit::Component::Ptr panel = gluit::Component::create<gluit::Component>(); panel->setLayout(boost::make_shared<gluit::VerticalLayout>()); panel->setActive(property.isEnabled()); gluit::Checkbox::Ptr propertyValue = gluit::Component::create<gluit::Checkbox>(); propertyValue->setText(property.getName()); propertyValue->setChecked(property.getValue()); panel->add(propertyValue); property.onValueChange.connect( PropertyEvent<bool>::Signal::slot_type(&setCheckboxChecked, CheckboxWeakPtr(propertyValue), _1).track(propertyValue)); propertyValue->onCheckChange.connect(boost::bind(&setPropertyValue<bool>, boost::ref(property), _1)); property.onSelfChange.connect( Property::Signal::slot_type(&setComponentActive, ComponentWeakPtr(panel), boost::ref(property)).track(panel)); return panel; }
void PropertyWidgetBuilder::visitValue(ValueProperty<bool> & property) { QCheckBox * checkBox = new QCheckBox(m_active_widget); checkBox->setText(property.description()); if (property.value()) checkBox->setCheckState(Qt::Checked); else checkBox->setCheckState(Qt::Unchecked); m_active_layout->addWidget(checkBox); QObject::connect(checkBox, &QCheckBox::stateChanged, [&property] (int state) { property.setValue(state); qDebug("Set Property %s = %i", qPrintable(property.name()), property.value()); } ); }
static void buildNumericPropertyUI(ComponentWeakPtr weak, ValueProperty<T>& property) { std::vector<gluit::Component::Ptr> components; gluit::Label::Ptr propertyName = gluit::Component::create<gluit::Label>(); propertyName->setText(property.getName()); components.push_back(propertyName); unsigned int precision = std::numeric_limits<T>::is_integer ? 0 : 2; Constraint<T> constraint = property.getConstraint(); if (std::fabs(constraint.max - constraint.min) > 10000) { gluit::Spinner::Ptr spinner = gluit::Component::create<gluit::Spinner>(); spinner->setMinimum(constraint.min); spinner->setMaximum(constraint.max); spinner->setStepSize(constraint.step); spinner->setValue(property.getValue()); spinner->setDisplayPrecision(precision); property.onValueChange.connect( typename PropertyEvent<T>::Signal::slot_type(&setSpinnerValue<T>, SpinnerWeakPtr(spinner), _1).track(spinner)); spinner->onValueChange.connect(boost::bind(&setNumericPropertyValue<double, T> , boost::ref(property), _1)); components.push_back(spinner); } else { gluit::Slider::Ptr slider = gluit::Component::create<gluit::Slider>(); slider->setMinimum(constraint.min); slider->setMaximum(constraint.max); slider->setMinStepSize(constraint.step); slider->setValue(property.getValue()); slider->setDisplayPrecision(precision); property.onValueChange.connect( typename PropertyEvent<T>::Signal::slot_type(&setSliderValue<T>, SliderWeakPtr(slider), _1).track(slider)); slider->onValueChange.connect(boost::bind(&setNumericPropertyValue<double, T> , boost::ref(property), _1)); components.push_back(slider); } gluit::invokeInEventLoop(boost::bind(&replaceContents, weak, components)); }
static gluit::Component::Ptr createNumericPropertyUI(ValueProperty<T>& property) { gluit::Component::Ptr panel = gluit::Component::create<gluit::Component>(); panel->setLayout(boost::make_shared<gluit::VerticalLayout>()); panel->setActive(property.isEnabled()); buildNumericPropertyUI(panel, property); property.onSelfChange.connect( Property::Signal::slot_type(&setComponentActive, ComponentWeakPtr(panel), boost::ref(property)).track(panel)); property.onSelfChange.connect( Property::Signal::slot_type(&buildNumericPropertyUI<T>, ComponentWeakPtr(panel), boost::ref(property)).track(panel)); return panel; }
printf(std::to_string(length.Get()).c_str()); auto var = 0; std::cin >> var; return 0; }); printf(std::to_string(height.Get()).c_str()); auto var = 0; std::cin >> var; #endif ValueProperty<int> height(0); height.MakeGet([](auto * value) { return *value; }); height.MakeSet([](auto * value, auto newValue) { if (newValue > 0) *value = newValue; else *value = 0; }); height.Set(-2); printf(std::to_string(height.Get()).c_str());
static void setNumericPropertyValue(ValueProperty<To>& property, const gluit::ChangeEvent<From>& e) { property.setValue(boost::numeric_cast<To>(e.newValue)); }
static void setPropertyValue(ValueProperty<T>& property, const gluit::ChangeEvent<T>& e) { property.setValue(e.newValue); }