diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index 37a0092..f8b44ff 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -61,6 +61,9 @@ void ActionManager::setupAction(MainWindow *mainWindow) CREATE_NEW_ACTION(mainWindow, actionPrevPicture); CREATE_NEW_ACTION(mainWindow, actionNextPicture); + CREATE_NEW_ACTION(mainWindow, actionTogglePauseAnimation); + CREATE_NEW_ACTION(mainWindow, actionAnimationNextFrame); + CREATE_NEW_THEMEICON_ACTION(mainWindow, actionOpen, document-open); CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip); CREATE_NEW_ACTION(mainWindow, actionFitInView); @@ -102,6 +105,9 @@ void ActionManager::retranslateUi(MainWindow *mainWindow) actionPrevPicture->setText(QCoreApplication::translate("MainWindow", "Previous image", nullptr)); actionNextPicture->setText(QCoreApplication::translate("MainWindow", "Next image", nullptr)); + actionTogglePauseAnimation->setText(QCoreApplication::translate("MainWindow", "Pause/Resume Animation", nullptr)); + actionAnimationNextFrame->setText(QCoreApplication::translate("MainWindow", "Animation Go to Next Frame", nullptr)); + actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr)); actionFitInView->setText(QCoreApplication::translate("MainWindow", "Fit to view", nullptr)); actionFitByWidth->setText(QCoreApplication::translate("MainWindow", "Fit to width", nullptr)); diff --git a/app/actionmanager.h b/app/actionmanager.h index 9360ef8..314b107 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -35,6 +35,9 @@ public: QAction *actionPrevPicture; QAction *actionNextPicture; + QAction *actionTogglePauseAnimation; + QAction *actionAnimationNextFrame; + QAction *actionHorizontalFlip; QAction *actionFitInView; QAction *actionFitByWidth; diff --git a/app/graphicsscene.cpp b/app/graphicsscene.cpp index 753e124..39d8ae5 100644 --- a/app/graphicsscene.cpp +++ b/app/graphicsscene.cpp @@ -21,6 +21,9 @@ public: : QGraphicsPixmapItem(pixmap, parent) {} + enum { Type = UserType + 1 }; + int type() const override { return Type; } + void setScaleHint(float scaleHint) { m_scaleHint = scaleHint; } @@ -61,6 +64,9 @@ class PGraphicsMovieItem : public QGraphicsItem public: PGraphicsMovieItem(QGraphicsItem *parent = nullptr) : QGraphicsItem(parent) {} + enum { Type = UserType + 2 }; + int type() const override { return Type; } + void setMovie(QMovie* movie) { if (m_movie) m_movie->disconnect(); m_movie.reset(movie); @@ -80,6 +86,10 @@ public: } } + inline QMovie * movie() const { + return m_movie.data(); + } + private: QScopedPointer m_movie; }; @@ -158,6 +168,29 @@ bool GraphicsScene::trySetTransformationMode(Qt::TransformationMode mode, float return false; } +bool GraphicsScene::togglePauseAnimation() +{ + PGraphicsMovieItem * animatedItem = qgraphicsitem_cast(m_theThing); + if (animatedItem) { + animatedItem->movie()->setPaused(animatedItem->movie()->state() != QMovie::Paused); + return true; + } + return false; +} + +bool GraphicsScene::skipAnimationFrame(int delta) +{ + PGraphicsMovieItem * animatedItem = qgraphicsitem_cast(m_theThing); + if (animatedItem) { + const int frameCount = animatedItem->movie()->frameCount(); + const int currentFrame = animatedItem->movie()->currentFrameNumber(); + const int targetFrame = (currentFrame + delta) % frameCount; + animatedItem->movie()->setPaused(true); + return animatedItem->movie()->jumpToFrame(targetFrame); + } + return false; +} + QPixmap GraphicsScene::renderToPixmap() { PGraphicsPixmapItem * pixmapItem = qgraphicsitem_cast(m_theThing); diff --git a/app/graphicsscene.h b/app/graphicsscene.h index ca2dc51..4ec3596 100644 --- a/app/graphicsscene.h +++ b/app/graphicsscene.h @@ -21,10 +21,13 @@ public: bool trySetTransformationMode(Qt::TransformationMode mode, float scaleHint); + bool togglePauseAnimation(); + bool skipAnimationFrame(int delta = 1); + QPixmap renderToPixmap(); private: - QGraphicsItem * m_theThing; + QGraphicsItem * m_theThing = nullptr; }; #endif // GRAPHICSSCENE_H diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 2a54516..de44bf4 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -801,6 +801,16 @@ void MainWindow::on_actionNextPicture_triggered() galleryNext(); } +void MainWindow::on_actionTogglePauseAnimation_triggered() +{ + m_graphicsView->scene()->togglePauseAnimation(); +} + +void MainWindow::on_actionAnimationNextFrame_triggered() +{ + m_graphicsView->scene()->skipAnimationFrame(1); +} + void MainWindow::on_actionToggleStayOnTop_triggered() { toggleStayOnTop(); diff --git a/app/mainwindow.h b/app/mainwindow.h index fa087a9..2850901 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -92,6 +92,9 @@ private slots: void on_actionPrevPicture_triggered(); void on_actionNextPicture_triggered(); + void on_actionTogglePauseAnimation_triggered(); + void on_actionAnimationNextFrame_triggered(); + void on_actionHorizontalFlip_triggered(); void on_actionFitInView_triggered(); void on_actionFitByWidth_triggered();