From 05feaea9bdbcf57076df0273f73c09c74f96468a Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 6 Feb 2025 11:44:35 +0100 Subject: [PATCH] Gui: Do not round color values set in property editor Do not use the number of decimals from the user settings to pass the material to the property as this will cause some unexpected rounding effects. This fixes issue 19048 --- src/Gui/propertyeditor/PropertyItem.cpp | 76 +++++++++++-------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 7ebe9db4bd..f780e9010d 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -3752,37 +3752,33 @@ void PropertyMaterialItem::setValue(const QVariant& value) auto mat = value.value(); Base::Color dc; dc.setValue(mat.diffuseColor); + uint32_t dcp = dc.getPackedValue(); Base::Color ac; ac.setValue(mat.ambientColor); + uint32_t acp = ac.getPackedValue(); Base::Color sc; sc.setValue(mat.specularColor); + uint32_t scp = sc.getPackedValue(); Base::Color ec; ec.setValue(mat.emissiveColor); + uint32_t ecp = ec.getPackedValue(); float s = mat.shininess; float t = mat.transparency; QString data = QStringLiteral("App.Material(" - "DiffuseColor=(%1,%2,%3)," - "AmbientColor=(%4,%5,%6)," - "SpecularColor=(%7,%8,%9)," - "EmissiveColor=(%10,%11,%12)," - "Shininess=(%13)," - "Transparency=(%14)," - ")") - .arg(dc.r, 0, 'f', decimals()) - .arg(dc.g, 0, 'f', decimals()) - .arg(dc.b, 0, 'f', decimals()) - .arg(ac.r, 0, 'f', decimals()) - .arg(ac.g, 0, 'f', decimals()) - .arg(ac.b, 0, 'f', decimals()) - .arg(sc.r, 0, 'f', decimals()) - .arg(sc.g, 0, 'f', decimals()) - .arg(sc.b, 0, 'f', decimals()) - .arg(ec.r, 0, 'f', decimals()) - .arg(ec.g, 0, 'f', decimals()) - .arg(ec.b, 0, 'f', decimals()) - .arg(s, 0, 'f', decimals()) - .arg(t, 0, 'f', decimals()); + "DiffuseColor = %1," + "AmbientColor = %2," + "SpecularColor = %3," + "EmissiveColor = %4," + "Shininess = %5," + "Transparency = %6," + ")") + .arg(dcp) + .arg(acp) + .arg(scp) + .arg(ecp) + .arg(s, 0, 'f', 10) + .arg(t, 0, 'f', 10); setPropertyValue(data); } @@ -4258,37 +4254,33 @@ void PropertyMaterialListItem::setValue(const QVariant& value) auto mat = list[0].value(); Base::Color dc; dc.setValue(mat.diffuseColor); + uint32_t dcp = dc.getPackedValue(); Base::Color ac; ac.setValue(mat.ambientColor); + uint32_t acp = ac.getPackedValue(); Base::Color sc; sc.setValue(mat.specularColor); + uint32_t scp = sc.getPackedValue(); Base::Color ec; ec.setValue(mat.emissiveColor); + uint32_t ecp = ec.getPackedValue(); float s = mat.shininess; float t = mat.transparency; QString item = QStringLiteral("App.Material(" - "DiffuseColor=(%1,%2,%3)," - "AmbientColor=(%4,%5,%6)," - "SpecularColor=(%7,%8,%9)," - "EmissiveColor=(%10,%11,%12)," - "Shininess=(%13)," - "Transparency=(%14)," - ")") - .arg(dc.r, 0, 'f', decimals()) - .arg(dc.g, 0, 'f', decimals()) - .arg(dc.b, 0, 'f', decimals()) - .arg(ac.r, 0, 'f', decimals()) - .arg(ac.g, 0, 'f', decimals()) - .arg(ac.b, 0, 'f', decimals()) - .arg(sc.r, 0, 'f', decimals()) - .arg(sc.g, 0, 'f', decimals()) - .arg(sc.b, 0, 'f', decimals()) - .arg(ec.r, 0, 'f', decimals()) - .arg(ec.g, 0, 'f', decimals()) - .arg(ec.b, 0, 'f', decimals()) - .arg(s, 0, 'f', decimals()) - .arg(t, 0, 'f', decimals()); + "DiffuseColor = %1," + "AmbientColor = %2," + "SpecularColor = %3," + "EmissiveColor = %4," + "Shininess = %5," + "Transparency = %6," + ")") + .arg(dcp) + .arg(acp) + .arg(scp) + .arg(ecp) + .arg(s, 0, 'f', 10) + .arg(t, 0, 'f', 10); str << item << ")"; setPropertyValue(data);