From 41b3be8fb651cd9d188fda881bb356578f79f4dd Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 19 Feb 2024 08:00:07 +0100 Subject: [PATCH] Gui: improve PropertyMaterialListItem --- src/Gui/propertyeditor/PropertyItem.cpp | 28 ++++++++++++++----------- src/Gui/propertyeditor/PropertyItem.h | 12 +++++------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 9bed833140..f1cfcb42ce 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -3618,12 +3618,16 @@ PropertyMaterialListItem::PropertyMaterialListItem() emissive->setPropertyName(QLatin1String("EmissiveColor")); this->appendChild(emissive); - shininess = static_cast(PropertyFloatItem::create()); + shininess = static_cast(PropertyIntegerConstraintItem::create()); + shininess->setRange(0, 100); + shininess->setStepSize(5); shininess->setParent(this); shininess->setPropertyName(QLatin1String("Shininess")); this->appendChild(shininess); - transparency = static_cast(PropertyFloatItem::create()); + transparency = static_cast(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()) @@ -3793,10 +3797,10 @@ float PropertyMaterialListItem::getShininess() const return 0; auto mat = list[0].value(); - 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()) @@ -3810,12 +3814,12 @@ void PropertyMaterialListItem::setShininess(float s) return; auto mat = list[0].value(); - mat.shininess = s; + mat.shininess = float(s) / 100.0F; list[0] = QVariant::fromValue(mat); setValue(list); } -float PropertyMaterialListItem::getTransparency() const +int PropertyMaterialListItem::getTransparency() const { QVariant value = data(1, Qt::EditRole); if (!value.canConvert()) @@ -3829,10 +3833,10 @@ float PropertyMaterialListItem::getTransparency() const return 0; auto mat = list[0].value(); - 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()) @@ -3846,7 +3850,7 @@ void PropertyMaterialListItem::setTransparency(float t) return; auto mat = list[0].value(); - mat.transparency = t; + mat.transparency = float(t) / 100.0F; list[0] = QVariant::fromValue(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}; diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index 1b4ce6e571..6512c09665 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -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; }; /**