diff --git a/app/graphicsscene.cpp b/app/graphicsscene.cpp index 321d0d9..2cb708b 100644 --- a/app/graphicsscene.cpp +++ b/app/graphicsscene.cpp @@ -48,7 +48,7 @@ void GraphicsScene::showSvg(const QString &filepath) this->setSceneRect(m_theThing->boundingRect()); } -void GraphicsScene::showGif(const QString &filepath) +void GraphicsScene::showAnimated(const QString &filepath) { this->clear(); QMovie * movie = new QMovie(filepath); diff --git a/app/graphicsscene.h b/app/graphicsscene.h index 3909449..75b1ed4 100644 --- a/app/graphicsscene.h +++ b/app/graphicsscene.h @@ -13,7 +13,7 @@ public: void showImage(const QPixmap &pixmap); void showText(const QString &text); void showSvg(const QString &filepath); - void showGif(const QString &filepath); + void showAnimated(const QString &filepath); bool trySetTransformationMode(Qt::TransformationMode mode); diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index e74126f..b59a196 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -39,19 +39,20 @@ void GraphicsView::showFileFromPath(const QString &filePath, bool doRequestGalle if (filePath.endsWith(".svg")) { showSvg(filePath); - } else if (filePath.endsWith(".gif")) { - showGif(filePath); } else { QImageReader imageReader(filePath); imageReader.setAutoTransform(true); imageReader.setDecideFormatFromContent(true); + // Since if the image format / plugin does not support this feature, imageFormat() will returns an invalid format. // So we cannot use imageFormat() and check if it returns QImage::Format_Invalid to detect if we support the file. // QImage::Format imageFormat = imageReader.imageFormat(); if (imageReader.format().isEmpty()) { doRequestGallery = false; showText(tr("File is not a valid image")); - } else if (!imageReader.supportsAnimation() && !imageReader.canRead()) { + } else if (imageReader.supportsAnimation() && imageReader.imageCount() > 1) { + showAnimated(filePath); + } else if (!imageReader.canRead()) { doRequestGallery = false; showText(tr("Image data is invalid or currently unsupported")); } else { @@ -98,10 +99,10 @@ void GraphicsView::showSvg(const QString &filepath) checkAndDoFitInView(); } -void GraphicsView::showGif(const QString &filepath) +void GraphicsView::showAnimated(const QString &filepath) { resetTransform(); - scene()->showGif(filepath); + scene()->showAnimated(filepath); checkAndDoFitInView(); } diff --git a/app/graphicsview.h b/app/graphicsview.h index 02cd6c6..ab324de 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -17,7 +17,7 @@ public: void showImage(const QImage &image); void showText(const QString &text); void showSvg(const QString &filepath); - void showGif(const QString &filepath); + void showAnimated(const QString &filepath); GraphicsScene * scene() const; void setScene(GraphicsScene *scene);