From 61517b21d0026e6a9bc0623559f4f00bc478a8fd Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 16 Jan 2021 14:43:24 -0800 Subject: [PATCH] Customizable PLI. --- common/lc_global.h | 4 ++ common/lc_instructions.cpp | 8 ++- common/lc_instructions.h | 7 ++ common/lc_instructionsdialog.cpp | 111 +++++++++++++++++++++++-------- common/lc_instructionsdialog.h | 23 +++++++ common/lc_model.cpp | 8 +-- common/lc_model.h | 2 +- common/project.cpp | 2 +- 8 files changed, 131 insertions(+), 34 deletions(-) diff --git a/common/lc_global.h b/common/lc_global.h index c8f2b614..56429013 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -17,6 +17,10 @@ #include #include +#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 diff --git a/common/lc_instructions.cpp b/common/lc_instructions.cpp index a4199ac3..201ed45c 100644 --- a/common/lc_instructions.cpp +++ b/common/lc_instructions.cpp @@ -24,8 +24,14 @@ lcInstructions::lcInstructions(Project* Project) mStepProperties[static_cast(lcInstructionsPropertyType::StepNumberFont)].Value = QFont("Arial", 72).toString(); mStepProperties[static_cast(lcInstructionsPropertyType::StepNumberColor)].Value = LC_RGBA(0, 0, 0, 255); mStepProperties[static_cast(lcInstructionsPropertyType::StepBackgroundColor)].Value = LC_RGBA(255, 255, 255, 0); + mStepProperties[static_cast(lcInstructionsPropertyType::PLIBackgroundColor)].Value = LC_RGBA(255, 255, 255, 255); + mStepProperties[static_cast(lcInstructionsPropertyType::PLIFont)].Value = QFont("Arial", 20, QFont::Bold).toString(); + mStepProperties[static_cast(lcInstructionsPropertyType::PLITextColor)].Value = LC_RGBA(0, 0, 0, 255); + mStepProperties[static_cast(lcInstructionsPropertyType::PLIBorderColor)].Value = LC_RGBA(0, 0, 0, 255); +// mStepProperties[static_cast(lcInstructionsPropertyType::PLIBorderWidth)].Value = 2.0f; +// mStepProperties[static_cast(lcInstructionsPropertyType::PLIBorderRound)].Value = true; - static_assert(static_cast(lcInstructionsPropertyType::Count) == 3, "Missing default property"); + static_assert(static_cast(lcInstructionsPropertyType::Count) == 7, "Missing default property"); CreatePages(); } diff --git a/common/lc_instructions.h b/common/lc_instructions.h index a40e0bb1..d77f78f3 100644 --- a/common/lc_instructions.h +++ b/common/lc_instructions.h @@ -39,6 +39,13 @@ enum class lcInstructionsPropertyType StepNumberFont, StepNumberColor, StepBackgroundColor, + PLIBackgroundColor, + PLIFont, + PLITextColor, + PLIBorderColor, +// PLIBorderWidth, +// PLIBorderRound, + // pli: spacing and margins, text alignment Count }; diff --git a/common/lc_instructionsdialog.cpp b/common/lc_instructionsdialog.cpp index 15fc9a25..d93ad910 100644 --- a/common/lc_instructionsdialog.cpp +++ b/common/lc_instructionsdialog.cpp @@ -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(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(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) diff --git a/common/lc_instructionsdialog.h b/common/lc_instructionsdialog.h index e64031ba..571f7918 100644 --- a/common/lc_instructionsdialog.h +++ b/common/lc_instructionsdialog.h @@ -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 diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 28886121..d542ae78 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -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) { diff --git a/common/lc_model.h b/common/lc_model.h index 2f4fd7ed..d65549cc 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -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; diff --git a/common/project.cpp b/common/project.cpp index 5c22a042..f5c306b4 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -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()) {