diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-09-30 03:27:05 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-09-30 03:27:05 +0200 |
commit | 88cbac1695292e1dade325ee26ba5c52467d4b75 (patch) | |
tree | 275ef197ca81de7d08291f937cf4eca0451e4fcf /src/ui/MxcAnimatedImage.h | |
parent | Make clazy happy (diff) | |
download | nheko-88cbac1695292e1dade325ee26ba5c52467d4b75.tar.xz |
Basic threading support
Diffstat (limited to 'src/ui/MxcAnimatedImage.h')
-rw-r--r-- | src/ui/MxcAnimatedImage.h | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h index 8891e57e..2b067166 100644 --- a/src/ui/MxcAnimatedImage.h +++ b/src/ui/MxcAnimatedImage.h @@ -6,7 +6,7 @@ #pragma once #include <QBuffer> -#include <QMovie> +#include <QImageReader> #include <QObject> #include <QQuickItem> @@ -24,10 +24,11 @@ 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(&movie, &QMovie::frameChanged, this, &MxcAnimatedImage::newFrame); + connect(&frameTimer, &QTimer::timeout, this, &MxcAnimatedImage::newFrame); setFlag(QQuickItem::ItemHasContents); // setAcceptHoverEvents(true); } @@ -55,7 +56,10 @@ public: { if (play_ != newPlay) { play_ = newPlay; - movie.setPaused(!play_); + if (play_) + frameTimer.start(); + else + frameTimer.stop(); emit playChanged(); } } @@ -73,10 +77,16 @@ signals: private slots: void startDownload(); - void newFrame(int frame) + void newFrame() { - currentFrame = frame; - imageDirty = true; + 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; update(); } @@ -86,8 +96,9 @@ private: QString filename_; bool animatable_ = false; QBuffer buffer; - QMovie movie; - int currentFrame = 0; - bool imageDirty = true; - bool play_ = true; + std::unique_ptr<QImageReader> movie; + bool imageDirty = true; + bool play_ = true; + QTimer frameTimer; + QImage currentFrame; }; |