Customizable PLI.

This commit is contained in:
Leonardo Zide 2021-01-16 14:43:24 -08:00
parent 19e439c32b
commit 61517b21d0
8 changed files with 131 additions and 34 deletions

View file

@ -17,6 +17,10 @@
#include <functional>
#include <memory>
#if _MSC_VER
#pragma warning(default : 4062) // enumerator 'identifier' in switch of enum 'enumeration' is not handled
#endif
#ifndef Q_FALLTHROUGH
#define Q_FALLTHROUGH();
#endif

View file

@ -24,8 +24,14 @@ lcInstructions::lcInstructions(Project* Project)
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepNumberFont)].Value = QFont("Arial", 72).toString();
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepNumberColor)].Value = LC_RGBA(0, 0, 0, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepBackgroundColor)].Value = LC_RGBA(255, 255, 255, 0);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBackgroundColor)].Value = LC_RGBA(255, 255, 255, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIFont)].Value = QFont("Arial", 20, QFont::Bold).toString();
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLITextColor)].Value = LC_RGBA(0, 0, 0, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderColor)].Value = LC_RGBA(0, 0, 0, 255);
// mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderWidth)].Value = 2.0f;
// mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderRound)].Value = true;
static_assert(static_cast<int>(lcInstructionsPropertyType::Count) == 3, "Missing default property");
static_assert(static_cast<int>(lcInstructionsPropertyType::Count) == 7, "Missing default property");
CreatePages();
}

View file

@ -39,6 +39,13 @@ enum class lcInstructionsPropertyType
StepNumberFont,
StepNumberColor,
StepBackgroundColor,
PLIBackgroundColor,
PLIFont,
PLITextColor,
PLIBorderColor,
// PLIBorderWidth,
// PLIBorderRound,
// pli: spacing and margins, text alignment
Count
};

View file

@ -42,6 +42,22 @@ void lcInstructionsStepNumberItem::Update()
setText(QString::number(mStep));
}
lcInstructionsPartsListItem::lcInstructionsPartsListItem(QGraphicsItem* Parent, lcInstructions* Instructions, lcModel* Model, lcStep Step)
: QGraphicsPixmapItem(Parent), mInstructions(Instructions), mModel(Model), mStep(Step)
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
}
void lcInstructionsPartsListItem::Update()
{
QColor BackgroundColor = mInstructions->GetColorProperty(lcInstructionsPropertyType::PLIBackgroundColor, mModel, mStep);
QFont Font = mInstructions->GetFontProperty(lcInstructionsPropertyType::PLIFont, mModel, mStep);
QColor TextColor = mInstructions->GetColorProperty(lcInstructionsPropertyType::PLITextColor, mModel, mStep);
QImage PartsImage = mModel->GetPartsListImage(300, mStep, lcRGBAFromQColor(BackgroundColor), Font, TextColor);
setPixmap(QPixmap::fromImage(PartsImage));
}
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget)
: QGraphicsView(Parent), mInstructions(Instructions), mPropertiesWidget(PropertiesWidget)
{
@ -79,6 +95,16 @@ void lcInstructionsPageWidget::StepSettingsChanged(lcModel* Model, lcStep Step)
continue;
}
lcInstructionsPartsListItem* PartsItem = dynamic_cast<lcInstructionsPartsListItem*>(Item);
if (PartsItem)
{
if (!Model || (PartsItem->GetModel() == Model && PartsItem->GetStep() == Step))
PartsItem->Update();
continue;
}
}
}
@ -125,11 +151,9 @@ void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
lcInstructionsStepNumberItem* StepNumberItem = new lcInstructionsStepNumberItem(StepImageItem, mInstructions, Step.Model, Step.Step);
StepNumberItem->Update();
QImage PartsImage = Step.Model->GetPartsListImage(300, Step.Step);
QGraphicsPixmapItem* PartsImageItem = new QGraphicsPixmapItem(QPixmap::fromImage(PartsImage), StepImageItem);
PartsImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
lcInstructionsPartsListItem* PartsImageItem = new lcInstructionsPartsListItem(StepImageItem, mInstructions, Step.Model, Step.Step);
PartsImageItem->setPos(StepNumberItem->boundingRect().topRight());
PartsImageItem->Update();
}
}
@ -277,17 +301,24 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType
switch (Type)
{
case lcInstructionsPropertyType::StepNumberFont:
break;
case lcInstructionsPropertyType::StepNumberColor:
Label = tr("Color:");
case lcInstructionsPropertyType::PLITextColor:
Label = tr("Text Color:");
break;
case lcInstructionsPropertyType::StepBackgroundColor:
case lcInstructionsPropertyType::PLIBackgroundColor:
Label = tr("Background Color:");
break;
case lcInstructionsPropertyType::PLIBorderColor:
Label = tr("Border Color:");
break;
case lcInstructionsPropertyType::StepNumberFont:
case lcInstructionsPropertyType::PLIFont:
// case lcInstructionsPropertyType::PLIBorderWidth:
// case lcInstructionsPropertyType::PLIBorderRound:
case lcInstructionsPropertyType::Count:
break;
}
@ -315,9 +346,6 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType
switch (Type)
{
case lcInstructionsPropertyType::StepNumberFont:
break;
case lcInstructionsPropertyType::StepNumberColor:
Title = tr("Select Step Number Color");
break;
@ -326,6 +354,22 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType
Title = tr("Select Step Background Color");
break;
case lcInstructionsPropertyType::PLIBackgroundColor:
Title = tr("Select Parts List Background Color");
break;
case lcInstructionsPropertyType::PLIBorderColor:
Title = tr("Select Parts List Border Color");
break;
case lcInstructionsPropertyType::PLITextColor:
Title = tr("Select Parts List Text Color");
break;
case lcInstructionsPropertyType::StepNumberFont:
case lcInstructionsPropertyType::PLIFont:
// case lcInstructionsPropertyType::StepPLIBorderWidth:
// case lcInstructionsPropertyType::StepPLIBorderRound:
case lcInstructionsPropertyType::Count:
break;
}
@ -343,20 +387,7 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType
void lcInstructionsPropertiesWidget::AddFontProperty(lcInstructionsPropertyType Type)
{
QString Label;
switch (Type)
{
case lcInstructionsPropertyType::StepNumberFont:
Label = tr("Font:");
break;
case lcInstructionsPropertyType::StepNumberColor:
case lcInstructionsPropertyType::StepBackgroundColor:
case lcInstructionsPropertyType::Count:
break;
}
const QString Label = tr("Font:");
const int Row = mPropertiesLayout->rowCount();
mPropertiesLayout->addWidget(new QLabel(Label), Row, 0);
@ -383,21 +414,28 @@ void lcInstructionsPropertiesWidget::AddFontProperty(lcInstructionsPropertyType
Title = tr("Select Step Number Font");
break;
case lcInstructionsPropertyType::PLIFont:
Title = tr("Select Parts List Font");
break;
case lcInstructionsPropertyType::StepNumberColor:
case lcInstructionsPropertyType::StepBackgroundColor:
case lcInstructionsPropertyType::PLIBackgroundColor:
case lcInstructionsPropertyType::PLITextColor:
case lcInstructionsPropertyType::PLIBorderColor:
case lcInstructionsPropertyType::Count:
break;
}
bool Ok = false;
QFont Font = mInstructions->GetFontProperty(lcInstructionsPropertyType::StepNumberFont, mModel, mStep);
QFont Font = mInstructions->GetFontProperty(Type, mModel, mStep);
Font = QFontDialog::getFont(&Ok, Font, this, tr("Select Step Number Font"));
if (Ok)
{
UpdateButton();
mInstructions->SetDefaultFont(lcInstructionsPropertyType::StepNumberFont, Font);
mInstructions->SetDefaultFont(Type, Font);
}
});
}
@ -455,6 +493,25 @@ void lcInstructionsPropertiesWidget::SelectionChanged(QGraphicsItem* FocusItem)
return;
}
lcInstructionsPartsListItem* PartsItem = dynamic_cast<lcInstructionsPartsListItem*>(FocusItem);
if (PartsItem)
{
CreatePropertyWidget(tr("Parts List Properties"));
mModel = PartsItem->GetModel();
mStep = PartsItem->GetStep();
AddColorProperty(lcInstructionsPropertyType::PLIBackgroundColor);
AddFontProperty(lcInstructionsPropertyType::PLIFont);
AddColorProperty(lcInstructionsPropertyType::PLITextColor);
AddColorProperty(lcInstructionsPropertyType::PLIBorderColor);
// PLIBorderWidth,
// PLIBorderRound,
return;
}
}
lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project)

