]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/pixmapviewer.cpp
panels/information: Fix preview size for animated images
[dolphin.git] / src / panels / information / pixmapviewer.cpp
index c870e9c3e13558ef96eefd86b97236ca97926815..b18c9e64ef4c0522ccd062274c431ef97aacce9c 100644 (file)
@@ -43,14 +43,6 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
         return;
     }
 
-    // Avoid flicker with static pixmap if an animated image is running
-    if (m_animatedImage) {
-        m_animatedImage->setScaledSize(pixmap.size());
-        if (m_animatedImage->state() == QMovie::Running) {
-            return;
-        }
-    }
-
     if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) {
         m_pendingPixmaps.enqueue(pixmap);
         if (m_pendingPixmaps.count() > 5) {
@@ -62,6 +54,12 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
 
     m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
     m_pixmap = pixmap;
+
+    // Avoid flicker with static pixmap if an animated image is running
+    if (m_animatedImage && m_animatedImage->state() == QMovie::Running) {
+        return;
+    }
+
     update();
 
     const bool animateTransition = (m_transition != NoTransition) && (m_pixmap.size() != m_oldPixmap.size());
@@ -99,7 +97,6 @@ void PixmapViewer::setAnimatedImageFileName(const QString &fileName)
     }
 
     if (m_animatedImage->fileName() != fileName) {
-        m_animatedImage->stop();
         m_animatedImage->setFileName(fileName);
     }
 
@@ -147,6 +144,7 @@ void PixmapViewer::checkPendingPixmaps()
         update();
         m_animation.start();
     } else if (m_hasAnimatedImage) {
+        m_animatedImage->setScaledSize(m_pixmap.size());
         m_animatedImage->start();
     } else {
         m_oldPixmap = m_pixmap;
@@ -158,6 +156,10 @@ void PixmapViewer::updateAnimatedImageFrame()
     Q_ASSERT(m_animatedImage);
 
     m_pixmap = m_animatedImage->currentPixmap();
+    if (m_pixmap.width() > m_sizeHint.width() || m_pixmap.height() > m_sizeHint.height()) {
+        m_pixmap = m_pixmap.scaled(m_sizeHint, Qt::KeepAspectRatio);
+        m_animatedImage->setScaledSize(m_pixmap.size());
+    }
     update();
 }
 
@@ -166,6 +168,8 @@ void PixmapViewer::stopAnimatedImage()
     if (m_hasAnimatedImage) {
         m_animatedImage->stop();
         m_hasAnimatedImage = false;
+        delete m_animatedImage;
+        m_animatedImage = nullptr;
     }
 }