]> cloud.milkyroute.net Git - dolphin.git/commitdiff
InformationPanel: prevent animated images from glitching
authorMéven Car <meven@kde.org>
Wed, 15 Jan 2025 20:15:42 +0000 (21:15 +0100)
committerMéven Car <meven@kde.org>
Fri, 17 Jan 2025 08:56:37 +0000 (08:56 +0000)
And show them in their actual pixel density.

src/panels/information/pixmapviewer.cpp

index 11c13e348b0b50300617a71d2c8cbb00f0e5914e..c870e9c3e13558ef96eefd86b97236ca97926815 100644 (file)
@@ -44,8 +44,11 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
     }
 
     // Avoid flicker with static pixmap if an animated image is running
-    if (m_animatedImage && m_animatedImage->state() == QMovie::Running) {
-        return;
+    if (m_animatedImage) {
+        m_animatedImage->setScaledSize(pixmap.size());
+        if (m_animatedImage->state() == QMovie::Running) {
+            return;
+        }
     }
 
     if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) {
@@ -68,7 +71,6 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
         // If there is no transition animation but an animatedImage
         // and it is not already running, start animating now
         if (m_animatedImage->state() != QMovie::Running) {
-            m_animatedImage->setScaledSize(m_pixmap.size());
             m_animatedImage->start();
         }
     }
@@ -126,7 +128,8 @@ void PixmapViewer::paintEvent(QPaintEvent *event)
         const bool useOldPixmap = (m_transition == SizeTransition) && (m_oldPixmap.width() > m_pixmap.width());
         const QPixmap &largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap;
         if (!largePixmap.isNull()) {
-            const QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, scaledHeight, Qt::IgnoreAspectRatio, Qt::FastTransformation);
+            QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, scaledHeight, Qt::IgnoreAspectRatio, Qt::FastTransformation);
+            scaledPixmap.setDevicePixelRatio(devicePixelRatioF());
 
             style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap);
         }
@@ -144,7 +147,6 @@ 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;