summary refs log tree commit diff
path: root/src/ui/MxcAnimatedImage.h
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-09-30 04:03:39 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-09-30 04:03:39 +0200
commit78784babd1bac589216fc768d927c7af6bc67226 (patch)
treea802abce4a86856872f1dd7ec199624b5edb1109 /src/ui/MxcAnimatedImage.h
parentDisable manpage on debian (diff)
downloadnheko-78784babd1bac589216fc768d927c7af6bc67226.tar.xz
Revert accidental animated image change
Diffstat (limited to 'src/ui/MxcAnimatedImage.h')
-rw-r--r--src/ui/MxcAnimatedImage.h31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h
index 2b067166..8891e57e 100644
--- a/src/ui/MxcAnimatedImage.h
+++ b/src/ui/MxcAnimatedImage.h
@@ -6,7 +6,7 @@
 #pragma once
 
 #include <QBuffer>
-#include <QImageReader>
+#include <QMovie>
 #include <QObject>
 #include <QQuickItem>
 
@@ -24,11 +24,10 @@ class MxcAnimatedImage : public QQuickItem
 public:
     MxcAnimatedImage(QQuickItem *parent = nullptr)
       : QQuickItem(parent)
-      , movie(new QImageReader())
     {
         connect(this, &MxcAnimatedImage::eventIdChanged, &MxcAnimatedImage::startDownload);
         connect(this, &MxcAnimatedImage::roomChanged, &MxcAnimatedImage::startDownload);
-        connect(&frameTimer, &QTimer::timeout, this, &MxcAnimatedImage::newFrame);
+        connect(&movie, &QMovie::frameChanged, this, &MxcAnimatedImage::newFrame);
         setFlag(QQuickItem::ItemHasContents);
         // setAcceptHoverEvents(true);
     }
@@ -56,10 +55,7 @@ public:
     {
         if (play_ != newPlay) {
             play_ = newPlay;
-            if (play_)
-                frameTimer.start();
-            else
-                frameTimer.stop();
+            movie.setPaused(!play_);
             emit playChanged();
         }
     }
@@ -77,16 +73,10 @@ signals:
 
 private slots:
     void startDownload();
-    void newFrame()
+    void newFrame(int frame)
     {
-        if (movie->currentImageNumber() > 0 && !movie->canRead() && movie->imageCount() > 1) {
-            buffer.seek(0);
-            movie.reset(new QImageReader(movie->device(), movie->format()));
-            if (height() != 0 && width() != 0)
-                movie->setScaledSize(this->size().toSize());
-        }
-        movie->read(&currentFrame);
-        imageDirty = true;
+        currentFrame = frame;
+        imageDirty   = true;
         update();
     }
 
@@ -96,9 +86,8 @@ private:
     QString filename_;
     bool animatable_ = false;
     QBuffer buffer;
-    std::unique_ptr<QImageReader> movie;
-    bool imageDirty = true;
-    bool play_      = true;
-    QTimer frameTimer;
-    QImage currentFrame;
+    QMovie movie;
+    int currentFrame = 0;
+    bool imageDirty  = true;
+    bool play_       = true;
 };