diff --git a/app/src/importimageseqdialog.cpp b/app/src/importimageseqdialog.cpp index 383bf0f46..a4ac70378 100644 --- a/app/src/importimageseqdialog.cpp +++ b/app/src/importimageseqdialog.cpp @@ -22,6 +22,7 @@ GNU General Public License for more details. #include "app_util.h" #include "editor.h" +#include "errordialog.h" #include "predefinedsetmodel.h" #include "layermanager.h" #include "viewmanager.h" @@ -178,37 +179,25 @@ void ImportImageSeqDialog::importArbitrarySequence() int imagesImportedSoFar = 0; progress.setMaximum(totalImagesToImport); - QString failedFiles; - bool failedImport = false; for (const QString& strImgFile : files) { QString strImgFileLower = strImgFile.toLower(); - if (strImgFileLower.endsWith(".png") || - strImgFileLower.endsWith(".jpg") || - strImgFileLower.endsWith(".jpeg") || - strImgFileLower.endsWith(".bmp") || - strImgFileLower.endsWith(".tif") || - strImgFileLower.endsWith(".tiff")) + Status st = mEditor->importImage(strImgFile); + if (!st.ok()) { - mEditor->importImage(strImgFile); + ErrorDialog errorDialog(st.title(), st.description(), st.details().html()); + errorDialog.exec(); + break; + } - imagesImportedSoFar++; - progress.setValue(imagesImportedSoFar); - QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); // Required to make progress bar update + imagesImportedSoFar++; + progress.setValue(imagesImportedSoFar); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); // Required to make progress bar update - if (progress.wasCanceled()) - { - break; - } - } - else + if (progress.wasCanceled()) { - failedFiles += strImgFile + "\n"; - if (!failedImport) - { - failedImport = true; - } + break; } for (int i = 1; i < number; i++) @@ -217,15 +206,6 @@ void ImportImageSeqDialog::importArbitrarySequence() } } - if (failedImport) - { - QMessageBox::warning(mParent, - tr("Warning"), - tr("Unable to import") + failedFiles, - QMessageBox::Ok, - QMessageBox::Ok); - } - emit notifyAnimationLengthChanged(); progress.close(); @@ -324,7 +304,13 @@ void ImportImageSeqDialog::importPredefinedSet() const QString& filePath = keySet.filePathAt(i); mEditor->scrubTo(frameIndex); - bool ok = mEditor->importImage(filePath); + Status st = mEditor->importImage(filePath); + if (!st.ok()) + { + ErrorDialog errorDialog(st.title(), st.description(), st.details().html()); + errorDialog.exec(); + break; + } imagesImportedSoFar++; progress.setValue(imagesImportedSoFar); @@ -334,8 +320,6 @@ void ImportImageSeqDialog::importPredefinedSet() { break; } - - if (!ok) { return;} } emit notifyAnimationLengthChanged(); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index aef3fd73a..bbe92fea0 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -868,14 +868,11 @@ void MainWindow2::importImage() return; } - bool ok = mEditor->importImage(strFilePath); - if (!ok) + Status st = mEditor->importImage(strFilePath); + if (!st.ok()) { - QMessageBox::warning(this, - tr("Warning"), - tr("Unable to import image.
TIP: Use Bitmap layer to import bitmaps."), - QMessageBox::Ok, - QMessageBox::Ok); + ErrorDialog errorDialog(st.title(), st.description(), st.details().html()); + errorDialog.exec(); return; } @@ -979,29 +976,27 @@ void MainWindow2::importGIF() progress.show(); QString strImgFileLower = gifDialog->getFilePath(); - bool importOK = strImgFileLower.toLower().endsWith(".gif"); - - if (importOK) + if (!strImgFileLower.toLower().endsWith(".gif")) + { + ErrorDialog errorDialog(tr("Import failed"), tr("You can only import files ending with .gif.")); + errorDialog.exec(); + } + else { - bool ok = mEditor->importGIF(strImgFileLower, space); - if (!ok) - importOK = false; + Status st = mEditor->importGIF(strImgFileLower, space); progress.setValue(50); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); // Required to make progress bar update - } - if (!importOK) - { - QMessageBox::warning(this, - tr("Warning"), - tr("was unable to import %1").arg(strImgFileLower), - QMessageBox::Ok, - QMessageBox::Ok); - } + progress.setValue(100); + progress.close(); - progress.setValue(100); - progress.close(); + if (!st.ok()) + { + ErrorDialog errorDialog(st.title(), st.description(), st.details().html()); + errorDialog.exec(); + } + } mSuppressAutoSaveDialog = false; } diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 2a9cc9d68..b6d3d44bf 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -914,17 +914,42 @@ void Editor::updateObject() emit updateLayerCount(); } -bool Editor::importBitmapImage(const QString& filePath, int space) +Status Editor::importBitmapImage(const QString& filePath, int space) { QImageReader reader(filePath); Q_ASSERT(layers()->currentLayer()->type() == Layer::BITMAP); auto layer = static_cast(layers()->currentLayer()); + Status status = Status::OK; + DebugDetails dd; + dd << QString("Raw file path: %1").arg(filePath); + QImage img(reader.size(), QImage::Format_ARGB32_Premultiplied); if (img.isNull()) { - return false; + QString format = reader.format(); + if (!format.isEmpty()) + { + dd << QString("QImageReader format: %1").arg(format); + } + dd << QString("QImageReader ImageReaderError type: %1").arg(reader.errorString()); + + QString errorDesc; + switch(reader.error()) + { + case QImageReader::ImageReaderError::FileNotFoundError: + errorDesc = tr("File not found at path \"%1\". Please check the image is present at the specified location and try again.").arg(filePath); + break; + case QImageReader::UnsupportedFormatError: + errorDesc = tr("Image format is not supported. Please convert the image file to one of the following formats and try again:\n%1") + .arg((QString)reader.supportedImageFormats().join(", ")); + break; + default: + errorDesc = tr("An error has occurred while reading the image. Please check that the file is a valid image and try again."); + } + + status = Status(Status::FAIL, dd, tr("Import failed"), errorDesc); } const QPoint pos(view()->getImportView().dx() - (img.width() / 2), @@ -958,15 +983,19 @@ bool Editor::importBitmapImage(const QString& filePath, int space) } } - return true; + return status; } -bool Editor::importVectorImage(const QString& filePath) +Status Editor::importVectorImage(const QString& filePath) { Q_ASSERT(layers()->currentLayer()->type() == Layer::VECTOR); auto layer = static_cast(layers()->currentLayer()); + Status status = Status::OK; + DebugDetails dd; + dd << QString("Raw file path: %1").arg(filePath); + VectorImage* vectorImage = layer->getVectorImageAtFrame(currentFrame()); if (vectorImage == nullptr) { @@ -984,14 +1013,20 @@ bool Editor::importVectorImage(const QString& filePath) backup(tr("Import Image")); } + else { + status = Status(Status::FAIL, dd, tr("Import failed"), tr("You cannot import images into a vector layer.")); + } - return ok; + return status; } -bool Editor::importImage(const QString& filePath) +Status Editor::importImage(const QString& filePath) { Layer* layer = layers()->currentLayer(); + DebugDetails dd; + dd << QString("Raw file path: %1").arg(filePath); + if (view()->getImportFollowsCamera()) { LayerCamera* camera = static_cast(layers()->getLastCameraLayer()); @@ -1008,21 +1043,22 @@ bool Editor::importImage(const QString& filePath) return importVectorImage(filePath); default: - { - //mLastError = Status::ERROR_INVALID_LAYER_TYPE; - return false; - } + dd << QString("Current layer: %1").arg(layer->type()); + return Status(Status::ERROR_INVALID_LAYER_TYPE, dd, tr("Import failed"), tr("You can only import images to a bitmap layer.")); } } -bool Editor::importGIF(const QString& filePath, int numOfImages) +Status Editor::importGIF(const QString& filePath, int numOfImages) { Layer* layer = layers()->currentLayer(); - if (layer->type() == Layer::BITMAP) + if (layer->type() != Layer::BITMAP) { - return importBitmapImage(filePath, numOfImages); + DebugDetails dd; + dd << QString("Raw file path: %1").arg(filePath); + dd << QString("Current layer: %1").arg(layer->type()); + return Status(Status::ERROR_INVALID_LAYER_TYPE, dd, tr("Import failed"), tr("You can only import images to a bitmap layer.")); } - return false; + return importBitmapImage(filePath, numOfImages); } void Editor::selectAll() const diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 2b517bdfb..e2700bf4a 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -167,8 +167,8 @@ class Editor : public QObject void clearCurrentFrame(); - bool importImage(const QString& filePath); - bool importGIF(const QString& filePath, int numOfImages = 0); + Status importImage(const QString& filePath); + Status importGIF(const QString& filePath, int numOfImages = 0); void restoreKey(); void scrubNextKeyFrame(); @@ -224,8 +224,8 @@ class Editor : public QObject void resetAutoSaveCounter(); private: - bool importBitmapImage(const QString&, int space = 0); - bool importVectorImage(const QString&); + Status importBitmapImage(const QString&, int space = 0); + Status importVectorImage(const QString&); void pasteToCanvas(BitmapImage* bitmapImage, int frameNumber); void pasteToCanvas(VectorImage* vectorImage, int frameNumber);