From aaa33d55e5140e42000b64a45d8b49dd3d611e46 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 14 Apr 2018 18:27:16 -0700 Subject: [PATCH] Save images to the documents folder if a folder is not specified. Fixes #224. --- common/lc_application.cpp | 2 +- common/project.cpp | 21 +++++++++++++++++---- common/project.h | 2 +- qt/lc_qimagedialog.cpp | 2 +- qt/lc_renderdialog.cpp | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 4d1565f1..9744d9ef 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -439,7 +439,7 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& if (SaveImage) { if (ImageName.isEmpty()) - ImageName = mProject->GetImageFileName(); + ImageName = mProject->GetImageFileName(true); if (ImageEnd < ImageStart) ImageEnd = ImageStart; diff --git a/common/project.cpp b/common/project.cpp index 384e6f08..c7f2bc75 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -121,9 +121,9 @@ QString Project::GetTitle() const return mModels.GetSize() == 1 ? tr("New Model.ldr") : tr("New Model.mpd"); } -QString Project::GetImageFileName() const +QString Project::GetImageFileName(bool AllowCurrentFolder) const { - QString FileName = QDir::toNativeSeparators(GetFileName()); + QString FileName = GetFileName(); if (!FileName.isEmpty()) { @@ -132,9 +132,22 @@ QString Project::GetImageFileName() const FileName = FileName.left(FileName.length() - Extension.length() - 1); } else - FileName = QLatin1String("image"); + { + if (!AllowCurrentFolder) + { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) + QStringList cachePathList = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + FileName = cachePathList.first(); +#else + FileName = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); +#endif - return FileName + lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION); + } + + FileName += QLatin1String("image"); + } + + return QDir::toNativeSeparators(FileName) + lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION); } void Project::SetActiveModel(int ModelIndex) diff --git a/common/project.h b/common/project.h index 8d3eb3f8..f60ed336 100644 --- a/common/project.h +++ b/common/project.h @@ -83,7 +83,7 @@ public: return mFileName; } - QString GetImageFileName() const; + QString GetImageFileName(bool AllowCurrentFolder) const; void SetActiveModel(int ModelIndex); void SetActiveModel(const QString& ModelName); diff --git a/qt/lc_qimagedialog.cpp b/qt/lc_qimagedialog.cpp index 633fe126..c1435012 100644 --- a/qt/lc_qimagedialog.cpp +++ b/qt/lc_qimagedialog.cpp @@ -22,7 +22,7 @@ lcQImageDialog::lcQImageDialog(QWidget* Parent) mHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); mStart = Model->GetCurrentStep(); mEnd = Model->GetLastStep(); - mFileName = Project->GetImageFileName(); + mFileName = Project->GetImageFileName(false); ui->fileName->setText(mFileName); ui->width->setText(QString::number(mWidth)); diff --git a/qt/lc_renderdialog.cpp b/qt/lc_renderdialog.cpp index 5f864fb2..fb29fc51 100644 --- a/qt/lc_renderdialog.cpp +++ b/qt/lc_renderdialog.cpp @@ -26,7 +26,7 @@ lcRenderDialog::lcRenderDialog(QWidget* Parent) ui->WidthEdit->setValidator(new QIntValidator(16, INT_MAX)); ui->HeightEdit->setText(QString::number(lcGetProfileInt(LC_PROFILE_POVRAY_HEIGHT))); ui->HeightEdit->setValidator(new QIntValidator(16, INT_MAX)); - ui->OutputEdit->setText(lcGetActiveProject()->GetImageFileName()); + ui->OutputEdit->setText(lcGetActiveProject()->GetImageFileName(false)); QImage Image(LC_POVRAY_PREVIEW_WIDTH, LC_POVRAY_PREVIEW_HEIGHT, QImage::Format_RGB32); Image.fill(QColor(255, 255, 255));