Added step number properties.

This commit is contained in:
Leonardo Zide 2021-01-15 14:24:44 -08:00
parent 929cf2919c
commit d4084ffb00
4 changed files with 163 additions and 16 deletions

View file

@ -39,8 +39,42 @@ lcInstructionsStepProperties lcInstructions::GetStepProperties(lcModel* Model, l
{ {
const lcInstructionsStepProperties& Properties = InstructionModel.StepProperties[StepIndex]; const lcInstructionsStepProperties& Properties = InstructionModel.StepProperties[StepIndex];
if (Properties.BackgroundColorMode == lcInstructionsPropertyMode::Set || (Properties.BackgroundColorMode == lcInstructionsPropertyMode::StepOnly && Step == StepIndex)) auto ShouldSetProperty = [StepIndex, Step](lcInstructionsPropertyMode Mode)
{
switch (Mode)
{
case lcInstructionsPropertyMode::NotSet:
return false;
case lcInstructionsPropertyMode::Default:
return true;
case lcInstructionsPropertyMode::Model:
return true;
case lcInstructionsPropertyMode::StepForward:
return true;
case lcInstructionsPropertyMode::StepOnly:
return StepIndex == Step;
}
return false;
};
if (ShouldSetProperty(Properties.BackgroundColorMode))
{
StepProperties.BackgroundColorMode = Properties.BackgroundColorMode;
StepProperties.BackgroundColor = Properties.BackgroundColor; StepProperties.BackgroundColor = Properties.BackgroundColor;
}
if (ShouldSetProperty(Properties.StepNumberFontMode))
{
StepProperties.StepNumberFontMode = Properties.StepNumberFontMode;
StepProperties.StepNumberFont = Properties.StepNumberFont;
}
if (ShouldSetProperty(Properties.StepNumberColorMode))
{
StepProperties.StepNumberColorMode = Properties.StepNumberColorMode;
StepProperties.StepNumberColor = Properties.StepNumberColor;
}
} }
return StepProperties; return StepProperties;

View file

@ -28,12 +28,20 @@ struct lcInstructionsPageSettings
enum class lcInstructionsPropertyMode enum class lcInstructionsPropertyMode
{ {
NotSet, NotSet,
Set, Default,
Model,
StepForward,
StepOnly StepOnly
}; };
struct lcInstructionsStepProperties struct lcInstructionsStepProperties
{ {
lcInstructionsPropertyMode StepNumberFontMode = lcInstructionsPropertyMode::NotSet;
QString StepNumberFont = QFont("Helvetica", 72).toString();
lcInstructionsPropertyMode StepNumberColorMode = lcInstructionsPropertyMode::NotSet;
quint32 StepNumberColor = LC_RGBA(0, 0, 0, 255);
lcInstructionsPropertyMode BackgroundColorMode = lcInstructionsPropertyMode::NotSet; lcInstructionsPropertyMode BackgroundColorMode = lcInstructionsPropertyMode::NotSet;
quint32 BackgroundColor = LC_RGBA(255, 255, 255, 0); quint32 BackgroundColor = LC_RGBA(255, 255, 255, 0);
}; };

View file

@ -6,25 +6,44 @@
#include "lc_view.h" #include "lc_view.h"
#include "lc_collapsiblewidget.h" #include "lc_collapsiblewidget.h"
lcInstructionsStepItem::lcInstructionsStepItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcInstructionsPropertiesWidget* PropertiesWidget) lcInstructionsStepImageItem::lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget)
: QGraphicsPixmapItem(Pixmap, Parent), mPropertiesWidget(PropertiesWidget) : QGraphicsPixmapItem(Pixmap, Parent), mModel(Model), mStep(Step), mPropertiesWidget(PropertiesWidget)
{ {
} }
void lcInstructionsStepItem::focusInEvent(QFocusEvent* FocusEvent) void lcInstructionsStepImageItem::focusInEvent(QFocusEvent* FocusEvent)
{ {
mPropertiesWidget->StepItemFocusIn(this); mPropertiesWidget->StepImageItemFocusIn(this);
QGraphicsPixmapItem::focusInEvent(FocusEvent); QGraphicsPixmapItem::focusInEvent(FocusEvent);
} }
void lcInstructionsStepItem::focusOutEvent(QFocusEvent* FocusEvent) void lcInstructionsStepImageItem::focusOutEvent(QFocusEvent* FocusEvent)
{ {
mPropertiesWidget->ItemFocusOut(this); mPropertiesWidget->ItemFocusOut(this);
QGraphicsPixmapItem::focusOutEvent(FocusEvent); QGraphicsPixmapItem::focusOutEvent(FocusEvent);
} }
lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget)
: QGraphicsSimpleTextItem(Text, Parent), mModel(Model), mStep(Step), mPropertiesWidget(PropertiesWidget)
{
}
void lcInstructionsStepNumberItem::focusInEvent(QFocusEvent* FocusEvent)
{
mPropertiesWidget->StepNumberItemFocusIn(this);
QGraphicsSimpleTextItem::focusInEvent(FocusEvent);
}
void lcInstructionsStepNumberItem::focusOutEvent(QFocusEvent* FocusEvent)
{
mPropertiesWidget->ItemFocusOut(this);
QGraphicsSimpleTextItem::focusOutEvent(FocusEvent);
}
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions) lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions)
: QGraphicsView(Parent), mInstructions(Instructions) : QGraphicsView(Parent), mInstructions(Instructions)
{ {
@ -66,12 +85,16 @@ void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page, lc
QImage& StepImage = Images.front(); QImage& StepImage = Images.front();
lcInstructionsStepItem* StepImageItem = new lcInstructionsStepItem(QPixmap::fromImage(StepImage), PageItem, PropertiesWidget); lcInstructionsStepImageItem* StepImageItem = new lcInstructionsStepImageItem(QPixmap::fromImage(StepImage), PageItem, Step.Model, Step.Step, PropertiesWidget);
StepImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable); StepImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
StepImageItem->setPos(MarginsRect.left() + MarginsRect.width() * Step.Rect.x(), MarginsRect.top() + MarginsRect.height() * Step.Rect.y()); StepImageItem->setPos(MarginsRect.left() + MarginsRect.width() * Step.Rect.x(), MarginsRect.top() + MarginsRect.height() * Step.Rect.y());
QGraphicsSimpleTextItem* StepNumberItem = new QGraphicsSimpleTextItem(QString::number(Step.Step), StepImageItem); lcInstructionsStepNumberItem* StepNumberItem = new lcInstructionsStepNumberItem(QString::number(Step.Step), StepImageItem, Step.Model, Step.Step, PropertiesWidget);
StepNumberItem->setFont(QFont("Helvetica", 96)); QFont StepNumberFont;
if (!StepNumberFont.fromString(StepProperties.StepNumberFont))
StepNumberFont = QFont("Helvetica", 72);
StepNumberItem->setFont(StepNumberFont);
StepNumberItem->setBrush(QBrush(QColor::fromRgb(LC_RGBA_RED(StepProperties.StepNumberColor), LC_RGBA_GREEN(StepProperties.StepNumberColor), LC_RGBA_BLUE(StepProperties.StepNumberColor))));
StepNumberItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable); StepNumberItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
QImage PartsImage = Step.Model->GetPartsListImage(300, Step.Step); QImage PartsImage = Step.Model->GetPartsListImage(300, Step.Step);
@ -234,12 +257,12 @@ void lcInstructionsPropertiesWidget::ColorButtonClicked()
// mPageListWidget->mThumbnailsWidget->setCurrentRow(0); // mPageListWidget->mThumbnailsWidget->setCurrentRow(0);
} }
void lcInstructionsPropertiesWidget::StepItemFocusIn(lcInstructionsStepItem* StepItem) void lcInstructionsPropertiesWidget::StepImageItemFocusIn(lcInstructionsStepImageItem* ImageItem)
{ {
if (mFocusItem == StepItem) if (mFocusItem == ImageItem)
return; return;
mFocusItem = StepItem; mFocusItem = ImageItem;
delete mWidget; delete mWidget;
mWidget = new lcCollapsibleWidget(tr("Step Properties")); // todo: disable collapse mWidget = new lcCollapsibleWidget(tr("Step Properties")); // todo: disable collapse
@ -258,6 +281,51 @@ void lcInstructionsPropertiesWidget::StepItemFocusIn(lcInstructionsStepItem* Ste
connect(ColorButton, &QToolButton::clicked, this, &lcInstructionsPropertiesWidget::ColorButtonClicked); connect(ColorButton, &QToolButton::clicked, this, &lcInstructionsPropertiesWidget::ColorButtonClicked);
} }
void lcInstructionsPropertiesWidget::StepNumberItemFocusIn(lcInstructionsStepNumberItem* NumberItem)
{
if (mFocusItem == NumberItem)
return;
mFocusItem = NumberItem;
delete mWidget;
mWidget = new lcCollapsibleWidget(tr("Step Number Properties")); // todo: disable collapse
QGridLayout* WidgetLayout = qobject_cast<QGridLayout*>(widget()->layout());
WidgetLayout->addWidget(mWidget, 2, 0, 1, -1);
QGridLayout* Layout = new QGridLayout();
mWidget->SetChildLayout(Layout);
lcInstructionsStepProperties StepProperties = mInstructions->GetStepProperties(NumberItem->GetModel(), NumberItem->GetStep());
QFont Font;
Font.fromString(StepProperties.StepNumberFont);
QLabel* FontLabel = new QLabel(tr("Font:"));
Layout->addWidget(FontLabel, 0, 0);
QToolButton* FontButton = new QToolButton();
FontButton->setText(Font.family());
Layout->addWidget(FontButton, 0, 1);
connect(FontButton, &QToolButton::clicked, []()
{
bool Ok;
QFontDialog::getFont(&Ok);
});// this, & lcInstructionsPropertiesWidget::ColorButtonClicked);
QLabel* ColorLabel = new QLabel(tr("Color:"));
Layout->addWidget(ColorLabel, 1, 0);
// QToolButton* ColorButton = new QToolButton();
// ColorButton->setText("Font");
//
// Layout->addWidget(ColorButton);
//
// connect(ColorButton, &QToolButton::clicked, this, &lcInstructionsPropertiesWidget::ColorButtonClicked);
}
void lcInstructionsPropertiesWidget::ItemFocusOut(QGraphicsItem* Item) void lcInstructionsPropertiesWidget::ItemFocusOut(QGraphicsItem* Item)
{ {
if (mFocusItem != Item) if (mFocusItem != Item)

View file

@ -4,15 +4,51 @@
class lcInstructionsPropertiesWidget; class lcInstructionsPropertiesWidget;
class lcInstructionsStepItem : public QGraphicsPixmapItem class lcInstructionsStepImageItem : public QGraphicsPixmapItem
{ {
public: public:
lcInstructionsStepItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcInstructionsPropertiesWidget* PropertiesWidget); lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget);
lcModel* GetModel() const
{
return mModel;
}
lcStep GetStep() const
{
return mStep;
}
protected: protected:
void focusInEvent(QFocusEvent* FocusEvent) override; void focusInEvent(QFocusEvent* FocusEvent) override;
void focusOutEvent(QFocusEvent* FocusEvent) override; void focusOutEvent(QFocusEvent* FocusEvent) override;
lcModel* mModel = nullptr;
lcStep mStep = 1;
lcInstructionsPropertiesWidget* mPropertiesWidget = nullptr;
};
class lcInstructionsStepNumberItem : public QGraphicsSimpleTextItem
{
public:
lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget);
lcModel* GetModel() const
{
return mModel;
}
lcStep GetStep() const
{
return mStep;
}
protected:
void focusInEvent(QFocusEvent* FocusEvent) override;
void focusOutEvent(QFocusEvent* FocusEvent) override;
lcModel* mModel = nullptr;
lcStep mStep = 1;
lcInstructionsPropertiesWidget* mPropertiesWidget = nullptr; lcInstructionsPropertiesWidget* mPropertiesWidget = nullptr;
}; };
@ -68,7 +104,8 @@ class lcInstructionsPropertiesWidget : public QDockWidget
public: public:
lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions); lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions);
void StepItemFocusIn(lcInstructionsStepItem* StepItem); void StepImageItemFocusIn(lcInstructionsStepImageItem* ImageItem);
void StepNumberItemFocusIn(lcInstructionsStepNumberItem* NumberItem);
void ItemFocusOut(QGraphicsItem* Item); void ItemFocusOut(QGraphicsItem* Item);
protected slots: protected slots: