summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-08-29 15:33:39 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-08-29 16:32:28 +0200
commit15bf643347e507513d6999dd346f0cce9c7952c8 (patch)
treef0b0470e0731e063021b57165391a2b5597ecaf3 /src/ui
parentcleanup QSettings usage a bit (diff)
downloadnheko-15bf643347e507513d6999dd346f0cce9c7952c8.tar.xz
Add option to only play animated images on hover
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/MxcAnimatedImage.cpp9
-rw-r--r--src/ui/MxcAnimatedImage.h12
2 files changed, 20 insertions, 1 deletions
diff --git a/src/ui/MxcAnimatedImage.cpp b/src/ui/MxcAnimatedImage.cpp

index cfc03827..3c93cc2b 100644 --- a/src/ui/MxcAnimatedImage.cpp +++ b/src/ui/MxcAnimatedImage.cpp
@@ -94,8 +94,12 @@ MxcAnimatedImage::startDownload() buffer.isOpen()); movie.setFormat(mimeType); movie.setDevice(&buffer); - movie.start(); + if (play_) + movie.start(); + else + movie.jumpToFrame(0); emit loadedChanged(); + update(); }); }; @@ -143,6 +147,9 @@ MxcAnimatedImage::startDownload() QSGNode * MxcAnimatedImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) { + if (!imageDirty) + return oldNode; + imageDirty = false; QSGImageNode *n = static_cast<QSGImageNode *>(oldNode); if (!n) diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h
index 7b9502e0..2e0489ad 100644 --- a/src/ui/MxcAnimatedImage.h +++ b/src/ui/MxcAnimatedImage.h
@@ -19,6 +19,7 @@ class MxcAnimatedImage : public QQuickItem Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged) Q_PROPERTY(bool animatable READ animatable NOTIFY animatableChanged) Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged) + Q_PROPERTY(bool play READ play WRITE setPlay NOTIFY playChanged) public: MxcAnimatedImage(QQuickItem *parent = nullptr) : QQuickItem(parent) @@ -32,6 +33,7 @@ public: bool animatable() const { return animatable_; } bool loaded() const { return buffer.size() > 0; } + bool play() const { return play_; } QString eventId() const { return eventId_; } TimelineModel *room() const { return room_; } void setEventId(QString newEventId) @@ -48,6 +50,14 @@ public: emit roomChanged(); } } + void setPlay(bool newPlay) + { + if (play_ != newPlay) { + play_ = newPlay; + movie.setPaused(!play_); + emit playChanged(); + } + } QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override; @@ -57,6 +67,7 @@ signals: void eventIdChanged(); void animatableChanged(); void loadedChanged(); + void playChanged(); private slots: void startDownload(); @@ -76,4 +87,5 @@ private: QMovie movie; int currentFrame = 0; bool imageDirty = true; + bool play_ = true; };