View file

@ -58,6 +58,29 @@ protected:
lcStep mStep = 1;
};
class lcInstructionsPartsListItem : public QGraphicsPixmapItem
{
public:
lcInstructionsPartsListItem(QGraphicsItem* Parent, lcInstructions* Instructions, lcModel* Model, lcStep Step);
lcModel* GetModel() const
{
return mModel;
}
lcStep GetStep() const
{
return mStep;
}
void Update();
protected:
lcInstructions* mInstructions = nullptr;
lcModel* mModel = nullptr;
lcStep mStep = 1;
};
class lcInstructionsPageWidget : public QGraphicsView
{
Q_OBJECT

View file

@ -1280,7 +1280,7 @@ QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
return Image;
}
QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const
QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundColor, QFont Font, QColor TextColor) const
{
lcPartsList PartsList;
@ -1379,7 +1379,7 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const
for (lcPartsListImage& Image : Images)
{
Context->ClearColorAndDepth(lcVector4(1.0f, 1.0f, 1.0f, 0.0f));
Context->ClearColorAndDepth(lcVector4(lcVector3FromColor(BackgroundColor), 0.0f));
lcScene Scene;
@ -1437,7 +1437,6 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const
QImage DummyImage(16, 16, QImage::Format_ARGB32);
QPainter DummyPainter(&DummyImage);
QFont Font("helvetica", 20, QFont::Bold);
DummyPainter.setFont(Font);
QFontMetrics FontMetrics = DummyPainter.fontMetrics();
int Ascent = FontMetrics.ascent();
@ -1485,10 +1484,11 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const
}
QImage PainterImage(ImageWidth + 40, CurrentHeight + 40, QImage::Format_ARGB32);
PainterImage.fill(QColor(255, 255, 255, 0));
PainterImage.fill(lcQColorFromRGBA(BackgroundColor));
QPainter Painter(&PainterImage);
Painter.setFont(Font);
Painter.setPen(TextColor);
for (lcPartsListImage& Image : Images)
{

View file

@ -232,7 +232,7 @@ public:
void GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const;
void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step);
QImage GetPartsListImage(int MaxWidth, lcStep Step) const;
QImage GetPartsListImage(int MaxWidth, lcStep Step, quint32 BackgroundColor, QFont Font, QColor TextColor) const;
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End);
void RayTest(lcObjectRayTest& ObjectRayTest) const;

View file

@ -1533,7 +1533,7 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
auto AddPartsListImage = [&Dir](QTextStream& Stream, lcModel* Model, lcStep Step, const QString& BaseName)
{
QImage Image = Model->GetPartsListImage(1024, Step);
QImage Image = Model->GetPartsListImage(1024, Step, LC_RGBA(255, 255, 255, 0), QFont("Arial", 20, QFont::Bold), Qt::black);
if (!Image.isNull())
{