Base: Move App::Color to Base

Every basic data type is stored in Base module, color is standing out as
one that does not. Moving it to Base opens possibilities to integrate it
better with the rest of FreeCAD.
This commit is contained in:
Kacper Donat
2025-02-15 22:58:19 +01:00
parent 145af5cddc
commit a72a63232a
215 changed files with 1057 additions and 1054 deletions

View File

@@ -143,7 +143,7 @@ std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
ParameterGrp::handle hGrp =
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
auto getColor = [hGrp](const char* parameter, App::Color& color) {
auto getColor = [hGrp](const char* parameter, Base::Color& color) {
uint32_t packed = color.getPackedRGB();
packed = hGrp->GetUnsigned(parameter, packed);
color.setPackedRGB(packed);
@@ -162,7 +162,7 @@ std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
mat.diffuseColor = App::Color(red, green, blue, 1.0);
mat.diffuseColor = Base::Color(red, green, blue, 1.0);
}
else {
getColor("DefaultShapeColor", mat.diffuseColor);

View File

@@ -142,7 +142,7 @@ QString MaterialProperty::getYAMLString() const
return _valuePtr->getYAMLString();
}
App::Color MaterialProperty::getColor() const
Base::Color MaterialProperty::getColor() const
{
auto colorString = getValue().toString();
std::stringstream stream(colorString.toStdString());
@@ -163,7 +163,7 @@ App::Color MaterialProperty::getColor() const
stream >> alpha;
}
App::Color color(red, green, blue, alpha);
Base::Color color(red, green, blue, alpha);
return color;
}
@@ -410,7 +410,7 @@ void MaterialProperty::setURL(const QString& value)
_valuePtr->setValue(QVariant(value));
}
void MaterialProperty::setColor(const App::Color& value)
void MaterialProperty::setColor(const Base::Color& value)
{
std::stringstream ss;
ss << "(" << value.r << ", " << value.g << ", " << value.b << ", " << value.a << ")";

View File

@@ -31,7 +31,7 @@
#include <QTextStream>
#include <App/Application.h>
#include <App/Color.h>
#include <Base/Color.h>
#include <App/Material.h>
#include <Base/BaseClass.h>
@@ -102,7 +102,7 @@ public:
{
return getValue().toString();
}
App::Color getColor() const;
Base::Color getColor() const;
MaterialProperty& getColumn(int column);
const MaterialProperty& getColumn(int column) const;
@@ -129,7 +129,7 @@ public:
void setQuantity(const QString& value);
void setList(const QList<QVariant>& value);
void setURL(const QString& value);
void setColor(const App::Color& value);
void setColor(const Base::Color& value);
MaterialProperty& operator=(const MaterialProperty& other);
friend QTextStream& operator<<(QTextStream& output, const MaterialProperty& property);

View File

@@ -64,7 +64,7 @@ public:
bool hasElementColor = false;
for (const auto& view : views) {
if (auto* prop = dynamic_cast<App::PropertyColor*>(view->getPropertyByName(property))) {
App::Color color = prop->getValue();
Base::Color color = prop->getValue();
QSignalBlocker block(buttonColor);
buttonColor->setColor(color.asValue<QColor>());
hasElementColor = true;
@@ -83,7 +83,7 @@ public:
for (const auto& view : views) {
if (auto* prop =
dynamic_cast<App::PropertyMaterial*>(view->getPropertyByName(property))) {
App::Color color = prop->getDiffuseColor();
Base::Color color = prop->getDiffuseColor();
QSignalBlocker block(buttonColor);
buttonColor->setColor(color.asValue<QColor>());
hasElementColor = true;
@@ -310,7 +310,7 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
}
std::string prop_name = name;
if (prop.is<App::PropertyColor>()) {
App::Color value = static_cast<const App::PropertyColor&>(prop).getValue();
Base::Color value = static_cast<const App::PropertyColor&>(prop).getValue();
if (prop_name == "LineColor") {
bool blocked = d->ui.buttonLineColor->blockSignals(true);
d->ui.buttonLineColor->setColor(value.asValue<QColor>());
@@ -479,7 +479,7 @@ void DlgDisplayPropertiesImp::onButtonLineColorChanged()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
QColor s = d->ui.buttonLineColor->color();
App::Color c {};
Base::Color c {};
c.setValue<QColor>(s);
for (auto it : Provider) {
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("LineColor"))) {
@@ -492,7 +492,7 @@ void DlgDisplayPropertiesImp::onButtonPointColorChanged()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
QColor s = d->ui.buttonPointColor->color();
App::Color c {};
Base::Color c {};
c.setValue<QColor>(s);
for (auto it : Provider) {
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("PointColor"))) {

View File

@@ -39,7 +39,7 @@
using namespace MatGui;
ColorWidget::ColorWidget(const App::Color& color, QWidget* parent)
ColorWidget::ColorWidget(const Base::Color& color, QWidget* parent)
: QWidget(parent)
{
_color = color.asValue<QColor>();

View File

@@ -46,7 +46,7 @@ class ColorWidget : public QWidget
Q_OBJECT
public:
explicit ColorWidget(const App::Color& color, QWidget* parent = nullptr);
explicit ColorWidget(const Base::Color& color, QWidget* parent = nullptr);
~ColorWidget() override = default;
QSize sizeHint() const override { return {75,23}; }

View File

@@ -31,7 +31,7 @@
#include <QSpacerItem>
#include <QVBoxLayout>
#include <App/Color.h>
#include <Base/Color.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Gui/Command.h>