leocad/common/lc_instructionsdialog.cpp

738 lines
23 KiB
C++
Raw Normal View History

2020-06-01 03:46:36 +02:00
#include "lc_global.h"
#include "lc_instructionsdialog.h"
2021-01-08 02:04:19 +01:00
#include "lc_pagesetupdialog.h"
2020-06-01 03:46:36 +02:00
#include "project.h"
#include "lc_model.h"
2021-01-08 02:04:19 +01:00
#include "lc_view.h"
2021-01-15 03:19:58 +01:00
#include "lc_collapsiblewidget.h"
lcInstructionsStepImageItem::lcInstructionsStepImageItem(QGraphicsItem* Parent, lcInstructions* Instructions, lcModel* Model, lcStep Step)
: QGraphicsPixmapItem(Parent), mInstructions(Instructions), mModel(Model), mStep(Step)
2021-01-15 03:19:58 +01:00
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
2021-01-15 03:19:58 +01:00
}
void lcInstructionsStepImageItem::Update()
2021-01-15 03:19:58 +01:00
{
lcView View(lcViewType::View, mModel);
View.SetOffscreenContext();
View.MakeCurrent();
View.SetBackgroundColorOverride(lcRGBAFromQColor(mInstructions->GetColorProperty(lcInstructionsPropertyType::StepBackgroundColor, mModel, mStep)));
View.SetSize(mWidth, mHeight);
std::vector<QImage> Images = View.GetStepImages(mStep, mStep);
if (!Images.empty())
setPixmap(QPixmap::fromImage(Images.front()));
}
lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(QGraphicsItem* Parent, lcInstructions* Instructions, lcModel* Model, lcStep Step)
: QGraphicsSimpleTextItem(Parent), mInstructions(Instructions), mModel(Model), mStep(Step)
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
}
void lcInstructionsStepNumberItem::Update()
{
2021-01-17 20:05:50 +01:00
bool Visible = mInstructions->GetBoolProperty(lcInstructionsPropertyType::ShowStepNumber, mModel, mStep);
setVisible(Visible);
QFont StepNumberFont = mInstructions->GetFontProperty(lcInstructionsPropertyType::StepNumberFont, mModel, mStep);
setFont(StepNumberFont);
setBrush(QBrush(mInstructions->GetColorProperty(lcInstructionsPropertyType::StepNumberColor, mModel, mStep)));
setText(QString::number(mStep));
2021-01-15 03:19:58 +01:00
}
2020-06-01 03:46:36 +02:00
2021-01-16 23:43:24 +01:00
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()
{
2021-01-17 20:05:50 +01:00
bool Visible = mInstructions->GetBoolProperty(lcInstructionsPropertyType::ShowStepPLI, mModel, mStep);
setVisible(Visible);
if (!Visible)
return;
2021-01-16 23:43:24 +01:00
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));
}
2021-01-15 23:43:31 +01:00
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget)
: QGraphicsView(Parent), mInstructions(Instructions), mPropertiesWidget(PropertiesWidget)
2021-01-15 23:24:44 +01:00
{
2021-01-16 00:37:28 +01:00
QGraphicsScene* Scene = new QGraphicsScene();
setScene(Scene);
connect(mInstructions, &lcInstructions::StepSettingsChanged, this, &lcInstructionsPageWidget::StepSettingsChanged);
2021-01-16 00:37:28 +01:00
connect(Scene, &QGraphicsScene::selectionChanged, this, &lcInstructionsPageWidget::SelectionChanged);
2021-01-15 23:24:44 +01:00
}
void lcInstructionsPageWidget::StepSettingsChanged(lcModel* Model, lcStep Step)
{
QGraphicsScene* Scene = scene();
QList<QGraphicsItem*> Items = Scene->items();
for (QGraphicsItem* Item : Items)
{
lcInstructionsStepImageItem* ImageItem = dynamic_cast<lcInstructionsStepImageItem*>(Item);
if (ImageItem)
{
if (!Model || (ImageItem->GetModel() == Model && ImageItem->GetStep() == Step))
ImageItem->Update();
continue;
}
lcInstructionsStepNumberItem* NumberItem = dynamic_cast<lcInstructionsStepNumberItem*>(Item);
if (NumberItem)
{
if (!Model || (NumberItem->GetModel() == Model && NumberItem->GetStep() == Step))
NumberItem->Update();
continue;
}
2021-01-16 23:43:24 +01:00
lcInstructionsPartsListItem* PartsItem = dynamic_cast<lcInstructionsPartsListItem*>(Item);
if (PartsItem)
{
if (!Model || (PartsItem->GetModel() == Model && PartsItem->GetStep() == Step))
PartsItem->Update();
continue;
}
}
}
2021-01-15 23:43:31 +01:00
void lcInstructionsPageWidget::SelectionChanged()
2021-01-15 23:24:44 +01:00
{
2021-01-15 23:43:31 +01:00
QGraphicsScene* Scene = qobject_cast<QGraphicsScene*>(sender());
QGraphicsItem* Focus = nullptr;
2021-01-15 23:24:44 +01:00
2021-01-15 23:43:31 +01:00
if (Scene)
{
QList<QGraphicsItem*> SelectedItems = Scene->selectedItems();
2021-01-15 23:24:44 +01:00
2021-01-15 23:43:31 +01:00
if (!SelectedItems.isEmpty())
Focus = SelectedItems.first();
}
2021-01-15 23:24:44 +01:00
2021-01-16 00:37:28 +01:00
mPropertiesWidget->SelectionChanged(Focus);
2021-01-15 23:24:44 +01:00
}
static void lcUpdateInstructionsPageScene(lcInstructions* Instructions, const lcInstructionsPage* Page, QGraphicsScene* Scene)
2020-06-01 03:46:36 +02:00
{
2021-01-16 00:37:28 +01:00
Scene->clear();
2020-06-01 03:46:36 +02:00
2021-01-07 20:48:43 +01:00
if (!Page)
return;
const lcInstructionsPageSetup& PageSetup = Instructions->mPageSetup;
// Scene->setSceneRect(0, 0, mInstructions->mPageSetup.Width, mInstructions->mPageSetup.Height);
2021-01-07 20:48:43 +01:00
QGraphicsRectItem* PageItem = Scene->addRect(QRectF(0.0f, 0.0f, PageSetup.Width, PageSetup.Height), QPen(Qt::black), QBrush(Qt::white));
PageItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
QRectF MarginsRect(PageSetup.MarginLeft, PageSetup.MarginTop, PageSetup.Width - PageSetup.MarginLeft - PageSetup.MarginRight, PageSetup.Height - PageSetup.MarginTop - PageSetup.MarginBottom);
for (const lcInstructionsStep& Step : Page->Steps)
2021-01-06 03:48:12 +01:00
{
lcInstructionsStepImageItem* StepImageItem = new lcInstructionsStepImageItem(PageItem, Instructions, Step.Model, Step.Step);
2021-01-07 20:48:43 +01:00
StepImageItem->setPos(MarginsRect.left() + MarginsRect.width() * Step.Rect.x(), MarginsRect.top() + MarginsRect.height() * Step.Rect.y());
StepImageItem->SetImageSize(MarginsRect.width() * Step.Rect.width(), MarginsRect.height() * Step.Rect.height());
StepImageItem->Update();
2021-01-07 20:48:43 +01:00
lcInstructionsStepNumberItem* StepNumberItem = new lcInstructionsStepNumberItem(StepImageItem, Instructions, Step.Model, Step.Step);
StepNumberItem->Update();
2021-01-07 20:48:43 +01:00
lcInstructionsPartsListItem* PartsImageItem = new lcInstructionsPartsListItem(StepImageItem, Instructions, Step.Model, Step.Step);
2021-01-07 20:48:43 +01:00
PartsImageItem->setPos(StepNumberItem->boundingRect().topRight());
2021-01-16 23:43:24 +01:00
PartsImageItem->Update();
2021-01-06 03:48:12 +01:00
}
2020-06-01 03:46:36 +02:00
}
void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
{
QGraphicsScene* Scene = scene();
lcUpdateInstructionsPageScene(mInstructions, Page, Scene);
}
2021-01-07 19:46:57 +01:00
lcInstructionsPageListWidget::lcInstructionsPageListWidget(QWidget* Parent, lcInstructions* Instructions)
: QDockWidget(Parent), mInstructions(Instructions)
2020-06-01 03:46:36 +02:00
{
QWidget* CentralWidget = new QWidget(this);
2021-01-06 23:06:15 +01:00
setWidget(CentralWidget);
setWindowTitle(tr("Pages"));
2020-06-01 03:46:36 +02:00
2021-01-07 02:45:38 +01:00
QVBoxLayout* Layout = new QVBoxLayout(CentralWidget);
2021-01-06 03:48:12 +01:00
Layout->setContentsMargins(0, 0, 0, 0);
2020-06-01 03:46:36 +02:00
2021-01-07 19:46:57 +01:00
QHBoxLayout* ButtonsLayout = new QHBoxLayout();
ButtonsLayout->setContentsMargins(0, 0, 0, 0);
Layout->addLayout(ButtonsLayout);
QToolButton* PageSetupButton = new QToolButton();
2022-05-16 21:36:52 +02:00
PageSetupButton->setText(tr("Page Setup"));
2021-01-07 19:46:57 +01:00
ButtonsLayout->addWidget(PageSetupButton);
connect(PageSetupButton, SIGNAL(clicked()), this, SLOT(ShowPageSetupDialog()));
ButtonsLayout->addStretch(1);
/*
2021-01-07 02:45:38 +01:00
lcCollapsibleWidget* SetupWidget = new lcCollapsibleWidget(tr("Page Setup"), CentralWidget);
Layout->addWidget(SetupWidget);
2021-01-07 19:46:57 +01:00
// QVBoxLayout* SetupLayout = new QVBoxLayout();
// SetupWidget->SetChildLayout(SetupLayout);
QGridLayout* SetupLayout = new QGridLayout();
2021-01-07 02:45:38 +01:00
SetupWidget->SetChildLayout(SetupLayout);
2021-01-07 19:46:57 +01:00
// lcCollapsibleWidget* SizeWidget = new lcCollapsibleWidget(tr("Size"));
QGroupBox* SizeWidget = new QGroupBox(tr("Size"));
2021-01-07 02:45:38 +01:00
SetupLayout->addWidget(SizeWidget);
QGridLayout* SizeLayout = new QGridLayout();
2021-01-07 19:46:57 +01:00
// SizeWidget->SetChildLayout(SizeLayout);
SizeWidget->setLayout(SizeLayout);
2021-01-07 02:45:38 +01:00
mWidthEdit = new lcSmallLineEdit();
SizeLayout->addWidget(new QLabel(tr("Width:")), 1, 0);
SizeLayout->addWidget(mWidthEdit, 1, 1);
mHeightEdit = new lcSmallLineEdit();
SizeLayout->addWidget(new QLabel(tr("Height:")), 1, 2);
SizeLayout->addWidget(mHeightEdit, 1, 3);
2021-01-07 19:46:57 +01:00
mUnitsComboBox = new QComboBox();
mUnitsComboBox->addItems(QStringList() << tr("Pixels") << tr("Centimeters") << tr("Inches"));
SizeLayout->addWidget(new QLabel(tr("Units:")), 4, 0);
SizeLayout->addWidget(mUnitsComboBox, 4, 1, 1, -1);
2021-01-07 02:45:38 +01:00
2021-01-07 19:46:57 +01:00
mSizeComboBox = new QComboBox();
SizeLayout->addWidget(new QLabel(tr("Preset:")), 5, 0);
SizeLayout->addWidget(mSizeComboBox, 5, 1, 1, -1);
// lcCollapsibleWidget* OrientationWidget = new lcCollapsibleWidget(tr("Orientation"));
// SetupLayout->addWidget(OrientationWidget);
//
// QVBoxLayout* OrientationLayout = new QVBoxLayout();
// OrientationWidget->SetChildLayout(OrientationLayout);
//
// mPortraitButton = new QRadioButton(tr("Portrait"));
// OrientationLayout->addWidget(mPortraitButton);
// mLandscapeButton = new QRadioButton(tr("Landscape"));
// OrientationLayout->addWidget(mLandscapeButton);
QGroupBox* MarginsWidget = new QGroupBox(tr("Margins"));
// lcCollapsibleWidget* MarginsWidget = new lcCollapsibleWidget(tr("Margins"));
2021-01-07 02:45:38 +01:00
SetupLayout->addWidget(MarginsWidget);
QGridLayout* MarginsLayout = new QGridLayout();
2021-01-07 19:46:57 +01:00
// MarginsWidget->SetChildLayout(MarginsLayout);
MarginsWidget->setLayout(MarginsLayout);
2021-01-07 02:45:38 +01:00
mLeftMarginEdit = new lcSmallLineEdit();
2021-01-07 19:46:57 +01:00
MarginsLayout->addWidget(new QLabel(tr("Left:")), 2, 0);
MarginsLayout->addWidget(mLeftMarginEdit, 2, 1);
2021-01-07 02:45:38 +01:00
mRightMarginEdit = new lcSmallLineEdit();
2021-01-07 19:46:57 +01:00
MarginsLayout->addWidget(new QLabel(tr("Right:")), 2, 2);
MarginsLayout->addWidget(mRightMarginEdit, 2, 3);
2021-01-07 02:45:38 +01:00
mTopMarginEdit = new lcSmallLineEdit();
2021-01-07 19:46:57 +01:00
MarginsLayout->addWidget(new QLabel(tr("Top:")), 3, 0);
MarginsLayout->addWidget(mTopMarginEdit, 3, 1);
2021-01-07 02:45:38 +01:00
mBottomMarginEdit = new lcSmallLineEdit();
2021-01-07 19:46:57 +01:00
MarginsLayout->addWidget(new QLabel(tr("Bottom:")), 3, 2);
MarginsLayout->addWidget(mBottomMarginEdit, 3, 3);
2021-01-07 02:45:38 +01:00
2021-01-07 19:46:57 +01:00
// lcCollapsibleWidget* UnitsWidget = new lcCollapsibleWidget(tr("Units"));
// SetupLayout->addWidget(UnitsWidget);
//
// QVBoxLayout* UnitsLayout = new QVBoxLayout();
// UnitsWidget->SetChildLayout(UnitsLayout);
2021-01-07 02:45:38 +01:00
2021-01-07 19:46:57 +01:00
// SetupWidget->Collapse();
*/
2021-01-06 23:06:15 +01:00
mThumbnailsWidget = new QListWidget(CentralWidget);
Layout->addWidget(mThumbnailsWidget);
}
2021-01-07 19:46:57 +01:00
void lcInstructionsPageListWidget::ShowPageSetupDialog()
{
lcPageSetupDialog Dialog(this, &mInstructions->mPageSetup);
if (Dialog.exec() != QDialog::Accepted)
return;
}
2021-01-15 03:19:58 +01:00
lcInstructionsPropertiesWidget::lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions)
: QDockWidget(Parent), mInstructions(Instructions)
{
QWidget* CentralWidget = new QWidget(this);
setWidget(CentralWidget);
setWindowTitle(tr("Properties"));
QGridLayout* Layout = new QGridLayout(CentralWidget);
Layout->setContentsMargins(0, 0, 0, 0);
QComboBox* ScopeComboBox = new QComboBox(CentralWidget);
ScopeComboBox->addItems(QStringList() << tr("Default") << tr("Current Model") << tr("Current Step Only") << tr("Current Step Forward"));
Layout->addWidget(new QLabel(tr("Scope:")), 0, 0);
Layout->addWidget(ScopeComboBox, 0, 1);
QComboBox* PresetComboBox = new QComboBox(CentralWidget);
Layout->addWidget(new QLabel(tr("Preset:")), 1, 0);
Layout->addWidget(PresetComboBox, 1, 1);
Layout->setRowStretch(3, 1);
}
2021-01-17 20:05:50 +01:00
void lcInstructionsPropertiesWidget::AddBoolProperty(lcInstructionsPropertyType Type)
2021-01-15 03:19:58 +01:00
{
2021-01-17 20:05:50 +01:00
const QString Label = mInstructions->GetPropertyLabel(Type);
const int Row = mPropertiesLayout->rowCount();
2021-01-15 03:19:58 +01:00
2021-01-17 20:05:50 +01:00
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)
2021-01-16 03:28:41 +01:00
{
2021-01-17 20:05:50 +01:00
mInstructions->SetDefaultBool(Type, Checked);
2024-12-20 00:54:40 +01:00
});
2021-01-17 20:05:50 +01:00
}
2021-01-15 03:19:58 +01:00
2021-01-17 20:05:50 +01:00
void lcInstructionsPropertiesWidget::AddColorProperty(lcInstructionsPropertyType Type)
{
const QString Label = mInstructions->GetPropertyLabel(Type);
2021-01-16 03:28:41 +01:00
const int Row = mPropertiesLayout->rowCount();
2021-01-15 03:19:58 +01:00
2021-01-16 03:28:41 +01:00
mPropertiesLayout->addWidget(new QLabel(Label), Row, 0);
2021-01-16 00:40:06 +01:00
2021-01-15 03:19:58 +01:00
QToolButton* ColorButton = new QToolButton();
2021-01-16 03:28:41 +01:00
mPropertiesLayout->addWidget(ColorButton, Row, 1);
2021-01-15 03:19:58 +01:00
auto UpdateButton = [this, Type, ColorButton]()
{
QPixmap Pixmap(12, 12);
QColor Color = mInstructions->GetColorProperty(Type, mModel, mStep);
Pixmap.fill(Color);
ColorButton->setIcon(Pixmap);
};
UpdateButton();
connect(ColorButton, &QToolButton::clicked, [this, Type, UpdateButton]()
2021-01-16 00:40:06 +01:00
{
2021-01-16 03:28:41 +01:00
QString Title;
switch (Type)
{
case lcInstructionsPropertyType::StepNumberColor:
Title = tr("Select Step Number Color");
break;
case lcInstructionsPropertyType::StepBackgroundColor:
Title = tr("Select Step Background Color");
break;
2021-01-16 23:43:24 +01:00
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;
2021-01-17 20:05:50 +01:00
case lcInstructionsPropertyType::ShowStepNumber:
case lcInstructionsPropertyType::ShowStepPLI:
2021-01-16 23:43:24 +01:00
case lcInstructionsPropertyType::StepNumberFont:
case lcInstructionsPropertyType::PLIFont:
// case lcInstructionsPropertyType::StepPLIBorderWidth:
// case lcInstructionsPropertyType::StepPLIBorderRound:
2021-01-16 03:28:41 +01:00
case lcInstructionsPropertyType::Count:
break;
}
QColor Color = mInstructions->GetColorProperty(Type, mModel, mStep);
Color = QColorDialog::getColor(Color, this, Title);
2021-01-15 03:19:58 +01:00
if (Color.isValid())
{
mInstructions->SetDefaultColor(Type, Color);
UpdateButton();
}
2021-01-16 00:40:06 +01:00
});
2021-01-15 03:19:58 +01:00
}
2021-01-16 03:28:41 +01:00
void lcInstructionsPropertiesWidget::AddFontProperty(lcInstructionsPropertyType Type)
2021-01-15 23:24:44 +01:00
{
2021-01-17 20:05:50 +01:00
const QString Label = mInstructions->GetPropertyLabel(Type);
2021-01-16 03:28:41 +01:00
const int Row = mPropertiesLayout->rowCount();
2021-01-15 23:24:44 +01:00
2021-01-16 03:28:41 +01:00
mPropertiesLayout->addWidget(new QLabel(Label), Row, 0);
2021-01-15 23:24:44 +01:00
QToolButton* FontButton = new QToolButton();
2021-01-16 03:28:41 +01:00
mPropertiesLayout->addWidget(FontButton, Row, 1);
2021-01-15 23:24:44 +01:00
auto UpdateButton = [this, Type, FontButton]()
{
QFont Font = mInstructions->GetFontProperty(Type, mModel, mStep);
QString FontName = QString("%1 %2").arg(Font.family(), QString::number(Font.pointSize()));
FontButton->setText(FontName);
};
UpdateButton();
connect(FontButton, &QToolButton::clicked, [this, Type, UpdateButton]()
2021-01-15 23:24:44 +01:00
{
2021-01-16 03:28:41 +01:00
QString Title;
switch (Type)
{
case lcInstructionsPropertyType::StepNumberFont:
Title = tr("Select Step Number Font");
break;
2021-01-16 23:43:24 +01:00
case lcInstructionsPropertyType::PLIFont:
Title = tr("Select Parts List Font");
break;
2021-01-17 20:05:50 +01:00
case lcInstructionsPropertyType::ShowStepNumber:
case lcInstructionsPropertyType::ShowStepPLI:
2021-01-16 03:28:41 +01:00
case lcInstructionsPropertyType::StepNumberColor:
case lcInstructionsPropertyType::StepBackgroundColor:
2021-01-16 23:43:24 +01:00
case lcInstructionsPropertyType::PLIBackgroundColor:
case lcInstructionsPropertyType::PLITextColor:
case lcInstructionsPropertyType::PLIBorderColor:
2021-01-16 03:28:41 +01:00
case lcInstructionsPropertyType::Count:
break;
}
2021-01-16 00:37:28 +01:00
bool Ok = false;
2021-01-16 23:43:24 +01:00
QFont Font = mInstructions->GetFontProperty(Type, mModel, mStep);
Font = QFontDialog::getFont(&Ok, Font, this, tr("Select Step Number Font"));
2021-01-16 00:37:28 +01:00
if (Ok)
{
UpdateButton();
2021-01-16 23:43:24 +01:00
mInstructions->SetDefaultFont(Type, Font);
}
2021-01-16 00:37:28 +01:00
});
2021-01-15 23:24:44 +01:00
}
2021-01-16 00:37:28 +01:00
void lcInstructionsPropertiesWidget::SelectionChanged(QGraphicsItem* FocusItem)
2021-01-15 03:19:58 +01:00
{
2021-01-15 23:43:31 +01:00
if (mFocusItem == FocusItem)
2021-01-15 03:19:58 +01:00
return;
delete mWidget;
mWidget = nullptr;
2021-01-15 23:43:31 +01:00
mFocusItem = FocusItem;
2021-01-16 03:28:41 +01:00
mModel = nullptr;
mStep = 1;
2021-01-15 23:43:31 +01:00
if (!FocusItem)
return;
2021-01-16 03:28:41 +01:00
auto CreatePropertyWidget = [this](const QString& Title)
{
mWidget = new lcCollapsibleWidget(Title); // todo: disable collapse
QGridLayout* WidgetLayout = qobject_cast<QGridLayout*>(widget()->layout());
WidgetLayout->addWidget(mWidget, 2, 0, 1, -1);
mPropertiesLayout = new QGridLayout();
mWidget->SetChildLayout(mPropertiesLayout);
};
2021-01-15 23:43:31 +01:00
lcInstructionsStepImageItem* ImageItem = dynamic_cast<lcInstructionsStepImageItem*>(FocusItem);
if (ImageItem)
{
2021-01-16 03:28:41 +01:00
CreatePropertyWidget(tr("Step Properties"));
mModel = ImageItem->GetModel();
mStep = ImageItem->GetStep();
2021-01-17 20:05:50 +01:00
AddBoolProperty(lcInstructionsPropertyType::ShowStepNumber);
AddBoolProperty(lcInstructionsPropertyType::ShowStepPLI);
2021-01-16 03:28:41 +01:00
AddColorProperty(lcInstructionsPropertyType::StepBackgroundColor);
2021-01-15 23:43:31 +01:00
return;
}
lcInstructionsStepNumberItem* NumberItem = dynamic_cast<lcInstructionsStepNumberItem*>(FocusItem);
if (NumberItem)
{
2021-01-16 03:28:41 +01:00
CreatePropertyWidget(tr("Step Number Properties"));
mModel = NumberItem->GetModel();
mStep = NumberItem->GetStep();
AddFontProperty(lcInstructionsPropertyType::StepNumberFont);
AddColorProperty(lcInstructionsPropertyType::StepNumberColor);
2021-01-15 23:43:31 +01:00
return;
}
2021-01-16 23:43:24 +01:00
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;
}
2021-01-15 03:19:58 +01:00
}
2021-01-06 23:06:15 +01:00
lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project)
: QMainWindow(Parent), mProject(Project)
{
setWindowTitle(tr("Instructions"));
2020-06-01 03:46:36 +02:00
2021-01-07 19:46:57 +01:00
mInstructions = mProject->GetInstructions();
2021-01-15 23:43:31 +01:00
mPropertiesWidget = new lcInstructionsPropertiesWidget(this, mInstructions);
mPropertiesWidget->setObjectName("InstructionsProperties");
addDockWidget(Qt::RightDockWidgetArea, mPropertiesWidget);
mPageWidget = new lcInstructionsPageWidget(this, mInstructions, mPropertiesWidget);
2021-01-06 23:06:15 +01:00
setCentralWidget(mPageWidget);
2020-06-01 03:46:36 +02:00
2021-01-15 03:19:58 +01:00
mPageListWidget = new lcInstructionsPageListWidget(this, mInstructions);
mPageListWidget->setObjectName("InstructionsPageList");
2021-01-06 23:06:15 +01:00
addDockWidget(Qt::LeftDockWidgetArea, mPageListWidget);
2020-06-01 03:46:36 +02:00
2021-01-06 03:48:12 +01:00
mPageSettingsToolBar = addToolBar(tr("Page Settings"));
mPageSettingsToolBar->setObjectName("PageSettings");
mPageSettingsToolBar->setFloatable(false);
mPageSettingsToolBar->setMovable(false);
mPrintAction = mPageSettingsToolBar->addAction(tr("Print"));
2022-05-16 21:36:52 +02:00
mVerticalPageAction = mPageSettingsToolBar->addAction(tr("Vertical"));
2021-01-06 03:48:12 +01:00
mVerticalPageAction->setCheckable(true);
2022-05-16 21:36:52 +02:00
mHorizontalPageAction = mPageSettingsToolBar->addAction(tr("Horizontal"));
2021-01-06 03:48:12 +01:00
mHorizontalPageAction->setCheckable(true);
mRowsSpinBox = new QSpinBox(mPageSettingsToolBar);
mPageSettingsToolBar->addWidget(mRowsSpinBox);
mColumnsSpinBox = new QSpinBox(mPageSettingsToolBar);
mPageSettingsToolBar->addWidget(mColumnsSpinBox);
QActionGroup* PageDirectionGroup = new QActionGroup(mPageSettingsToolBar);
PageDirectionGroup->addAction(mVerticalPageAction);
PageDirectionGroup->addAction(mHorizontalPageAction);
2021-01-15 03:19:58 +01:00
for (size_t PageNumber = 0; PageNumber < mInstructions->mPages.size(); PageNumber++)
2022-05-16 21:36:52 +02:00
mPageListWidget->mThumbnailsWidget->addItem(QString(tr("Page %1")).arg(PageNumber + 1));
2020-06-01 03:46:36 +02:00
2021-01-06 23:06:15 +01:00
connect(mPageListWidget->mThumbnailsWidget, SIGNAL(currentRowChanged(int)), this, SLOT(CurrentThumbnailChanged(int)));
mPageListWidget->mThumbnailsWidget->setCurrentRow(0);
2021-01-06 03:48:12 +01:00
connect(mPrintAction, &QAction::triggered, this, &lcInstructionsDialog::ShowPrintDialog);
2021-01-07 02:45:38 +01:00
connect(mVerticalPageAction, SIGNAL(toggled(bool)), this, SLOT(UpdatePageSettings()));
connect(mHorizontalPageAction, SIGNAL(toggled(bool)), this, SLOT(UpdatePageSettings()));
2021-01-06 03:48:12 +01:00
connect(mRowsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(UpdatePageSettings()));
connect(mColumnsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(UpdatePageSettings()));
}
void lcInstructionsDialog::ShowPrintDialog()
{
#ifndef QT_NO_PRINTER
int PageCount = static_cast<int>(mInstructions->mPages.size());
QPrinter Printer(QPrinter::HighResolution);
Printer.setFromTo(1, PageCount + 1);
QPrintDialog PrintDialog(&Printer, this);
if (PrintDialog.exec() == QDialog::Accepted)
Print(&Printer);
#endif
}
void lcInstructionsDialog::Print(QPrinter* Printer)
{
#ifndef QT_NO_PRINTER
int DocCopies;
int PageCopies;
const int PageCount = static_cast<int>(mInstructions->mPages.size());
if (Printer->collateCopies())
{
DocCopies = 1;
PageCopies = Printer->supportsMultipleCopies() ? 1 : Printer->copyCount();
}
else
{
DocCopies = Printer->supportsMultipleCopies() ? 1 : Printer->copyCount();
PageCopies = 1;
}
int FromPage = Printer->fromPage();
int ToPage = Printer->toPage();
bool Ascending = true;
if (FromPage == 0 && ToPage == 0)
{
FromPage = 1;
ToPage = PageCount;
}
FromPage = qMax(1, FromPage);
ToPage = qMin(PageCount, ToPage);
if (ToPage < FromPage)
return;
if (Printer->pageOrder() == QPrinter::LastPageFirst)
{
std::swap(FromPage, ToPage);
Ascending = false;
}
QGraphicsScene* Scene = new QGraphicsScene();
QPainter Painter(Printer);
bool FirstPage = true;
for (int DocCopy = 0; DocCopy < DocCopies; DocCopy++)
{
int Page = FromPage;
for (;;)
{
for (int PageCopy = 0; PageCopy < PageCopies; PageCopy++)
{
if (Printer->printerState() == QPrinter::Aborted || Printer->printerState() == QPrinter::Error)
return;
if (!FirstPage)
Printer->newPage();
else
FirstPage = false;
const lcInstructionsPage* InstructionsPage = &mInstructions->mPages[Page - 1];
lcUpdateInstructionsPageScene(mInstructions, InstructionsPage, Scene);
Scene->render(&Painter);
}
if (Page == ToPage)
break;
if (Ascending)
Page++;
else
Page--;
}
}
delete Scene;
#endif
}
2021-01-06 03:48:12 +01:00
void lcInstructionsDialog::UpdatePageSettings()
{
lcInstructionsPageSettings PageSettings;
PageSettings.Rows = mRowsSpinBox->value();
PageSettings.Columns = mColumnsSpinBox->value();
if (mHorizontalPageAction->isChecked())
PageSettings.Direction = lcInstructionsDirection::Horizontal;
else
PageSettings.Direction = lcInstructionsDirection::Vertical;
2021-01-15 03:19:58 +01:00
mInstructions->SetDefaultPageSettings(PageSettings);
2021-01-06 03:48:12 +01:00
// lcInstructionsPage* Page = &mInstructions.mPages[mThumbnailsWidget->currentIndex().row()];
2021-01-06 23:06:15 +01:00
mPageListWidget->mThumbnailsWidget->clear();
2021-01-15 03:19:58 +01:00
for (size_t PageNumber = 0; PageNumber < mInstructions->mPages.size(); PageNumber++)
2021-01-06 23:06:15 +01:00
mPageListWidget->mThumbnailsWidget->addItem(QString("Page %1").arg(PageNumber + 1));
2021-01-06 03:48:12 +01:00
// mThumbnailsWidget->setCurrentRow(0);
// mPageWidget->SetCurrentPage(Page);
2020-06-01 03:46:36 +02:00
}
void lcInstructionsDialog::CurrentThumbnailChanged(int Index)
{
2021-01-15 03:19:58 +01:00
if (Index < 0 || Index >= static_cast<int>(mInstructions->mPages.size()))
2021-01-06 03:48:12 +01:00
{
2021-01-15 23:43:31 +01:00
mPageWidget->SetCurrentPage(nullptr);
2021-01-06 03:48:12 +01:00
return;
}
2021-01-15 03:19:58 +01:00
const lcInstructionsPage* Page = &mInstructions->mPages[Index];
2021-01-06 03:48:12 +01:00
// const lcInstructionsPageSettings& PageSettings = Page->Settings;
2021-01-15 03:19:58 +01:00
const lcInstructionsPageSettings& PageSettings = mInstructions->mPageSettings;
2021-01-06 03:48:12 +01:00
2021-01-15 23:43:31 +01:00
mPageWidget->SetCurrentPage(Page);
2021-01-06 03:48:12 +01:00
if (PageSettings.Direction == lcInstructionsDirection::Horizontal)
{
mHorizontalPageAction->blockSignals(true);
mHorizontalPageAction->setChecked(true);
mHorizontalPageAction->blockSignals(false);
}
else
{
mVerticalPageAction->blockSignals(true);
mVerticalPageAction->setChecked(true);
mVerticalPageAction->blockSignals(false);
}
mRowsSpinBox->blockSignals(true);
mRowsSpinBox->setValue(PageSettings.Rows);
mRowsSpinBox->blockSignals(false);
mColumnsSpinBox->blockSignals(true);
mColumnsSpinBox->setValue(PageSettings.Columns);
mColumnsSpinBox->blockSignals(false);
2020-06-01 03:46:36 +02:00
}