From 78784babd1bac589216fc768d927c7af6bc67226 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 30 Sep 2022 04:03:39 +0200 Subject: Revert accidental animated image change --- src/ui/MxcAnimatedImage.h | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/ui/MxcAnimatedImage.h') 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 -#include +#include #include #include @@ -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(¤tFrame); - imageDirty = true; + currentFrame = frame; + imageDirty = true; update(); } @@ -96,9 +86,8 @@ private: QString filename_; bool animatable_ = false; QBuffer buffer; - std::unique_ptr movie; - bool imageDirty = true; - bool play_ = true; - QTimer frameTimer; - QImage currentFrame; + QMovie movie; + int currentFrame = 0; + bool imageDirty = true; + bool play_ = true; }; -- cgit 1.5.1