support gif catpacks

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-01-18 15:39:25 +02:00
parent b90cda5eef
commit 2e428330f4
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 17 additions and 1 deletions

View File

@ -22,12 +22,27 @@
CatPainter::CatPainter(const QString& path, QObject* parent) : QObject(parent)
{
m_image = QPixmap(path);
// Attempt to load as a movie
m_movie = new QMovie(path, QByteArray(), this);
if (m_movie->isValid()) {
// Start the animation if it's a valid movie file
connect(m_movie, &QMovie::frameChanged, this, &CatPainter::updateFrame);
m_movie->start();
} else {
// Otherwise, load it as a static image
delete m_movie;
m_movie = nullptr;
m_image = QPixmap(path);
}
}
void CatPainter::paint(QPainter* painter, const QRect& viewport)
{
QPixmap frame = m_image;
if (m_movie && m_movie->isValid()) {
frame = m_movie->currentPixmap();
}
auto fit = APPLICATION->settings()->get("CatFit").toString();
painter->setOpacity(APPLICATION->settings()->get("CatOpacity").toFloat() / 100);

View File

@ -34,5 +34,6 @@ class CatPainter : public QObject {
void updateFrame();
private:
QMovie* m_movie = nullptr;
QPixmap m_image;
};