From e4b829b7e2f0a6ff6a37fac7ab823e95be28c65d Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 2 May 2026 15:44:48 -0700 Subject: [PATCH] Reorganize Save Image dialog. --- common/lc_mainwindow.cpp | 26 +++++++++++++- common/lc_mainwindow.h | 1 + common/project.cpp | 19 ++++------- common/project.h | 11 +++++- qt/lc_qimagedialog.cpp | 74 ++++++++++++++++------------------------ qt/lc_qimagedialog.h | 15 ++++---- 6 files changed, 79 insertions(+), 67 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 4d67f7f1..fefaf12c 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -14,6 +14,7 @@ #include "lc_htmldialog.h" #include "lc_renderdialog.h" #include "lc_instructionsdialog.h" +#include "lc_qimagedialog.h" #include "lc_profile.h" #include "lc_view.h" #include "project.h" @@ -1360,6 +1361,29 @@ void lcMainWindow::ShowPrintDialog() #endif } +void lcMainWindow::ShowImageDialog() +{ + lcImageDialogOptions Options; + Project* Project = lcGetActiveProject(); + lcModel* Model = Project->GetActiveModel(); + + Options.Width = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); + Options.Height = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); + Options.Start = Model->GetCurrentStep(); + Options.End = Model->GetLastStep(); + Options.FilePath = Project->GetImageFileName(false); + + lcImageDialog Dialog(this, &Options); + + if (Dialog.exec() != QDialog::Accepted) + return; + + lcSetProfileInt(LC_PROFILE_IMAGE_WIDTH, Options.Width); + lcSetProfileInt(LC_PROFILE_IMAGE_HEIGHT, Options.Height); + + lcGetActiveProject()->SaveImage(Options); +} + void lcMainWindow::SetShadingMode(lcShadingMode ShadingMode) { lcGetPreferences().mShadingMode = ShadingMode; @@ -2639,7 +2663,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_FILE_SAVE_IMAGE: - lcGetActiveProject()->SaveImage(); + ShowImageDialog(); break; case LC_FILE_IMPORT_LDD: diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index baf8f477..84b21c64 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -328,6 +328,7 @@ protected: void ShowRenderDialog(lcRenderDialogMode RenderDialogMode); void ShowInstructionsDialog(); void ShowPrintDialog(); + void ShowImageDialog(); void CreatePreviewWidget(); bool OpenProjectFile(const QString& FileName); diff --git a/common/project.cpp b/common/project.cpp index f47302e1..8b5e9f35 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -14,7 +14,6 @@ #include "lc_profile.h" #include "lc_file.h" #include "lc_zipfile.h" -#include "lc_qimagedialog.h" #include "lc_modellistdialog.h" #include "lc_bricklink.h" #include "lc_string.h" @@ -2601,22 +2600,18 @@ bool Project::ExportWavefront(const QString& FileName) return true; } -void Project::SaveImage() +void Project::SaveImage(const lcImageDialogOptions& Options) { - lcImageDialog Dialog(gMainWindow); - - if (Dialog.exec() != QDialog::Accepted) - return; - - QString Extension = QFileInfo(Dialog.mFileName).suffix(); + QString FilePath = Options.FilePath; + QString Extension = QFileInfo(FilePath).suffix(); if (!Extension.isEmpty()) - lcSetProfileString(LC_PROFILE_IMAGE_EXTENSION, Dialog.mFileName.right(Extension.length() + 1)); + lcSetProfileString(LC_PROFILE_IMAGE_EXTENSION, FilePath.right(Extension.length() + 1)); - if (Dialog.mStart != Dialog.mEnd) - Dialog.mFileName = Dialog.mFileName.insert(Dialog.mFileName.length() - Extension.length() - 1, QLatin1String("%1")); + if (Options.Start != Options.End) + FilePath = FilePath.insert(FilePath.length() - Extension.length() - 1, QLatin1String("%1")); - mActiveModel->SaveStepImages(Dialog.mFileName, Dialog.mStart != Dialog.mEnd, false, Dialog.mWidth, Dialog.mHeight, Dialog.mStart, Dialog.mEnd); + mActiveModel->SaveStepImages(FilePath, Options.Start != Options.End, false, Options.Width, Options.Height, Options.Start, Options.End); } void Project::UpdatePieceInfo(PieceInfo* Info) const diff --git a/common/project.h b/common/project.h index e7022d59..d1c243f5 100644 --- a/common/project.h +++ b/common/project.h @@ -27,6 +27,15 @@ public: bool PartsListEnd; }; +struct lcImageDialogOptions +{ + QString FilePath; + int Width; + int Height; + int Start; + int End; +}; + class Project { public: @@ -83,7 +92,7 @@ public: bool ImportLDD(const QString& FileName); bool ImportInventory(const QByteArray& Inventory, const QString& Name, const QString& Description); - void SaveImage(); + void SaveImage(const lcImageDialogOptions& Options); bool ExportCurrentStep(const QString& FileName); bool ExportModel(const QString& FileName, lcModel* Model) const; bool Export3DStudio(const QString& FileName); diff --git a/qt/lc_qimagedialog.cpp b/qt/lc_qimagedialog.cpp index 874ecbaa..2a59f7ca 100644 --- a/qt/lc_qimagedialog.cpp +++ b/qt/lc_qimagedialog.cpp @@ -1,13 +1,10 @@ #include "lc_global.h" #include "lc_qimagedialog.h" #include "ui_lc_qimagedialog.h" -#include "lc_application.h" #include "project.h" -#include "lc_model.h" -#include "lc_profile.h" -lcImageDialog::lcImageDialog(QWidget* Parent) - : QDialog(Parent), ui(new Ui::lcImageDialog) +lcImageDialog::lcImageDialog(QWidget* Parent, lcImageDialogOptions* Options) + : QDialog(Parent), mOptions(Options), ui(new Ui::lcImageDialog) { ui->setupUi(this); @@ -18,19 +15,11 @@ lcImageDialog::lcImageDialog(QWidget* Parent) ui->firstStep->setValidator(new QIntValidator(this)); ui->lastStep->setValidator(new QIntValidator(this)); - Project* Project = lcGetActiveProject(); - lcModel* Model = Project->GetActiveModel(); - mWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); - mHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); - mStart = Model->GetCurrentStep(); - mEnd = Model->GetLastStep(); - mFileName = Project->GetImageFileName(false); - - ui->fileName->setText(mFileName); - ui->width->setText(QString::number(mWidth)); - ui->height->setText(QString::number(mHeight)); - ui->firstStep->setText(QString::number(mStart)); - ui->lastStep->setText(QString::number(mEnd)); + ui->fileName->setText(mOptions->FilePath); + ui->width->setText(QString::number(mOptions->Width)); + ui->height->setText(QString::number(mOptions->Height)); + ui->firstStep->setText(QString::number(mOptions->Start)); + ui->lastStep->setText(QString::number(mOptions->End)); ui->rangeCurrent->setChecked(true); } @@ -41,75 +30,72 @@ lcImageDialog::~lcImageDialog() void lcImageDialog::accept() { - QString fileName = ui->fileName->text(); + QString FilePath = ui->fileName->text(); - if (fileName.isEmpty()) + if (FilePath.isEmpty()) { QMessageBox::information(this, tr("Error"), tr("Output File cannot be empty.")); return; } - int width = ui->width->text().toInt(); + int Width = ui->width->text().toInt(); - if (width < 1 || width > 32768) + if (Width < 1 || Width > 32768) { QMessageBox::information(this, tr("Error"), tr("Please enter a width between 1 and 32768.")); return; } - int height = ui->height->text().toInt(); + int Height = ui->height->text().toInt(); - if (height < 1 || height > 32768) + if (Height < 1 || Height > 32768) { QMessageBox::information(this, tr("Error"), tr("Please enter a height between 1 and 32768.")); return; } - int start = mStart, end = mStart; + int Start = mOptions->Start, End = mOptions->Start; if (ui->rangeAll->isChecked()) { - start = 1; - end = mEnd; + Start = 1; + End = mOptions->End; } else if (ui->rangeCurrent->isChecked()) { - start = mStart; - end = mStart; + Start = mOptions->Start; + End = mOptions->Start; } else if (ui->rangeCustom->isChecked()) { - start = ui->firstStep->text().toInt(); + Start = ui->firstStep->text().toInt(); - if (start < 1 || start > mEnd) + if (Start < 1 || Start > mOptions->End) { - QMessageBox::information(this, tr("Error"), tr("First step must be between 1 and %1.").arg(QString::number(mEnd))); + QMessageBox::information(this, tr("Error"), tr("First step must be between 1 and %1.").arg(QString::number(mOptions->End))); return; } - end = ui->lastStep->text().toInt(); + End = ui->lastStep->text().toInt(); - if (end < 1 || end > mEnd) + if (End < 1 || End > mOptions->End) { - QMessageBox::information(this, tr("Error"), tr("Last step must be between 1 and %1.").arg(QString::number(mEnd))); + QMessageBox::information(this, tr("Error"), tr("Last step must be between 1 and %1.").arg(QString::number(mOptions->End))); return; } - if (end < start) + if (End < Start) { QMessageBox::information(this, tr("Error"), tr("Last step must be greater than first step.")); return; } } - mFileName = fileName; - mWidth = width; - mHeight = height; - mStart = start; - mEnd = end; - - lcSetProfileInt(LC_PROFILE_IMAGE_WIDTH, mWidth); - lcSetProfileInt(LC_PROFILE_IMAGE_HEIGHT, mHeight); + mOptions->FilePath = FilePath; + mOptions->Width = Width; + mOptions->Height = Height; + mOptions->Start = Start; + mOptions->End = End; QDialog::accept(); } diff --git a/qt/lc_qimagedialog.h b/qt/lc_qimagedialog.h index 1b1ea588..6ae40673 100644 --- a/qt/lc_qimagedialog.h +++ b/qt/lc_qimagedialog.h @@ -4,20 +4,16 @@ namespace Ui { class lcImageDialog; } +struct lcImageDialogOptions; + class lcImageDialog : public QDialog { Q_OBJECT public: - lcImageDialog(QWidget* Parent); - ~lcImageDialog(); - - QString mFileName; - int mWidth; - int mHeight; - int mStart; - int mEnd; - + lcImageDialog(QWidget* Parent, lcImageDialogOptions* Options); + virtual ~lcImageDialog(); + public slots: void accept() override; @@ -25,6 +21,7 @@ private slots: void FileNameBrowseClicked(); private: + lcImageDialogOptions* mOptions; Ui::lcImageDialog* ui; };