diff options
author | Alessandro Portale <[email protected]> | 2023-09-13 21:55:47 +0200 |
---|---|---|
committer | Alessandro Portale <[email protected]> | 2023-09-14 10:51:35 +0000 |
commit | 726f2730e7468073c49b2f775986372735b22e4e (patch) | |
tree | 8e1004a03aacd1f582d5461b5017f71b45121af8 /src/plugins/imageviewer/imageviewer.cpp | |
parent | 7fc69e1063c310d98d691394526fce0015a11f95 (diff) |
ImageViewer: Fix animation playback replay and loop
This fixes the issue that looped animated images do not automatically
loop and that animations can generally not be replayed from start.
It introduces the "resume" state to the tool bar icon in order to
distinguish between "playing an animation from start" and "resuming the
playback of a paused animation".
The setting cache mode QMovie::CacheAll was removed because it prevents
a looped animation from looping, and also its memory consumption (which
depends on animation dimension and frames) does not seem to be
positively outweighed by anything else.
Fixes: QTCREATORBUG-29606
Change-Id: Iaca8d93766201f5f953784be7ee6d56610e63695
Reviewed-by: <[email protected]>
Reviewed-by: Eike Ziller <[email protected]>
Reviewed-by: Marcus Tillmanns <[email protected]>
Diffstat (limited to 'src/plugins/imageviewer/imageviewer.cpp')
-rw-r--r-- | src/plugins/imageviewer/imageviewer.cpp | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/src/plugins/imageviewer/imageviewer.cpp b/src/plugins/imageviewer/imageviewer.cpp index 5d4a068e717..d1893b703ae 100644 --- a/src/plugins/imageviewer/imageviewer.cpp +++ b/src/plugins/imageviewer/imageviewer.cpp @@ -234,7 +234,7 @@ void ImageViewer::ctor() d->imageView, &ImageView::reset); connect(d->file.data(), &ImageViewerFile::reloadFinished, d->imageView, &ImageView::createScene); - connect(d->file.data(), &ImageViewerFile::isPausedChanged, + connect(d->file.data(), &ImageViewerFile::movieStateChanged, this, &ImageViewer::updatePauseAction); connect(d->imageView, &ImageView::scaleFactorChanged, this, &ImageViewer::scaleFactorUpdate); @@ -349,19 +349,42 @@ void ImageViewer::togglePlay() void ImageViewer::playToggled() { - d->file->setPaused(!d->file->isPaused()); + QMovie *m = d->file->movie(); + if (!m) + return; + const QMovie::MovieState state = d->file->movie()->state(); + switch (state) { + case QMovie::NotRunning: + m->start(); + break; + case QMovie::Paused: + m->setPaused(false); + break; + case QMovie::Running: + m->setPaused(true); + break; + } } void ImageViewer::updatePauseAction() { - bool isMovie = d->file->type() == ImageViewerFile::TypeMovie; - if (isMovie && !d->file->isPaused()) { - d->actionPlayPause->setToolTipBase(Tr::tr("Pause Animation")); - d->actionPlayPause->setIcon(Icons::INTERRUPT_SMALL_TOOLBAR.icon()); - } else { - d->actionPlayPause->setToolTipBase(Tr::tr("Play Animation")); - d->actionPlayPause->setIcon(Icons::RUN_SMALL_TOOLBAR.icon()); - d->actionPlayPause->setEnabled(isMovie); + const bool isMovie = d->file->type() == ImageViewerFile::TypeMovie; + const QMovie::MovieState state = isMovie ? d->file->movie()->state() : QMovie::NotRunning; + CommandAction *a = d->actionPlayPause; + switch (state) { + case QMovie::NotRunning: + a->setToolTipBase(Tr::tr("Play Animation")); + a->setIcon(Icons::RUN_SMALL_TOOLBAR.icon()); + a->setEnabled(isMovie); + break; + case QMovie::Paused: + a->setToolTipBase(Tr::tr("Resume Paused Animation")); + a->setIcon(Icons::CONTINUE_SMALL_TOOLBAR.icon()); + break; + case QMovie::Running: + a->setToolTipBase(Tr::tr("Pause Animation")); + a->setIcon(Icons::INTERRUPT_SMALL_TOOLBAR.icon()); + break; } } |