Working step number options.

This commit is contained in:
Leonardo Zide 2021-01-15 15:37:28 -08:00
parent ec4044dcfa
commit 239e753749
4 changed files with 64 additions and 18 deletions

View file

@ -98,6 +98,28 @@ void lcInstructions::SetDefaultStepBackgroundColor(quint32 Color)
emit PageInvalid(static_cast<int>(PageIndex)); // todo: invalidate steps, not pages emit PageInvalid(static_cast<int>(PageIndex)); // todo: invalidate steps, not pages
} }
void lcInstructions::SetDefaultStepNumberFont(const QString& Font)
{
if (mStepProperties.StepNumberFont == Font)
return;
mStepProperties.StepNumberFont = Font;
for (size_t PageIndex = 0; PageIndex < mPages.size(); PageIndex++)
emit PageInvalid(static_cast<int>(PageIndex)); // todo: invalidate steps, not pages
}
void lcInstructions::SetDefaultStepNumberColor(quint32 Color)
{
if (mStepProperties.StepNumberColor == Color)
return;
mStepProperties.StepNumberColor = Color;
for (size_t PageIndex = 0; PageIndex < mPages.size(); PageIndex++)
emit PageInvalid(static_cast<int>(PageIndex)); // todo: invalidate steps, not pages
}
void lcInstructions::CreatePages() void lcInstructions::CreatePages()
{ {
mPages.clear(); mPages.clear();

View file

@ -37,7 +37,7 @@ enum class lcInstructionsPropertyMode
struct lcInstructionsStepProperties struct lcInstructionsStepProperties
{ {
lcInstructionsPropertyMode StepNumberFontMode = lcInstructionsPropertyMode::NotSet; lcInstructionsPropertyMode StepNumberFontMode = lcInstructionsPropertyMode::NotSet;
QString StepNumberFont = QFont("Helvetica", 72).toString(); QString StepNumberFont = QFont("Arial", 72).toString();
lcInstructionsPropertyMode StepNumberColorMode = lcInstructionsPropertyMode::NotSet; lcInstructionsPropertyMode StepNumberColorMode = lcInstructionsPropertyMode::NotSet;
quint32 StepNumberColor = LC_RGBA(0, 0, 0, 255); quint32 StepNumberColor = LC_RGBA(0, 0, 0, 255);
@ -75,7 +75,10 @@ public:
lcInstructionsStepProperties GetStepProperties(lcModel* Model, lcStep Step) const; lcInstructionsStepProperties GetStepProperties(lcModel* Model, lcStep Step) const;
void SetDefaultPageSettings(const lcInstructionsPageSettings& PageSettings); void SetDefaultPageSettings(const lcInstructionsPageSettings& PageSettings);
void SetDefaultStepBackgroundColor(quint32 Color); void SetDefaultStepBackgroundColor(quint32 Color);
void SetDefaultStepNumberFont(const QString& Font);
void SetDefaultStepNumberColor(quint32 Color);
std::vector<lcInstructionsPage> mPages; std::vector<lcInstructionsPage> mPages;
lcInstructionsPageSettings mPageSettings; lcInstructionsPageSettings mPageSettings;

View file

@ -19,6 +19,10 @@ lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(const QString& Text,
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget) lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget)
: QGraphicsView(Parent), mInstructions(Instructions), mPropertiesWidget(PropertiesWidget) : QGraphicsView(Parent), mInstructions(Instructions), mPropertiesWidget(PropertiesWidget)
{ {
QGraphicsScene* Scene = new QGraphicsScene();
setScene(Scene);
connect(Scene, &QGraphicsScene::selectionChanged, this, &lcInstructionsPageWidget::SelectionChanged);
} }
void lcInstructionsPageWidget::SelectionChanged() void lcInstructionsPageWidget::SelectionChanged()
@ -34,14 +38,14 @@ void lcInstructionsPageWidget::SelectionChanged()
Focus = SelectedItems.first(); Focus = SelectedItems.first();
} }
mPropertiesWidget->FocusChanged(Focus); mPropertiesWidget->SelectionChanged(Focus);
} }
void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page) void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
{ {
QGraphicsScene* Scene = new QGraphicsScene(); QGraphicsScene* Scene = scene();
connect(Scene, &QGraphicsScene::selectionChanged, this, &lcInstructionsPageWidget::SelectionChanged);
setScene(Scene); Scene->clear();
if (!Page) if (!Page)
return; return;
@ -283,27 +287,44 @@ void lcInstructionsPropertiesWidget::StepNumberItemFocusIn(lcInstructionsStepNum
Layout->addWidget(FontLabel, 0, 0); Layout->addWidget(FontLabel, 0, 0);
QToolButton* FontButton = new QToolButton(); QToolButton* FontButton = new QToolButton();
FontButton->setText(Font.family()); QString FontName = Font.family();
QString FontStyle = Font.styleName();
if (!FontStyle.isEmpty())
FontName += " " + FontStyle;
FontName += " " + QString::number(Font.pointSize());
FontButton->setText(FontName);
Layout->addWidget(FontButton, 0, 1); Layout->addWidget(FontButton, 0, 1);
connect(FontButton, &QToolButton::clicked, []() connect(FontButton, &QToolButton::clicked, [this, Font]()
{ {
bool Ok; bool Ok = false;
QFontDialog::getFont(&Ok);
});// this, & lcInstructionsPropertiesWidget::ColorButtonClicked); QFont NewFont = QFontDialog::getFont(&Ok, Font, this, tr("Select Step Number Font"));
if (Ok)
mInstructions->SetDefaultStepNumberFont(NewFont.toString()); // todo: this is clearing the scene selection and hiding the properties widget
});
QLabel* ColorLabel = new QLabel(tr("Color:")); QLabel* ColorLabel = new QLabel(tr("Color:"));
Layout->addWidget(ColorLabel, 1, 0); Layout->addWidget(ColorLabel, 1, 0);
// QToolButton* ColorButton = new QToolButton(); QToolButton* ColorButton = new QToolButton();
// ColorButton->setText("Font"); QPixmap Pixmap(12, 12);
// QColor Color(LC_RGBA_RED(StepProperties.StepNumberColor), LC_RGBA_GREEN(StepProperties.StepNumberColor), LC_RGBA_BLUE(StepProperties.StepNumberColor));
// Layout->addWidget(ColorButton); Pixmap.fill(Color);
// ColorButton->setIcon(Pixmap);
// connect(ColorButton, &QToolButton::clicked, this, &lcInstructionsPropertiesWidget::ColorButtonClicked); Layout->addWidget(ColorButton, 1, 1);
connect(ColorButton, &QToolButton::clicked, [this, Color]()
{
QColor NewColor = QColorDialog::getColor(Color, this, tr("Select Step Number Color"));
if (NewColor.isValid())
mInstructions->SetDefaultStepNumberColor(LC_RGBA(NewColor.red(), NewColor.green(), NewColor.blue(), NewColor.alpha()));
});
} }
void lcInstructionsPropertiesWidget::FocusChanged(QGraphicsItem* FocusItem) void lcInstructionsPropertiesWidget::SelectionChanged(QGraphicsItem* FocusItem)
{ {
if (mFocusItem == FocusItem) if (mFocusItem == FocusItem)
return; return;

View file

@ -100,7 +100,7 @@ class lcInstructionsPropertiesWidget : public QDockWidget
public: public:
lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions); lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions);
void FocusChanged(QGraphicsItem* FocusItem); void SelectionChanged(QGraphicsItem* FocusItem);
protected slots: protected slots:
void ColorButtonClicked(); void ColorButtonClicked();