qt/LedOK/player/elegif.cpp

33 lines
980 B
C++
Raw Normal View History

2023-04-18 14:14:46 +08:00
#include "elegif.h"
#include <QPainter>
#include <QMovie>
EleGif::EleGif(QString path, QWidget *parent) : QWidget{parent} {
movie = new QMovie(path, QByteArray(), this);
movie->setCacheMode(QMovie::CacheAll);
movie->jumpToFrame(0);
}
void EleGif::paintEvent(QPaintEvent *){
QPainter painter(this);
2024-02-21 18:08:50 +08:00
if(movie) {
2023-04-18 14:14:46 +08:00
painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
painter.drawPixmap(0, 0, width(), height(), movie->currentPixmap());
2024-02-21 18:08:50 +08:00
if(timer==0) {
2023-04-18 14:14:46 +08:00
timer = new SyncTimer(movie->nextFrameDelay());
connect(timer, &SyncTimer::timeout, this, &EleGif::sltNext, Qt::BlockingQueuedConnection);
timer->start();
}
}
}
void EleGif::sltNext(){
if(isVisible()) {
movie->jumpToNextFrame();
timer->inter = movie->nextFrameDelay();
update();
2024-02-21 18:08:50 +08:00
} else if(timer) {
2023-04-18 14:14:46 +08:00
timer->stop();
2024-02-21 18:08:50 +08:00
timer = 0;
2023-04-18 14:14:46 +08:00
}
}