Skip to content
Snippets Groups Projects
Commit bbbc7963 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add editor of color properties.

parent 31c24484
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,7 @@ namespace gepetto {
void setIntProperty (int value) const;
void setStringProperty (const QString& value) const;
void setFloatProperty (const double& value) const;
void setColorProperty (const QColor& value) const;
private:
template <typename T> void setProperty(const QObject* sender, const T& value) const;
......
......@@ -47,13 +47,13 @@ namespace gepetto {
QComboBox* cb = new QComboBox;
int value;
/* bool success = */ enumProp->get(value);
int indexSelected = 0;
std::size_t indexSelected = 0;
for (std::size_t i = 0; i < enumMeta->values.size(); ++i)
{
cb->addItem(enumMeta->names[i].c_str(), enumMeta->values[i]);
if (value == enumMeta->values[i]) indexSelected = i;
}
cb->setCurrentIndex(indexSelected);
cb->setCurrentIndex((int)indexSelected);
if (prop->hasWriteAccess())
bti->connect(cb, SIGNAL(currentIndexChanged(int)), SLOT(setIntProperty(int)));
else
......@@ -87,6 +87,28 @@ namespace gepetto {
return dsb;
}
QWidget* colorPropertyEditor (BodyTreeItem* bti, const graphics::PropertyPtr_t prop)
{
if (!prop->hasWriteAccess()) return NULL;
osgVector4 value;
/* bool success = */ prop->get(value);
QColor color;
color.setRgbF((qreal)value[0],(qreal)value[1],(qreal)value[2],(qreal)value[3]);
QPushButton* button = new QPushButton("Select color");
// Set icon for current color value
/// Color dialog should be opened in a different place
QColorDialog* colorDialog = new QColorDialog(color, MainWindow::instance());
colorDialog->setOption(QColorDialog::ShowAlphaChannel, true);
colorDialog->setProperty("propertyName", QString::fromStdString(prop->name()));
colorDialog->connect(button, SIGNAL(clicked()), SLOT(open()));
bti->connect (colorDialog, SIGNAL(colorSelected(QColor)), SLOT(setColorProperty(QColor)));
return button;
}
BodyTreeItem::BodyTreeItem(QObject *parent, graphics::NodePtr_t node) :
QObject (parent),
QStandardItem (QString (node->getID().c_str())),
......@@ -131,12 +153,18 @@ namespace gepetto {
field = stringPropertyEditor(this, prop);
} else if (prop->type() == "float") {
field = floatPropertyEditor(this, prop);
} else {
qDebug() << "Unhandled property" << name << "of type" << prop->type().c_str() << ".";
} else if (prop->type() == "osgVector4") {
if (name.contains ("color", Qt::CaseInsensitive)) {
field = colorPropertyEditor (this, prop);
} else {
field = NULL;
}
}
if (field != NULL) {
field->setProperty("propertyName", name);
l->addRow(name + ':', field);
} else {
qDebug() << "Unhandled property" << name << "of type" << prop->type().c_str() << ".";
}
}
disconnect(SIGNAL(requestInitialize()));
......@@ -151,6 +179,8 @@ namespace gepetto {
std::string name = nameVariant.toString().toStdString();
boost::mutex::scoped_lock lock (MainWindow::instance()->osg()->osgFrameMutex());
node_->setProperty<T>(name, value);
} else {
qDebug() << "Sender has no property propertyName" << sender;
}
}
}
......@@ -175,6 +205,16 @@ namespace gepetto {
setProperty (QObject::sender(), float(value));
}
void BodyTreeItem::setColorProperty (const QColor& value) const
{
osgVector4 c (
(float)value.redF(),
(float)value.greenF(),
(float)value.blueF(),
(float)value.alphaF());
setProperty (QObject::sender(), c);
}
BodyTreeItem::~BodyTreeItem()
{
if (propertyEditors_->parent() != NULL)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment