qt/LedOK/player/elevideo.cpp
2022-08-25 18:37:24 +08:00

41 lines
1.3 KiB
C++

#include "elevideo.h"
#include "tools.h"
#include <QPainter>
#include <QMessageBox>
#include <QOpenGLWidget>
EleVideo::EleVideo(QString path, QWidget *parent) : QWidget{parent} {
auto glWgt = new QOpenGLWidget(this);
glWgt->setGeometry(-1,-1,1,1);
connect(glWgt, &QOpenGLWidget::frameSwapped, glWgt, (void(QOpenGLWidget::*)())&QOpenGLWidget::update);
player = new FFPlayer();
connect(glWgt, &QOpenGLWidget::frameSwapped, player, &FFPlayer::updFrame);
connect(player, &FFPlayer::emUpd, this, [this](QImage img) {
this->img = img;
update();
});
connect(player, &FFPlayer::emError, this, [this](QString err) {
QMessageBox::critical(this, "Video Error", err);
});
player->open(path.toUtf8());
}
//void EleVideo::mouseDoubleClickEvent(QMouseEvent *) {
// qDebug()<<"img"<<img;
// qDebug()<<"img"<<player->img;
// qDebug()<<"viCurTime"<<player->viCurTime;
// qDebug()<<"viSize"<<player->viSize;
//}
void EleVideo::showEvent(QShowEvent *) {
if(player!=nullptr) player->play();
}
void EleVideo::hideEvent(QHideEvent *) {
if(player!=nullptr) player->stop();
}
void EleVideo::paintEvent(QPaintEvent *e) {
QWidget::paintEvent(e);
QPainter painter(this);
painter.drawImage(QRectF(0, 0, width(), height()), img);
}