From cc75291125319003ec95020e84d5b2430050ed77 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 17 Jan 2021 11:05:50 -0800 Subject: [PATCH] Added number and PLI toggles. --- common/lc_instructions.cpp | 44 ++++++++++++++++++++++- common/lc_instructions.h | 7 ++++ common/lc_instructionsdialog.cpp | 61 ++++++++++++++++++-------------- common/lc_instructionsdialog.h | 1 + 4 files changed, 85 insertions(+), 28 deletions(-) diff --git a/common/lc_instructions.cpp b/common/lc_instructions.cpp index cb7488cc..8596ffa2 100644 --- a/common/lc_instructions.cpp +++ b/common/lc_instructions.cpp @@ -21,6 +21,8 @@ lcInstructions::lcInstructions(Project* Project) mPageSettings.Columns = 1; mPageSettings.Direction = lcInstructionsDirection::Horizontal; + mStepProperties[static_cast(lcInstructionsPropertyType::ShowStepNumber)].Value = true; + mStepProperties[static_cast(lcInstructionsPropertyType::ShowStepPLI)].Value = true; 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); @@ -31,11 +33,40 @@ lcInstructions::lcInstructions(Project* Project) // mStepProperties[static_cast(lcInstructionsPropertyType::PLIBorderWidth)].Value = 2.0f; // mStepProperties[static_cast(lcInstructionsPropertyType::PLIBorderRound)].Value = true; - static_assert(static_cast(lcInstructionsPropertyType::Count) == 7, "Missing default property"); + static_assert(static_cast(lcInstructionsPropertyType::Count) == 9, "Missing default property"); CreatePages(); } +QString lcInstructions::GetPropertyLabel(lcInstructionsPropertyType Type) +{ + switch (Type) + { + case lcInstructionsPropertyType::ShowStepNumber: + return tr("Show Step Number"); + case lcInstructionsPropertyType::ShowStepPLI: + return tr("Show Parts List"); + case lcInstructionsPropertyType::StepNumberFont: + return tr("Font:"); + case lcInstructionsPropertyType::StepNumberColor: + return tr("Text Color:"); + case lcInstructionsPropertyType::StepBackgroundColor: + return tr("Background Color:"); + case lcInstructionsPropertyType::PLIBackgroundColor: + return tr("Background Color:"); + case lcInstructionsPropertyType::PLIFont: + return tr("Font:"); + case lcInstructionsPropertyType::PLITextColor: + return tr("Text Color:"); + case lcInstructionsPropertyType::PLIBorderColor: + return tr("Border Color:"); + case lcInstructionsPropertyType::Count: + break; + } + + return QString(); +} + void lcInstructions::SetDefaultPageSettings(const lcInstructionsPageSettings& PageSettings) { mPageSettings = PageSettings; @@ -43,6 +74,12 @@ void lcInstructions::SetDefaultPageSettings(const lcInstructionsPageSettings& Pa CreatePages(); } +bool lcInstructions::GetBoolProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const +{ + QVariant Value = GetProperty(Type, Model, Step); + return Value.toBool(); +} + QColor lcInstructions::GetColorProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const { QVariant Value = GetProperty(Type, Model, Step); @@ -82,6 +119,11 @@ QVariant lcInstructions::GetProperty(lcInstructionsPropertyType Type, lcModel* M return Value; } +void lcInstructions::SetDefaultBool(lcInstructionsPropertyType Type, bool Enabled) +{ + SetDefaultProperty(Type, Enabled); +} + void lcInstructions::SetDefaultColor(lcInstructionsPropertyType Type, const QColor& Color) { SetDefaultProperty(Type, lcRGBAFromQColor(Color)); diff --git a/common/lc_instructions.h b/common/lc_instructions.h index d77f78f3..d63ba24d 100644 --- a/common/lc_instructions.h +++ b/common/lc_instructions.h @@ -36,6 +36,8 @@ enum class lcInstructionsPropertyMode enum class lcInstructionsPropertyType { + ShowStepNumber, + ShowStepPLI, StepNumberFont, StepNumberColor, StepBackgroundColor, @@ -84,14 +86,19 @@ class lcInstructions : public QObject public: lcInstructions(Project* Project = nullptr); + static QString GetPropertyLabel(lcInstructionsPropertyType Type); + void SetDefaultPageSettings(const lcInstructionsPageSettings& PageSettings); + bool GetBoolProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const; QColor GetColorProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const; QFont GetFontProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const; + void SetDefaultBool(lcInstructionsPropertyType Type, bool Enabled); void SetDefaultColor(lcInstructionsPropertyType Type, const QColor& Color); void SetDefaultFont(lcInstructionsPropertyType Type, const QFont& Font); +//protected: std::vector mPages; lcInstructionsPageSettings mPageSettings; lcInstructionsPageSetup mPageSetup; diff --git a/common/lc_instructionsdialog.cpp b/common/lc_instructionsdialog.cpp index d93ad910..068f775d 100644 --- a/common/lc_instructionsdialog.cpp +++ b/common/lc_instructionsdialog.cpp @@ -35,6 +35,9 @@ lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(QGraphicsItem* Parent void lcInstructionsStepNumberItem::Update() { + bool Visible = mInstructions->GetBoolProperty(lcInstructionsPropertyType::ShowStepNumber, mModel, mStep); + setVisible(Visible); + QFont StepNumberFont = mInstructions->GetFontProperty(lcInstructionsPropertyType::StepNumberFont, mModel, mStep); setFont(StepNumberFont); @@ -50,6 +53,12 @@ lcInstructionsPartsListItem::lcInstructionsPartsListItem(QGraphicsItem* Parent, void lcInstructionsPartsListItem::Update() { + bool Visible = mInstructions->GetBoolProperty(lcInstructionsPropertyType::ShowStepPLI, mModel, mStep); + setVisible(Visible); + + if (!Visible) + return; + QColor BackgroundColor = mInstructions->GetColorProperty(lcInstructionsPropertyType::PLIBackgroundColor, mModel, mStep); QFont Font = mInstructions->GetFontProperty(lcInstructionsPropertyType::PLIFont, mModel, mStep); QColor TextColor = mInstructions->GetColorProperty(lcInstructionsPropertyType::PLITextColor, mModel, mStep); @@ -295,34 +304,26 @@ lcInstructionsPropertiesWidget::lcInstructionsPropertiesWidget(QWidget* Parent, Layout->setRowStretch(3, 1); } +void lcInstructionsPropertiesWidget::AddBoolProperty(lcInstructionsPropertyType Type) +{ + const QString Label = mInstructions->GetPropertyLabel(Type); + const int Row = mPropertiesLayout->rowCount(); + + QCheckBox* CheckBox = new QCheckBox(Label); + mPropertiesLayout->addWidget(CheckBox, Row, 0, 1, -1); + + bool Enabled = mInstructions->GetBoolProperty(Type, mModel, mStep); + CheckBox->setChecked(Enabled); + + connect(CheckBox, &QToolButton::toggled, [this, Type](bool Checked) + { + mInstructions->SetDefaultBool(Type, Checked); + } ); +} + void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType Type) { - QString Label; - - switch (Type) - { - case lcInstructionsPropertyType::StepNumberColor: - 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; - } - + const QString Label = mInstructions->GetPropertyLabel(Type); const int Row = mPropertiesLayout->rowCount(); mPropertiesLayout->addWidget(new QLabel(Label), Row, 0); @@ -366,6 +367,8 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType Title = tr("Select Parts List Text Color"); break; + case lcInstructionsPropertyType::ShowStepNumber: + case lcInstructionsPropertyType::ShowStepPLI: case lcInstructionsPropertyType::StepNumberFont: case lcInstructionsPropertyType::PLIFont: // case lcInstructionsPropertyType::StepPLIBorderWidth: @@ -387,7 +390,7 @@ void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType void lcInstructionsPropertiesWidget::AddFontProperty(lcInstructionsPropertyType Type) { - const QString Label = tr("Font:"); + const QString Label = mInstructions->GetPropertyLabel(Type); const int Row = mPropertiesLayout->rowCount(); mPropertiesLayout->addWidget(new QLabel(Label), Row, 0); @@ -418,6 +421,8 @@ void lcInstructionsPropertiesWidget::AddFontProperty(lcInstructionsPropertyType Title = tr("Select Parts List Font"); break; + case lcInstructionsPropertyType::ShowStepNumber: + case lcInstructionsPropertyType::ShowStepPLI: case lcInstructionsPropertyType::StepNumberColor: case lcInstructionsPropertyType::StepBackgroundColor: case lcInstructionsPropertyType::PLIBackgroundColor: @@ -474,6 +479,8 @@ void lcInstructionsPropertiesWidget::SelectionChanged(QGraphicsItem* FocusItem) mModel = ImageItem->GetModel(); mStep = ImageItem->GetStep(); + AddBoolProperty(lcInstructionsPropertyType::ShowStepNumber); + AddBoolProperty(lcInstructionsPropertyType::ShowStepPLI); AddColorProperty(lcInstructionsPropertyType::StepBackgroundColor); return; diff --git a/common/lc_instructionsdialog.h b/common/lc_instructionsdialog.h index 571f7918..6fbdb107 100644 --- a/common/lc_instructionsdialog.h +++ b/common/lc_instructionsdialog.h @@ -141,6 +141,7 @@ public: void SelectionChanged(QGraphicsItem* FocusItem); protected: + void AddBoolProperty(lcInstructionsPropertyType Type); void AddColorProperty(lcInstructionsPropertyType Type); void AddFontProperty(lcInstructionsPropertyType Type);