Consolidated light color properties.

This commit is contained in:
Leonardo Zide 2023-08-27 11:17:07 -07:00
parent 4e09ceaf7d
commit 9d60160f6a
8 changed files with 141 additions and 136 deletions

View file

@ -649,6 +649,11 @@ inline lcVector3 lcVector3FromColor(quint32 Color)
return v; return v;
} }
inline lcVector3 lcVector3FromQColor(QColor Color)
{
return lcVector3(Color.redF(), Color.greenF(), Color.blueF());
}
inline lcVector4 lcVector4FromColor(quint32 Color) inline lcVector4 lcVector4FromColor(quint32 Color)
{ {
lcVector4 v(LC_RGBA_RED(Color), LC_RGBA_GREEN(Color), LC_RGBA_BLUE(Color), LC_RGBA_ALPHA(Color)); lcVector4 v(LC_RGBA_RED(Color), LC_RGBA_GREEN(Color), LC_RGBA_BLUE(Color), LC_RGBA_ALPHA(Color));
@ -661,6 +666,11 @@ inline quint32 lcColorFromVector3(const lcVector3& Color)
return LC_RGB(roundf(Color[0] * 255), roundf(Color[1] * 255), roundf(Color[2] * 255)); return LC_RGB(roundf(Color[0] * 255), roundf(Color[1] * 255), roundf(Color[2] * 255));
} }
inline QColor lcQColorFromVector3(const lcVector3& Color)
{
return QColor::fromRgb(roundf(Color[0] * 255), roundf(Color[1] * 255), roundf(Color[2] * 255));
}
inline float lcLuminescence(const lcVector3& Color) inline float lcLuminescence(const lcVector3& Color)
{ {
return 0.2126f * Color[0] + 0.7152f * Color[1] + 0.0722f * Color[2]; return 0.2126f * Color[0] + 0.7152f * Color[1] + 0.0722f * Color[2];

View file

@ -3113,6 +3113,19 @@ void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
gMainWindow->UpdateCameraMenu(); gMainWindow->UpdateCameraMenu();
} }
void lcModel::SetLightColor(lcLight* Light, const lcVector3& Color)
{
if (Light->GetColor() == Color)
return;
Light->SetColor(Color, mCurrentStep, gMainWindow->GetAddKeys());
Light->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Changing Light Color"));
gMainWindow->UpdateSelectedObjects(false);
UpdateAllViews();
}
void lcModel::SetLightName(lcLight* Light, const QString &Name) void lcModel::SetLightName(lcLight* Light, const QString &Name)
{ {
if (Light->GetName() == Name) if (Light->GetName() == Name)

View file

@ -367,6 +367,8 @@ public:
void SetCameraZNear(lcCamera* Camera, float ZNear); void SetCameraZNear(lcCamera* Camera, float ZNear);
void SetCameraZFar(lcCamera* Camera, float ZFar); void SetCameraZFar(lcCamera* Camera, float ZFar);
void SetCameraName(lcCamera* Camera, const QString& Name); void SetCameraName(lcCamera* Camera, const QString& Name);
void SetLightColor(lcLight* Light, const lcVector3& Color);
void SetLightName(lcLight* Light, const QString& Name); void SetLightName(lcLight* Light, const QString& Name);
void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property); void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property);

View file

