diff --git a/.gitignore b/.gitignore index 0e8cf2fd..fcee8ad4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ *.dae *.3ds *.obj +.vs build debug release diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index 678dda71..bb6e46b2 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -115,6 +115,13 @@ lcCommand gCommands[LC_NUM_COMMANDS] = QT_TRANSLATE_NOOP("Status", "Render the current model using POV-Ray"), "" }, + // LC_FILE_INSTRUCTIONS + { + QT_TRANSLATE_NOOP("Action", "File.Instructions"), + QT_TRANSLATE_NOOP("Menu", "&Instructions..."), + QT_TRANSLATE_NOOP("Status", "Configure instructions layout"), + "" + }, // LC_FILE_PRINT { QT_TRANSLATE_NOOP("Action", "File.Print"), diff --git a/common/lc_commands.h b/common/lc_commands.h index f14c9784..6182b15b 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -18,6 +18,7 @@ enum lcCommandId LC_FILE_EXPORT_POVRAY, LC_FILE_EXPORT_WAVEFRONT, LC_FILE_RENDER, + LC_FILE_INSTRUCTIONS, LC_FILE_PRINT, LC_FILE_PRINT_PREVIEW, LC_FILE_PRINT_BOM, diff --git a/common/lc_instructionsdialog.cpp b/common/lc_instructionsdialog.cpp new file mode 100644 index 00000000..2bbef3ce --- /dev/null +++ b/common/lc_instructionsdialog.cpp @@ -0,0 +1,62 @@ +#include "lc_global.h" +#include "lc_instructionsdialog.h" +#include "project.h" +#include "lc_model.h" + +lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, Project* Project) + : QGraphicsView(Parent) +{ +} + +void lcInstructionsPageWidget::SetCurrentPage(lcInstructionsPageLayout* PageLayout) +{ + QGraphicsScene* Scene = new QGraphicsScene(this); + setScene(Scene); + Scene->setSceneRect(0, 0, 1000, 1000); +// Scene->setBackgroundBrush(Qt::black); + + QImage StepImage = PageLayout->Model->GetStepImage(false, 500, 500, PageLayout->Step); + QGraphicsPixmapItem* StepImageItem = Scene->addPixmap(QPixmap::fromImage(StepImage)); + StepImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable); + + QGraphicsSimpleTextItem* StepNumberItem = Scene->addSimpleText(QString::number(PageLayout->Step), QFont("Helvetica", 96)); + StepNumberItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable); + + QImage PartsImage = PageLayout->Model->GetPartsListImage(300, PageLayout->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)); +} + +lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project) + : QMainWindow(Parent), mProject(Project) +{ + QWidget* CentralWidget = new QWidget(this); + setCentralWidget(CentralWidget); + setWindowTitle(tr("Instructions")); + + QVBoxLayout* Layout = new QVBoxLayout(CentralWidget); + + QSplitter* Splitter = new QSplitter(CentralWidget); + Splitter->setOrientation(Qt::Horizontal); + Layout->addWidget(Splitter); + + mThumbnailsWidget = new QListWidget(Splitter); + Splitter->addWidget(mThumbnailsWidget); + + mPageWidget = new lcInstructionsPageWidget(Splitter, mProject); + Splitter->addWidget(mPageWidget); + + mPageLayouts = mProject->GetPageLayouts(); + + for (size_t PageNumber = 0; PageNumber < mPageLayouts.size(); PageNumber++) + mThumbnailsWidget->addItem(QString("Page %1").arg(PageNumber + 1)); + + connect(mThumbnailsWidget, SIGNAL(currentRowChanged(int)), this, SLOT(CurrentThumbnailChanged(int))); + mThumbnailsWidget->setCurrentRow(0); +} + +void lcInstructionsDialog::CurrentThumbnailChanged(int Index) +{ + mPageWidget->SetCurrentPage(&mPageLayouts[Index]); +} diff --git a/common/lc_instructionsdialog.h b/common/lc_instructionsdialog.h new file mode 100644 index 00000000..72c07985 --- /dev/null +++ b/common/lc_instructionsdialog.h @@ -0,0 +1,33 @@ +#pragma once + +struct lcInstructionsPageLayout; + +class lcInstructionsPageWidget : public QGraphicsView +{ + Q_OBJECT + +public: + lcInstructionsPageWidget(QWidget* Parent, Project* Project); + + void SetCurrentPage(lcInstructionsPageLayout* PageLayout); +}; + +class lcInstructionsDialog : public QMainWindow +{ + Q_OBJECT + +public: + lcInstructionsDialog(QWidget* Parent, Project* Project); + +protected slots: + void CurrentThumbnailChanged(int Index); + +protected: + Project* mProject; + + int mCurrentPageNumber; + std::vector mPageLayouts; + + QListWidget* mThumbnailsWidget; + lcInstructionsPageWidget* mPageWidget; +}; diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index c10b6a91..94cc7a95 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -14,6 +14,7 @@ #include "lc_setsdatabasedialog.h" #include "lc_qhtmldialog.h" #include "lc_renderdialog.h" +#include "lc_instructionsdialog.h" #include "lc_profile.h" #include "view.h" #include "project.h" @@ -480,6 +481,7 @@ void lcMainWindow::CreateMenus() ExportMenu->addAction(mActions[LC_FILE_EXPORT_WAVEFRONT]); FileMenu->addSeparator(); FileMenu->addAction(mActions[LC_FILE_RENDER]); + FileMenu->addAction(mActions[LC_FILE_INSTRUCTIONS]); FileMenu->addAction(mActions[LC_FILE_PRINT]); FileMenu->addAction(mActions[LC_FILE_PRINT_PREVIEW]); // FileMenu->addAction(mActions[LC_FILE_PRINT_BOM]); @@ -1037,7 +1039,7 @@ void lcMainWindow::Print(QPrinter* Printer) int DocCopies; int PageCopies; - std::vector> PageLayouts = lcGetActiveProject()->GetPageLayouts(); + std::vector PageLayouts = lcGetActiveProject()->GetPageLayouts(); const int PageCount = static_cast(PageLayouts.size()); if (Printer->collateCopies()) @@ -1107,8 +1109,8 @@ void lcMainWindow::Print(QPrinter* Printer) int StepWidth = MarginRect.width(); int StepHeight = MarginRect.height(); - lcModel* Model = PageLayouts[Page - 1].first; - lcStep Step = PageLayouts[Page - 1].second; + lcModel* Model = PageLayouts[Page - 1].Model; + lcStep Step = PageLayouts[Page - 1].Step; QImage Image = Model->GetStepImage(false, StepWidth, StepHeight, Step); Painter.drawImage(MarginRect.left(), MarginRect.top(), Image); @@ -1201,6 +1203,14 @@ void lcMainWindow::ShowRenderDialog() Dialog.exec(); } +void lcMainWindow::ShowInstructionsDialog() +{ + lcInstructionsDialog* Dialog = new lcInstructionsDialog(this, lcGetActiveProject()); + Dialog->setWindowModality(Qt::ApplicationModal); + Dialog->setAttribute(Qt::WA_DeleteOnClose); + Dialog->show(); +} + void lcMainWindow::ShowPrintDialog() { #ifndef QT_NO_PRINTER @@ -2522,6 +2532,10 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) ShowRenderDialog(); break; + case LC_FILE_INSTRUCTIONS: + ShowInstructionsDialog(); + break; + case LC_FILE_PRINT_PREVIEW: TogglePrintPreview(); break; diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index aced6c3a..3ce7355b 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -379,6 +379,7 @@ protected: void ShowAboutDialog(); void ShowHTMLDialog(); void ShowRenderDialog(); + void ShowInstructionsDialog(); void ShowPrintDialog(); bool OpenProjectFile(const QString& FileName); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 7e5584c3..1a78895b 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1695,9 +1695,9 @@ void lcModel::SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Z } } -std::vector> lcModel::GetPageLayouts(std::vector& AddedModels) +std::vector lcModel::GetPageLayouts(std::vector& AddedModels) { - std::vector> PageLayouts; + std::vector PageLayouts; if (std::find(AddedModels.begin(), AddedModels.end(), this) != AddedModels.end()) return PageLayouts; @@ -1716,7 +1716,7 @@ std::vector> lcModel::GetPageLayouts(std::vector CurrentStep) { - PageLayouts.emplace_back(std::make_pair(this, CurrentStep)); + PageLayouts.emplace_back(lcInstructionsPageLayout{ this, CurrentStep }); CurrentStep++; } @@ -1725,12 +1725,12 @@ std::vector> lcModel::GetPageLayouts(std::vectormPieceInfo->IsModel()) { lcModel* SubModel = Piece->mPieceInfo->GetModel(); - std::vector> SubModelLayouts = SubModel->GetPageLayouts(AddedModels); + std::vector SubModelLayouts = SubModel->GetPageLayouts(AddedModels); PageLayouts.insert(PageLayouts.end(), std::make_move_iterator(SubModelLayouts.begin()), std::make_move_iterator(SubModelLayouts.end())); } } - PageLayouts.emplace_back(std::make_pair(this, CurrentStep)); + PageLayouts.emplace_back(lcInstructionsPageLayout{ this, CurrentStep }); CurrentStep++; } diff --git a/common/lc_model.h b/common/lc_model.h index 370d67d3..42902074 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -20,6 +20,12 @@ class lcGLWidget; +struct lcInstructionsPageLayout +{ + lcModel* Model; + lcStep Step; +}; + enum class lcSelectionMode { Single, @@ -242,7 +248,7 @@ public: QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step); QImage GetPartsListImage(int MaxWidth, lcStep Step) const; void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End); - std::vector> GetPageLayouts(std::vector& AddedModels); + std::vector GetPageLayouts(std::vector& AddedModels); void RayTest(lcObjectRayTest& ObjectRayTest) const; void BoxTest(lcObjectBoxTest& ObjectBoxTest) const; diff --git a/common/project.cpp b/common/project.cpp index 5dc67d87..02f757c8 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1473,14 +1473,14 @@ void Project::ExportCSV() } } -std::vector> Project::GetPageLayouts() const +std::vector Project::GetPageLayouts() const { std::vector AddedModels; - if (mActiveModel) - return mActiveModel->GetPageLayouts(AddedModels); + if (!mModels.IsEmpty()) + return mModels[0]->GetPageLayouts(AddedModels); - return std::vector>(); + return std::vector(); } void Project::ExportHTML(const lcHTMLExportOptions& Options) diff --git a/common/project.h b/common/project.h index b80c28fe..21e1f56a 100644 --- a/common/project.h +++ b/common/project.h @@ -36,6 +36,8 @@ enum LC_MOUSE_TRACK LC_TRACK_RIGHT }; +struct lcInstructionsPageLayout; + class Project { public: @@ -80,7 +82,7 @@ public: QString GetImageFileName(bool AllowCurrentFolder) const; - std::vector> GetPageLayouts() const; + std::vector GetPageLayouts() const; void SetActiveModel(int ModelIndex); void SetActiveModel(const QString& FileName); diff --git a/leocad.pro b/leocad.pro index a6b4eea5..10738e81 100644 --- a/leocad.pro +++ b/leocad.pro @@ -166,6 +166,7 @@ macx { } SOURCES += common/view.cpp \ + common/lc_instructionsdialog.cpp \ common/texfont.cpp \ common/project.cpp \ common/pieceinf.cpp \ @@ -226,6 +227,7 @@ SOURCES += common/view.cpp \ qt/lc_setsdatabasedialog.cpp \ common/lc_partpalettedialog.cpp HEADERS += \ + common/lc_instructionsdialog.h \ common/view.h \ common/texfont.h \ common/project.h \ @@ -290,7 +292,7 @@ HEADERS += \ qt/lc_renderdialog.h \ qt/lc_setsdatabasedialog.h \ common/lc_partpalettedialog.h -FORMS += \ +FORMS += \ qt/lc_qarraydialog.ui \ qt/lc_qgroupdialog.ui \ qt/lc_qaboutdialog.ui \