leocad/common/lc_instructionsdialog.cpp

261 lines
9.2 KiB
C++
Raw Normal View History

2020-06-01 03:46:36 +02:00
#include "lc_global.h"
#include "lc_instructionsdialog.h"
2021-01-07 02:45:38 +01:00
#include "lc_collapsiblewidget.h"
2020-06-01 03:46:36 +02:00
#include "project.h"
#include "lc_model.h"
2021-01-07 02:45:38 +01:00
#include "lc_qutils.h"
2021-01-07 19:46:57 +01:00
#include "lc_pagesetupdialog.h"
2020-06-01 03:46:36 +02:00
2021-01-06 03:48:12 +01:00
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent)
2020-06-01 03:46:36 +02:00
: QGraphicsView(Parent)
{
}
2021-01-06 03:48:12 +01:00
void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
2020-06-01 03:46:36 +02:00
{
QGraphicsScene* Scene = new QGraphicsScene(this);
setScene(Scene);
Scene->setSceneRect(0, 0, 1000, 1000);
// Scene->setBackgroundBrush(Qt::black);
2021-01-06 03:48:12 +01:00
if (Page)
{
for (const lcInstructionsStep& Step : Page->Steps)
{
QImage StepImage = Step.Model->GetStepImage(false, 500, 500, Step.Step);
QGraphicsPixmapItem* StepImageItem = Scene->addPixmap(QPixmap::fromImage(StepImage));
StepImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
StepImageItem->setPos(1000.0 * Step.Rect.x(), 1000.0 * Step.Rect.y());
2020-06-01 03:46:36 +02:00
2021-01-06 03:48:12 +01:00
QGraphicsSimpleTextItem* StepNumberItem = Scene->addSimpleText(QString::number(Step.Step), QFont("Helvetica", 96));
StepNumberItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
StepNumberItem->setPos(1000.0 * Step.Rect.x(), 1000.0 * Step.Rect.y());
2020-06-01 03:46:36 +02:00
2021-01-06 03:48:12 +01:00
QImage PartsImage = Step.Model->GetPartsListImage(300, Step.Step);
QGraphicsPixmapItem* PartsImageItem = Scene->addPixmap(QPixmap::fromImage(PartsImage));
PartsImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
PartsImageItem->setPos(StepNumberItem->pos() + QPointF(StepNumberItem->sceneBoundingRect().width(), 0));
}
}
2020-06-01 03:46:36 +02:00
}
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();
PageSetupButton->setText("Page Setup");
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-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-06 23:06:15 +01:00
mPageWidget = new lcInstructionsPageWidget(this);
setCentralWidget(mPageWidget);
2020-06-01 03:46:36 +02:00
2021-01-07 19:46:57 +01:00
mPageListWidget = new lcInstructionsPageListWidget(this, &mInstructions);
2021-01-06 23:06:15 +01:00
mPageListWidget->setObjectName("PageList");
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);
mVerticalPageAction = mPageSettingsToolBar->addAction("Vertical");
mVerticalPageAction->setCheckable(true);
mHorizontalPageAction = mPageSettingsToolBar->addAction("Horizontal");
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);
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));
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
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::UpdatePageSettings()
{
lcInstructionsPageSettings PageSettings;
PageSettings.Rows = mRowsSpinBox->value();
PageSettings.Columns = mColumnsSpinBox->value();
if (mHorizontalPageAction->isChecked())
PageSettings.Direction = lcInstructionsDirection::Horizontal;
else
PageSettings.Direction = lcInstructionsDirection::Vertical;
mInstructions.SetDefaultPageSettings(PageSettings);
// lcInstructionsPage* Page = &mInstructions.mPages[mThumbnailsWidget->currentIndex().row()];
2021-01-06 23:06:15 +01:00
mPageListWidget->mThumbnailsWidget->clear();
2021-01-06 03:48:12 +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-07 02:45:38 +01:00
if (Index < 0 || Index >= static_cast<int>(mInstructions.mPages.size()))
2021-01-06 03:48:12 +01:00
{
mPageWidget->SetCurrentPage(nullptr);
return;
}
const lcInstructionsPage* Page = &mInstructions.mPages[Index];
// const lcInstructionsPageSettings& PageSettings = Page->Settings;
const lcInstructionsPageSettings& PageSettings = mInstructions.mPageSettings;
mPageWidget->SetCurrentPage(Page);
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
}