Gui: improve PropertyMaterialListItem

This commit is contained in:
wmayer
2024-02-19 08:00:07 +01:00
committed by wwmayer
parent c633edfe8a
commit 41b3be8fb6
2 changed files with 22 additions and 18 deletions

View File

@@ -3618,12 +3618,16 @@ PropertyMaterialListItem::PropertyMaterialListItem()
emissive->setPropertyName(QLatin1String("EmissiveColor"));
this->appendChild(emissive);
shininess = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
shininess = static_cast<PropertyIntegerConstraintItem*>(PropertyIntegerConstraintItem::create());
shininess->setRange(0, 100);
shininess->setStepSize(5);
shininess->setParent(this);
shininess->setPropertyName(QLatin1String("Shininess"));
this->appendChild(shininess);
transparency = static_cast<PropertyFloatItem*>(PropertyFloatItem::create());
transparency = static_cast<PropertyIntegerConstraintItem*>(PropertyIntegerConstraintItem::create());
transparency->setRange(0, 100);
transparency->setStepSize(5);
transparency->setParent(this);
transparency->setPropertyName(QLatin1String("Transparency"));
this->appendChild(transparency);
@@ -3779,7 +3783,7 @@ void PropertyMaterialListItem::setEmissiveColor(const QColor& color)
setValue(list);
}
float PropertyMaterialListItem::getShininess() const
int PropertyMaterialListItem::getShininess() const
{
QVariant value = data(1, Qt::EditRole);
if (!value.canConvert<QVariantList>())
@@ -3793,10 +3797,10 @@ float PropertyMaterialListItem::getShininess() const
return 0;
auto mat = list[0].value<Material>();
return mat.shininess;
return int(100 * mat.shininess);
}
void PropertyMaterialListItem::setShininess(float s)
void PropertyMaterialListItem::setShininess(int s)
{
QVariant value = data(1, Qt::EditRole);
if (!value.canConvert<QVariantList>())
@@ -3810,12 +3814,12 @@ void PropertyMaterialListItem::setShininess(float s)
return;
auto mat = list[0].value<Material>();
mat.shininess = s;
mat.shininess = float(s) / 100.0F;
list[0] = QVariant::fromValue<Material>(mat);
setValue(list);
}
float PropertyMaterialListItem::getTransparency() const
int PropertyMaterialListItem::getTransparency() const
{
QVariant value = data(1, Qt::EditRole);
if (!value.canConvert<QVariantList>())
@@ -3829,10 +3833,10 @@ float PropertyMaterialListItem::getTransparency() const
return 0;
auto mat = list[0].value<Material>();
return mat.transparency;
return int(100 * mat.transparency);
}
void PropertyMaterialListItem::setTransparency(float t)
void PropertyMaterialListItem::setTransparency(int t)
{
QVariant value = data(1, Qt::EditRole);
if (!value.canConvert<QVariantList>())
@@ -3846,7 +3850,7 @@ void PropertyMaterialListItem::setTransparency(float t)
return;
auto mat = list[0].value<Material>();
mat.transparency = t;
mat.transparency = float(t) / 100.0F;
list[0] = QVariant::fromValue<Material>(mat);
setValue(list);
}
@@ -3920,8 +3924,8 @@ QVariant PropertyMaterialListItem::toolTip(const App::Property* prop) const
.arg(ac.red()).arg(ac.green()).arg(ac.blue())
.arg(sc.red()).arg(sc.green()).arg(sc.blue())
.arg(ec.red()).arg(ec.green()).arg(ec.blue())
.arg(value.shininess)
.arg(value.transparency)
.arg(int(100 * value.shininess))
.arg(int(100 * value.transparency))
;
return {data};

View File

@@ -1075,10 +1075,10 @@ class GuiExport PropertyMaterialListItem : public PropertyItem
void setSpecularColor(const QColor&);
QColor getEmissiveColor() const;
void setEmissiveColor(const QColor&);
float getShininess() const;
void setShininess(float);
float getTransparency() const;
void setTransparency(float);
int getShininess() const;
void setShininess(int);
int getTransparency() const;
void setTransparency(int);
protected:
PropertyMaterialListItem();
@@ -1095,8 +1095,8 @@ private:
PropertyColorItem* diffuse;
PropertyColorItem* specular;
PropertyColorItem* emissive;
PropertyFloatItem* shininess;
PropertyFloatItem* transparency;
PropertyIntegerConstraintItem* shininess;
PropertyIntegerConstraintItem* transparency;
};
/**