Reorganize Save Image dialog.

This commit is contained in:
Leonardo Zide
2026-05-02 15:44:48 -07:00
parent 6ee89e743c
commit e4b829b7e2
6 changed files with 79 additions and 67 deletions
+25 -1
View File
@@ -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:
+1
View File
@@ -328,6 +328,7 @@ protected:
void ShowRenderDialog(lcRenderDialogMode RenderDialogMode);
void ShowInstructionsDialog();
void ShowPrintDialog();
void ShowImageDialog();
void CreatePreviewWidget();
bool OpenProjectFile(const QString& FileName);
+7 -12
View File
@@ -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
+10 -1
View File
@@ -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);
+30 -44
View File
@@ -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();
}
+6 -9
View File
@@ -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;
};