Prevent the animated background/foreground from restarting itself if the image is the exact same as the currently playing one

This commit is contained in:
Crystalwarrior 2019-09-10 23:26:03 +03:00
parent 7378205523
commit 7e2ec58c7e
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,7 @@ private:
QWidget *m_parent; QWidget *m_parent;
QMovie *m_movie; QMovie *m_movie;
AOApplication *ao_app; AOApplication *ao_app;
QString last_image;
}; };

View File

@ -7,6 +7,7 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent)
m_parent = parent; m_parent = parent;
ao_app = p_ao_app; ao_app = p_ao_app;
m_movie = new QMovie(this); m_movie = new QMovie(this);
last_image = "";
} }
void AOScene::set_image(QString p_image) void AOScene::set_image(QString p_image)
@ -15,6 +16,9 @@ void AOScene::set_image(QString p_image)
QString default_path = ao_app->get_default_background_path(p_image + ".png"); QString default_path = ao_app->get_default_background_path(p_image + ".png");
QString animated_background_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); QString animated_background_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image));
if (file_exists(animated_background_path) && animated_background_path == last_image)
return;
QPixmap background(background_path); QPixmap background(background_path);
QPixmap default_bg(default_path); QPixmap default_bg(default_path);
@ -32,11 +36,16 @@ void AOScene::set_image(QString p_image)
{ {
this->setMovie(m_movie); this->setMovie(m_movie);
m_movie->start(); m_movie->start();
last_image = animated_background_path;
} }
else if (file_exists(background_path)) else if (file_exists(background_path))
{
this->setPixmap(background.scaled(w, h)); this->setPixmap(background.scaled(w, h));
}
else else
{
this->setPixmap(default_bg.scaled(w, h)); this->setPixmap(default_bg.scaled(w, h));
}
} }
void AOScene::set_legacy_desk(QString p_image) void AOScene::set_legacy_desk(QString p_image)
@ -48,6 +57,9 @@ void AOScene::set_legacy_desk(QString p_image)
QString animated_desk_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); QString animated_desk_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image));
QString default_path = ao_app->get_image_suffix(ao_app->get_default_background_path(p_image)); QString default_path = ao_app->get_image_suffix(ao_app->get_default_background_path(p_image));
if (file_exists(animated_desk_path) && animated_desk_path == last_image)
return;
QPixmap f_desk; QPixmap f_desk;
int vp_width = m_parent->width(); int vp_width = m_parent->width();
@ -73,6 +85,7 @@ void AOScene::set_legacy_desk(QString p_image)
{ {
this->setMovie(m_movie); this->setMovie(m_movie);
m_movie->start(); m_movie->start();
last_image = animated_desk_path;
} }
else else
{ {