feat: animation pause and manually step to next frame
Resolve: https://github.com/BLumia/pineapple-pictures/issues/85
This commit is contained in:
parent
a993437983
commit
42e3d4c691
|
@ -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));
|
||||
|
|
|
@ -35,6 +35,9 @@ public:
|
|||
QAction *actionPrevPicture;
|
||||
QAction *actionNextPicture;
|
||||
|
||||
QAction *actionTogglePauseAnimation;
|
||||
QAction *actionAnimationNextFrame;
|
||||
|
||||
QAction *actionHorizontalFlip;
|
||||
QAction *actionFitInView;
|
||||
QAction *actionFitByWidth;
|
||||
|
|
|
@ -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<QMovie> m_movie;
|
||||
};
|
||||
|
@ -158,6 +168,29 @@ bool GraphicsScene::trySetTransformationMode(Qt::TransformationMode mode, float
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GraphicsScene::togglePauseAnimation()
|
||||
{
|
||||
PGraphicsMovieItem * animatedItem = qgraphicsitem_cast<PGraphicsMovieItem *>(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<PGraphicsMovieItem *>(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<PGraphicsPixmapItem *>(m_theThing);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user