@ -44,11 +44,8 @@ lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcL
mPOVRayLight = false; mPOVRayLight = false;
mShadowless = false; mShadowless = false;
mEnableCutoff = false; mEnableCutoff = false;
mAmbientColor = lcVector4(0.0f, 0.0f, 0.0f, 1.0f); mColor = lcVector3(1.0f, 1.0f, 1.0f);
mDiffuseColor = lcVector4(0.8f, 0.8f, 0.8f, 1.0f);
mSpecularColor = lcVector4(1.0f, 1.0f, 1.0f, 1.0f);
mAttenuation = lcVector3(1.0f, 0.0f, 0.0f); mAttenuation = lcVector3(1.0f, 0.0f, 0.0f);
mLightColor = lcVector3(1.0f, 1.0f, 1.0f);
mLightFactor[0] = LightType == lcLightType::Directional ? 11.4f : 0.25f; mLightFactor[0] = LightType == lcLightType::Directional ? 11.4f : 0.25f;
mLightFactor[1] = LightType == lcLightType::Area ? 0.25f : LightType == lcLightType::Spot ? 0.150f : 0.0f; mLightFactor[1] = LightType == lcLightType::Area ? 0.25f : LightType == lcLightType::Spot ? 0.150f : 0.0f;
mLightDiffuse = 1.0f; mLightDiffuse = 1.0f;
@ -66,11 +63,8 @@ lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcL
mPositionKeys.ChangeKey(mPosition, 1, true); mPositionKeys.ChangeKey(mPosition, 1, true);
mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true); mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true);
mUpVectorKeys.ChangeKey(mUpVector, 1, true); mUpVectorKeys.ChangeKey(mUpVector, 1, true);
mAmbientColorKeys.ChangeKey(mAmbientColor, 1, true); mColorKeys.ChangeKey(mColor, 1, true);
mDiffuseColorKeys.ChangeKey(mDiffuseColor, 1, true);
mSpecularColorKeys.ChangeKey(mSpecularColor, 1, true);
mAttenuationKeys.ChangeKey(mAttenuation, 1, true); mAttenuationKeys.ChangeKey(mAttenuation, 1, true);
mLightColorKeys.ChangeKey(mLightColor, 1, true);
mLightFactorKeys.ChangeKey(mLightFactor, 1, true); mLightFactorKeys.ChangeKey(mLightFactor, 1, true);
mLightDiffuseKeys.ChangeKey(mLightDiffuse, 1, true); mLightDiffuseKeys.ChangeKey(mLightDiffuse, 1, true);
mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true); mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true);
@ -115,10 +109,10 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
Stream << QLatin1String("0 !LEOCAD LIGHT UP_VECTOR ") << mUpVector[0] << ' ' << mUpVector[1] << ' ' << mUpVector[2] << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT UP_VECTOR ") << mUpVector[0] << ' ' << mUpVector[1] << ' ' << mUpVector[2] << LineEnding;
} }
if (mLightColorKeys.GetSize() > 1) if (mColorKeys.GetSize() > 1)
mLightColorKeys.SaveKeysLDraw(Stream, "LIGHT COLOR_RGB_KEY "); mColorKeys.SaveKeysLDraw(Stream, "LIGHT COLOR_KEY ");
else else
Stream << QLatin1String("0 !LEOCAD LIGHT COLOR_RGB ") << mLightColor[0] << ' ' << mLightColor[1] << ' ' << mLightColor[2] << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT COLOR ") << mColor[0] << ' ' << mColor[1] << ' ' << mColor[2] << LineEnding;
if (!mPOVRayLight) if (!mPOVRayLight)
{ {
@ -326,27 +320,29 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
Stream >> mPosition[0] >> mPosition[1] >> mPosition[2]; Stream >> mPosition[0] >> mPosition[1] >> mPosition[2];
mPositionKeys.ChangeKey(mPosition, 1, true); mPositionKeys.ChangeKey(mPosition, 1, true);
} }
else if (Token == QLatin1String("POSITION_KEY"))
mPositionKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("TARGET_POSITION")) else if (Token == QLatin1String("TARGET_POSITION"))
{ {
Stream >> mTargetPosition[0] >> mTargetPosition[1] >> mTargetPosition[2]; Stream >> mTargetPosition[0] >> mTargetPosition[1] >> mTargetPosition[2];
mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true); mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true);
} }
else if (Token == QLatin1String("TARGET_POSITION_KEY"))
mTargetPositionKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("UP_VECTOR")) else if (Token == QLatin1String("UP_VECTOR"))
{ {
Stream >> mUpVector[0] >> mUpVector[1] >> mUpVector[2]; Stream >> mUpVector[0] >> mUpVector[1] >> mUpVector[2];
mUpVectorKeys.ChangeKey(mUpVector, 1, true); mUpVectorKeys.ChangeKey(mUpVector, 1, true);
} }
else if (Token == QLatin1String("POSITION_KEY"))
mPositionKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("TARGET_POSITION_KEY"))
mTargetPositionKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("UP_VECTOR_KEY")) else if (Token == QLatin1String("UP_VECTOR_KEY"))
mUpVectorKeys.LoadKeysLDraw(Stream); mUpVectorKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("COLOR_RGB")) else if (Token == QLatin1String("COLOR"))
{ {
Stream >> mLightColor[0] >> mLightColor[1] >> mLightColor[2]; Stream >> mColor[0] >> mColor[1] >> mColor[2];
mLightColorKeys.ChangeKey(mLightColor, 1, true); mColorKeys.ChangeKey(mColor, 1, true);
} }
else if (Token == QLatin1String("COLOR_KEY"))
mColorKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH")) else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH"))
{ {
if (mPOVRayLight) if (mPOVRayLight)
@ -461,8 +457,6 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
{ {
mShadowless = true; mShadowless = true;
} }
else if (Token == QLatin1String("COLOR_RGB_KEY"))
mLightColorKeys.LoadKeysLDraw(Stream);
else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY"))) else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY")))
mSpotExponentKeys.LoadKeysLDraw(Stream); mSpotExponentKeys.LoadKeysLDraw(Stream);
else if ((Token == QLatin1String("ANGLE_KEY")) || (Token == QLatin1String("RADIUS_KEY")) || (Token == QLatin1String("SIZE_KEY")) || (Token == QLatin1String("RADIUS_AND_SPOT_BLEND_KEY"))) else if ((Token == QLatin1String("ANGLE_KEY")) || (Token == QLatin1String("RADIUS_KEY")) || (Token == QLatin1String("SIZE_KEY")) || (Token == QLatin1String("RADIUS_AND_SPOT_BLEND_KEY")))
@ -562,10 +556,6 @@ void lcLight::UpdateLight(lcStep Step, lcLightProperties Props, int Property)
case LC_LIGHT_SHAPE: case LC_LIGHT_SHAPE:
mLightShape = Props.mLightShape; mLightShape = Props.mLightShape;
break; break;
case LC_LIGHT_COLOR:
mLightColor = Props.mLightColor;
mLightColorKeys.ChangeKey(mLightColor, Step, false);
break;
case LC_LIGHT_FACTOR: case LC_LIGHT_FACTOR:
if (Props.mPOVRayLight && mLightType == lcLightType::Area) if (Props.mPOVRayLight && mLightType == lcLightType::Area)
{ {
@ -841,16 +831,18 @@ void lcLight::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
} }
} }
void lcLight::SetColor(const lcVector3& Color, lcStep Step, bool AddKey)
{
mColorKeys.ChangeKey(Color, Step, AddKey);
}
void lcLight::InsertTime(lcStep Start, lcStep Time) void lcLight::InsertTime(lcStep Start, lcStep Time)
{ {
mPositionKeys.InsertTime(Start, Time); mPositionKeys.InsertTime(Start, Time);
mTargetPositionKeys.InsertTime(Start, Time); mTargetPositionKeys.InsertTime(Start, Time);
mUpVectorKeys.InsertTime(Start, Time); mUpVectorKeys.InsertTime(Start, Time);
mAmbientColorKeys.InsertTime(Start, Time); mColorKeys.InsertTime(Start, Time);
mDiffuseColorKeys.InsertTime(Start, Time);
mSpecularColorKeys.InsertTime(Start, Time);
mAttenuationKeys.InsertTime(Start, Time); mAttenuationKeys.InsertTime(Start, Time);
mLightColorKeys.InsertTime(Start, Time);
mLightFactorKeys.InsertTime(Start, Time); mLightFactorKeys.InsertTime(Start, Time);
mLightDiffuseKeys.InsertTime(Start, Time); mLightDiffuseKeys.InsertTime(Start, Time);
mLightSpecularKeys.InsertTime(Start, Time); mLightSpecularKeys.InsertTime(Start, Time);
@ -867,11 +859,8 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time)
mPositionKeys.RemoveTime(Start, Time); mPositionKeys.RemoveTime(Start, Time);
mTargetPositionKeys.RemoveTime(Start, Time); mTargetPositionKeys.RemoveTime(Start, Time);
mUpVectorKeys.RemoveTime(Start, Time); mUpVectorKeys.RemoveTime(Start, Time);
mAmbientColorKeys.RemoveTime(Start, Time); mColorKeys.RemoveTime(Start, Time);
mDiffuseColorKeys.RemoveTime(Start, Time);
mSpecularColorKeys.RemoveTime(Start, Time);
mAttenuationKeys.RemoveTime(Start, Time); mAttenuationKeys.RemoveTime(Start, Time);
mLightColorKeys.RemoveTime(Start, Time);
mLightFactorKeys.RemoveTime(Start, Time); mLightFactorKeys.RemoveTime(Start, Time);
mLightDiffuseKeys.RemoveTime(Start, Time); mLightDiffuseKeys.RemoveTime(Start, Time);
mLightSpecularKeys.RemoveTime(Start, Time); mLightSpecularKeys.RemoveTime(Start, Time);
@ -888,11 +877,8 @@ void lcLight::UpdatePosition(lcStep Step)
mPosition = mPositionKeys.CalculateKey(Step); mPosition = mPositionKeys.CalculateKey(Step);
mTargetPosition = mTargetPositionKeys.CalculateKey(Step); mTargetPosition = mTargetPositionKeys.CalculateKey(Step);
mUpVector = mUpVectorKeys.CalculateKey(Step); mUpVector = mUpVectorKeys.CalculateKey(Step);
mAmbientColor = mAmbientColorKeys.CalculateKey(Step); mColor = mColorKeys.CalculateKey(Step);
mDiffuseColor = mDiffuseColorKeys.CalculateKey(Step);
mSpecularColor = mSpecularColorKeys.CalculateKey(Step);
mAttenuation = mAttenuationKeys.CalculateKey(Step); mAttenuation = mAttenuationKeys.CalculateKey(Step);
mLightColor = mLightColorKeys.CalculateKey(Step);
mLightFactor = mLightFactorKeys.CalculateKey(Step); mLightFactor = mLightFactorKeys.CalculateKey(Step);
mLightDiffuse = mLightDiffuseKeys.CalculateKey(Step); mLightDiffuse = mLightDiffuseKeys.CalculateKey(Step);
mLightSpecular = mLightSpecularKeys.CalculateKey(Step); mLightSpecular = mLightSpecularKeys.CalculateKey(Step);
@ -1455,21 +1441,12 @@ void lcLight::RemoveKeyFrames()
mUpVectorKeys.RemoveAll(); mUpVectorKeys.RemoveAll();
mUpVectorKeys.ChangeKey(mUpVector, 1, true); mUpVectorKeys.ChangeKey(mUpVector, 1, true);
mAmbientColorKeys.RemoveAll(); mColorKeys.RemoveAll();
mAmbientColorKeys.ChangeKey(mAmbientColor, 1, true); mColorKeys.ChangeKey(mColor, 1, true);
mDiffuseColorKeys.RemoveAll();
mDiffuseColorKeys.ChangeKey(mDiffuseColor, 1, true);
mSpecularColorKeys.RemoveAll();
mSpecularColorKeys.ChangeKey(mSpecularColor, 1, true);
mAttenuationKeys.RemoveAll(); mAttenuationKeys.RemoveAll();
mAttenuationKeys.ChangeKey(mAttenuation, 1, true); mAttenuationKeys.ChangeKey(mAttenuation, 1, true);
mLightColorKeys.RemoveAll();
mLightColorKeys.ChangeKey(mLightColor, 1, true);
mLightFactorKeys.RemoveAll(); mLightFactorKeys.RemoveAll();
mLightFactorKeys.ChangeKey(mLightFactor, 1, true); mLightFactorKeys.ChangeKey(mLightFactor, 1, true);

View file

@ -43,7 +43,6 @@ enum lcLightProperty
{ {
LC_LIGHT_NONE, LC_LIGHT_NONE,
LC_LIGHT_SHAPE, LC_LIGHT_SHAPE,
LC_LIGHT_COLOR,
LC_LIGHT_TYPE, LC_LIGHT_TYPE,
LC_LIGHT_FACTOR, LC_LIGHT_FACTOR,
LC_LIGHT_DIFFUSE, LC_LIGHT_DIFFUSE,
@ -61,7 +60,6 @@ enum lcLightProperty
struct lcLightProperties struct lcLightProperties
{ {
lcVector3 mLightColor;
lcVector2 mLightFactor; lcVector2 mLightFactor;
lcVector2 mAreaGrid; lcVector2 mAreaGrid;
float mLightDiffuse; float mLightDiffuse;
@ -306,7 +304,16 @@ public:
void RemoveTime(lcStep Start, lcStep Time); void RemoveTime(lcStep Start, lcStep Time);
bool IsVisible() const bool IsVisible() const
{ return (mState & LC_LIGHT_HIDDEN) == 0; } {
return (mState & LC_LIGHT_HIDDEN) == 0;
}
void SetColor(const lcVector3& Color, lcStep Step, bool AddKey);
lcVector3 GetColor() const
{
return mColor;
}
void SetName(const QString& Name) void SetName(const QString& Name)
{ {
@ -327,7 +334,6 @@ public:
lcLightProperties GetLightProperties() const lcLightProperties GetLightProperties() const
{ {
lcLightProperties props; lcLightProperties props;
props.mLightColor = mLightColor;
props.mLightFactor = mLightFactor; props.mLightFactor = mLightFactor;
props.mLightDiffuse = mLightDiffuse; props.mLightDiffuse = mLightDiffuse;
props.mLightSpecular = mLightSpecular; props.mLightSpecular = mLightSpecular;
@ -349,11 +355,7 @@ public:
lcVector3 mTargetPosition; lcVector3 mTargetPosition;
lcVector3 mUpVector; lcVector3 mUpVector;
lcVector4 mAmbientColor;
lcVector4 mDiffuseColor;
lcVector4 mSpecularColor;
lcVector3 mAttenuation; lcVector3 mAttenuation;
lcVector3 mLightColor;
lcVector2 mLightFactor; lcVector2 mLightFactor;
lcVector2 mAreaGrid; lcVector2 mAreaGrid;
lcVector2 mAreaSize; lcVector2 mAreaSize;
@ -375,15 +377,14 @@ public:
QString mName; QString mName;
protected: protected:
lcVector3 mColor;
lcObjectKeyArray<lcVector3> mPositionKeys; lcObjectKeyArray<lcVector3> mPositionKeys;
lcObjectKeyArray<lcVector3> mTargetPositionKeys; lcObjectKeyArray<lcVector3> mTargetPositionKeys;
lcObjectKeyArray<lcVector3> mUpVectorKeys; lcObjectKeyArray<lcVector3> mUpVectorKeys;
lcObjectKeyArray<lcVector3> mColorKeys;
lcObjectKeyArray<lcVector4> mAmbientColorKeys;
lcObjectKeyArray<lcVector4> mDiffuseColorKeys;
lcObjectKeyArray<lcVector4> mSpecularColorKeys;
lcObjectKeyArray<lcVector3> mAttenuationKeys; lcObjectKeyArray<lcVector3> mAttenuationKeys;
lcObjectKeyArray<lcVector3> mLightColorKeys;
lcObjectKeyArray<lcVector2> mLightFactorKeys; lcObjectKeyArray<lcVector2> mLightFactorKeys;
lcObjectKeyArray<lcVector2> mAreaGridKeys; lcObjectKeyArray<lcVector2> mAreaGridKeys;
lcObjectKeyArray<float> mLightSpecularKeys; lcObjectKeyArray<float> mLightSpecularKeys;

View file

@ -2175,7 +2175,7 @@ bool Project::ExportPOVRay(const QString& FileName)
const QString LightName = QString(Light->mName).replace(" ","_"); const QString LightName = QString(Light->mName).replace(" ","_");
LightType = Light->GetLightType(); LightType = Light->GetLightType();
Shadowless = static_cast<int>(Light->mShadowless); Shadowless = static_cast<int>(Light->mShadowless);
LightColor = Light->mLightColor; LightColor = Light->GetColor();
Power = Light->mPOVRayExponent; Power = Light->mPOVRayExponent;
switch(LightType) switch(LightType)
{ {

View file

@ -222,9 +222,9 @@ lcQPropertiesTree::lcQPropertiesTree(QWidget *parent) :
m_checkedIcon = drawCheckBox(true); m_checkedIcon = drawCheckBox(true);
m_uncheckedIcon = drawCheckBox(false); m_uncheckedIcon = drawCheckBox(false);
m_delegate = new lcQPropertiesTreeDelegate(parent); mDelegate = new lcQPropertiesTreeDelegate(parent);
m_delegate->setTreeWidget(this); mDelegate->setTreeWidget(this);
setItemDelegate(m_delegate); setItemDelegate(mDelegate);
SetEmpty(); SetEmpty();
@ -264,7 +264,7 @@ void lcQPropertiesTree::keyPressEvent(QKeyEvent *event)
case Qt::Key_Return: case Qt::Key_Return:
case Qt::Key_Enter: case Qt::Key_Enter:
case Qt::Key_Space: // Trigger Edit case Qt::Key_Space: // Trigger Edit
if (!m_delegate->editedItem()) if (!mDelegate->editedItem())
{ {
if (const QTreeWidgetItem *item = currentItem()) if (const QTreeWidgetItem *item = currentItem())
{ {
@ -299,7 +299,7 @@ void lcQPropertiesTree::mousePressEvent(QMouseEvent *event)
if (item) if (item)
{ {
if ((item != m_delegate->editedItem()) && (event->button() == Qt::LeftButton) && (header()->logicalIndexAt(event->pos().x()) == 1) && if ((item != mDelegate->editedItem()) && (event->button() == Qt::LeftButton) && (header()->logicalIndexAt(event->pos().x()) == 1) &&
((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled)))
editItem(item, 1); editItem(item, 1);
} }
@ -567,14 +567,14 @@ QWidget *lcQPropertiesTree::createEditor(QWidget *parent, QTreeWidgetItem *item)
case PropertyLightColor: case PropertyLightColor:
{ {
QPushButton *editor = new QPushButton(parent); QPushButton *Editor = new QPushButton(parent);
QColor value = item->data(0, PropertyValueRole).value<QColor>(); QColor Value = item->data(0, PropertyValueRole).value<QColor>();
updateLightColorEditor(editor, value); UpdateLightColorEditor(Editor, Value);
connect(editor, SIGNAL(clicked()), this, SLOT(slotColorButtonClicked())); connect(Editor, &QPushButton::clicked, this, &lcQPropertiesTree::LightColorButtonClicked);
return editor; return Editor;
} }
case PropertyColor: case PropertyColor:
@ -649,26 +649,26 @@ void lcQPropertiesTree::updateColorEditor(QPushButton *editor, int value) const
editor->setText(color->Name); editor->setText(color->Name);
} }
void lcQPropertiesTree::updateLightColorEditor(QPushButton *editor, QColor color) const void lcQPropertiesTree::UpdateLightColorEditor(QPushButton* Editor, QColor Color) const
{ {
QImage img(12, 12, QImage::Format_ARGB32); QImage Image(12, 12, QImage::Format_ARGB32);
img.fill(0); Image.fill(0);
QPainter painter(&img); QPainter Painter(&Image);
painter.setCompositionMode(QPainter::CompositionMode_Source); Painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.setPen(Qt::darkGray); Painter.setPen(Qt::darkGray);
painter.setBrush(color); Painter.setBrush(Color);
painter.drawRect(0, 0, img.width() - 1, img.height() - 1); Painter.drawRect(0, 0, Image.width() - 1, Image.height() - 1);
painter.end(); Painter.end();
editor->setStyleSheet("Text-align:left"); Editor->setStyleSheet("Text-align:left");
editor->setIcon(QPixmap::fromImage(img)); Editor->setIcon(QPixmap::fromImage(Image));
editor->setText(color.name().toUpper()); Editor->setText(Color.name().toUpper());
} }
void lcQPropertiesTree::slotToggled(bool Value) void lcQPropertiesTree::slotToggled(bool Value)
{ {
QTreeWidgetItem* Item = m_delegate->editedItem(); QTreeWidgetItem* Item = mDelegate->editedItem();
lcModel* Model = gMainWindow->GetActiveModel(); lcModel* Model = gMainWindow->GetActiveModel();
lcObject* Focus = Model->GetFocusObject(); lcObject* Focus = Model->GetFocusObject();
@ -708,7 +708,7 @@ void lcQPropertiesTree::slotToggled(bool Value)
void lcQPropertiesTree::slotReturnPressed() void lcQPropertiesTree::slotReturnPressed()
{ {
QLineEdit* Editor = (QLineEdit*)sender(); QLineEdit* Editor = (QLineEdit*)sender();
QTreeWidgetItem* Item = m_delegate->editedItem(); QTreeWidgetItem* Item = mDelegate->editedItem();
lcModel* Model = gMainWindow->GetActiveModel(); lcModel* Model = gMainWindow->GetActiveModel();
if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE) if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE)
@ -905,15 +905,17 @@ void lcQPropertiesTree::slotReturnPressed()
} }
else if (Item == lightColorR || Item == lightColorG || Item == lightColorB) else if (Item == lightColorR || Item == lightColorG || Item == lightColorB)
{ {
lcVector3 Color = Light->GetColor();
float Value = lcParseValueLocalized(Editor->text()); float Value = lcParseValueLocalized(Editor->text());
if (Item == lightColorR)
Props.mLightColor[0] = Value;
else if (Item == lightColorG)
Props.mLightColor[2] = Value;
else if (Item == lightColorB)
Props.mLightColor[1] = Value;
Model->UpdateLight(Light, Props, LC_LIGHT_COLOR); if (Item == lightColorR)
Color[0] = Value;
else if (Item == lightColorG)
Color[2] = Value;
else if (Item == lightColorB)
Color[1] = Value;
Model->SetLightColor(Light, Color);
} }
else if (Item == lightFactorA || Item == lightFactorB) else if (Item == lightFactorA || Item == lightFactorB)
{ {
@ -991,7 +993,7 @@ void lcQPropertiesTree::slotReturnPressed()
void lcQPropertiesTree::slotSetValue(int Value) void lcQPropertiesTree::slotSetValue(int Value)
{ {
QTreeWidgetItem* Item = m_delegate->editedItem(); QTreeWidgetItem* Item = mDelegate->editedItem();
lcModel* Model = gMainWindow->GetActiveModel(); lcModel* Model = gMainWindow->GetActiveModel();
if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE) if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE)
@ -1000,7 +1002,7 @@ void lcQPropertiesTree::slotSetValue(int Value)
{ {
Model->SetSelectedPiecesColorIndex(Value); Model->SetSelectedPiecesColorIndex(Value);
QPushButton *editor = (QPushButton*)m_delegate->editor(); QPushButton *editor = (QPushButton*)mDelegate->editor();
updateColorEditor(editor, Value); updateColorEditor(editor, Value);
} }
else if (Item == partID) else if (Item == partID)
@ -1041,24 +1043,6 @@ void lcQPropertiesTree::slotSetValue(int Value)
} }
} }
void lcQPropertiesTree::slotSetColorValue(QColor Value)
{
lcModel* Model = gMainWindow->GetActiveModel();
lcObject* Focus = Model->GetFocusObject();
lcLight* Light = (Focus && Focus->IsLight()) ? (lcLight*)Focus : nullptr;
if (Light)
{
float r = Value.red();
float g = Value.green();
float b = Value.blue();
lcVector3 Color(r/255, g/255, b/255);
lcLightProperties Props = Light->GetLightProperties();
Props.mLightColor = Color;
Model->UpdateLight(Light, Props, LC_LIGHT_COLOR);
}
}
void lcQPropertiesTree::slotColorButtonClicked() void lcQPropertiesTree::slotColorButtonClicked()
{ {
int ColorIndex = gDefaultColor; int ColorIndex = gDefaultColor;
@ -1104,6 +1088,28 @@ void lcQPropertiesTree::slotColorButtonClicked()
Popup->show(); Popup->show();
} }
void lcQPropertiesTree::LightColorButtonClicked()
{
lcModel* Model = gMainWindow->GetActiveModel();
lcObject* Focus = Model->GetFocusObject();
lcLight* Light = (Focus && Focus->IsLight()) ? (lcLight*)Focus : nullptr;
if (!Light)
return;
QColor Color = QColorDialog::getColor(lcQColorFromVector3(Light->GetColor()), this, tr("Select Light Color"));
if (!Color.isValid())
return;
Model->SetLightColor(Light, lcVector3FromQColor(Color));
QPushButton* Editor = qobject_cast<QPushButton*>(mDelegate->editor());
if (Editor)
UpdateLightColorEditor(Editor, Color);
}
QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType) QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType)
{ {
QTreeWidgetItem *newItem; QTreeWidgetItem *newItem;
@ -1452,7 +1458,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
PropertyType SpotSizeProperty = PropertyFloatLightSpotSize; PropertyType SpotSizeProperty = PropertyFloatLightSpotSize;
lcVector3 Position(0.0f, 0.0f, 0.0f); lcVector3 Position(0.0f, 0.0f, 0.0f);
lcVector3 Target(0.0f, 0.0f, 0.0f); lcVector3 Target(0.0f, 0.0f, 0.0f);
lcVector3 Color(0.0f, 0.0f, 0.0f); QColor Color(Qt::white);
lcVector2 Factor(0.0f, 0.0f); lcVector2 Factor(0.0f, 0.0f);
lcVector2 AreaGrid(0.0f, 0.0f); lcVector2 AreaGrid(0.0f, 0.0f);
@ -1467,7 +1473,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
Shadowless = Light->mShadowless; Shadowless = Light->mShadowless;
Position = Light->mPosition; Position = Light->mPosition;
Target = Light->mTargetPosition; Target = Light->mTargetPosition;
Color = Light->mLightColor; Color = lcQColorFromVector3(Light->GetColor());
Factor = Light->mLightFactor; Factor = Light->mLightFactor;
LightType = Light->GetLightType(); LightType = Light->GetLightType();
@ -1594,9 +1600,9 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
lightTargetZ = addProperty(lightTarget, tr("Z"), TargetProperty); lightTargetZ = addProperty(lightTarget, tr("Z"), TargetProperty);
} }
// Light Colour // Light Color
lightColor = addProperty(nullptr, tr("Color"), PropertyGroup); lightColor = addProperty(nullptr, tr("Color"), PropertyGroup);
lightColorIcon = addProperty(lightColor, tr("Name"), PropertyLightColor); lightColorIcon = addProperty(lightColor, tr("Value"), PropertyLightColor);
lightColorR = addProperty(lightColor, tr("Red"), PropertyFloat); lightColorR = addProperty(lightColor, tr("Red"), PropertyFloat);
lightColorG = addProperty(lightColor, tr("Green"), PropertyFloat); lightColorG = addProperty(lightColor, tr("Green"), PropertyFloat);
lightColorB = addProperty(lightColor, tr("Blue"), PropertyFloat); lightColorB = addProperty(lightColor, tr("Blue"), PropertyFloat);
@ -1679,30 +1685,28 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
lightTargetZ->setData(0, PropertyValueRole, Target[2]); lightTargetZ->setData(0, PropertyValueRole, Target[2]);
} }
QImage img(16, 16, QImage::Format_ARGB32); QImage ColorImage(16, 16, QImage::Format_ARGB32);
img.fill(0); ColorImage.fill(0);
QColor RgbColor = QColor::fromRgb(int(Color[1]*255), int(Color[1]*255), int(Color[2]*255)); QPainter painter(&ColorImage);
QPainter painter(&img);
painter.setCompositionMode(QPainter::CompositionMode_Source); painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.setPen(Qt::darkGray); painter.setPen(Qt::darkGray);
painter.setBrush(RgbColor); painter.setBrush(Color);
painter.drawRect(0, 0, img.width() - 1, img.height() - 1); painter.drawRect(0, 0, ColorImage.width() - 1, ColorImage.height() - 1);
painter.end(); painter.end();
lightColorIcon->setIcon(1, QIcon(QPixmap::fromImage(img))); lightColorIcon->setIcon(1, QIcon(QPixmap::fromImage(ColorImage)));
lightColorIcon->setText(1, RgbColor.name().toUpper()); lightColorIcon->setText(1, Color.name().toUpper());
lightColorIcon->setData(0, PropertyValueRole, RgbColor); lightColorIcon->setData(0, PropertyValueRole, Color);
lightColorR->setText(1, lcFormatValueLocalized(Color[0])); lightColorR->setText(1, lcFormatValueLocalized(Color.redF()));
lightColorR->setData(0, PropertyValueRole, Color[0]); lightColorR->setData(0, PropertyValueRole, Color.redF());
lightColorR->setToolTip(1, tr("Red color using 0 to 1 decimal.")); lightColorR->setToolTip(1, tr("Red color using 0 to 1 decimal."));
lightColorG->setText(1, lcFormatValueLocalized(Color[1])); lightColorG->setText(1, lcFormatValueLocalized(Color.greenF()));
lightColorG->setData(0, PropertyValueRole, Color[1]); lightColorG->setData(0, PropertyValueRole, Color.greenF());
lightColorG->setToolTip(1, tr("Green color using 0 to 1 decimal.")); lightColorG->setToolTip(1, tr("Green color using 0 to 1 decimal."));
lightColorB->setText(1, lcFormatValueLocalized(Color[2])); lightColorB->setText(1, lcFormatValueLocalized(Color.blueF()));
lightColorB->setData(0, PropertyValueRole, Color[2]); lightColorB->setData(0, PropertyValueRole, Color.blueF());
lightColorB->setToolTip(1, tr("Blue color using 0 to 1 decimal.")); lightColorB->setToolTip(1, tr("Blue color using 0 to 1 decimal."));
lightFormat->setText(1, Format); lightFormat->setText(1, Format);

View file

@ -62,14 +62,14 @@ protected slots:
void slotReturnPressed(); void slotReturnPressed();
void slotSetValue(int value); void slotSetValue(int value);
void slotColorButtonClicked(); void slotColorButtonClicked();
void slotSetColorValue(QColor Value); void LightColorButtonClicked();
protected: protected:
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void updateColorEditor(QPushButton *editor, int value) const; void updateColorEditor(QPushButton *editor, int value) const;
void updateLightColorEditor(QPushButton *editor, QColor color) const; void UpdateLightColorEditor(QPushButton* Editor, QColor Color) const;
QTreeWidgetItem *addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType); QTreeWidgetItem *addProperty(QTreeWidgetItem *parent, const QString& label, PropertyType propertyType);
@ -79,8 +79,6 @@ protected:
void SetLight(lcObject* Focus); void SetLight(lcObject* Focus);
void SetMultiple(); void SetMultiple();
void getPartProperties(lcPartProperties *properties);
lcLightType mLightType; lcLightType mLightType;
int mLightShape; int mLightShape;
bool mPOVRayLight; bool mPOVRayLight;
@ -88,7 +86,7 @@ protected:
lcPropertyWidgetMode mWidgetMode; lcPropertyWidgetMode mWidgetMode;
lcObject* mFocus; lcObject* mFocus;
lcQPropertiesTreeDelegate *m_delegate; lcQPropertiesTreeDelegate* mDelegate;
QIcon m_expandIcon; QIcon m_expandIcon;
QIcon m_checkedIcon; QIcon m_checkedIcon;
QIcon m_uncheckedIcon; QIcon m_uncheckedIcon;