qt/LedOK/player/elevideo.cpp

41 lines
1.3 KiB
C++
Raw Normal View History

2022-01-20 10:08:17 +08:00
#include "elevideo.h"
2022-08-25 18:37:24 +08:00
#include "tools.h"
#include <QPainter>
#include <QMessageBox>
#include <QOpenGLWidget>
2022-01-20 10:08:17 +08:00
2022-08-25 18:37:24 +08:00
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());
2022-01-20 10:08:17 +08:00
}
2022-08-25 18:37:24 +08:00
//void EleVideo::mouseDoubleClickEvent(QMouseEvent *) {
// qDebug()<<"img"<<img;
// qDebug()<<"img"<<player->img;
// qDebug()<<"viCurTime"<<player->viCurTime;
// qDebug()<<"viSize"<<player->viSize;
//}
2022-01-20 10:08:17 +08:00
void EleVideo::showEvent(QShowEvent *) {
2022-08-25 18:37:24 +08:00
if(player!=nullptr) player->play();
2022-01-20 10:08:17 +08:00
}
void EleVideo::hideEvent(QHideEvent *) {
2022-08-25 18:37:24 +08:00
if(player!=nullptr) player->stop();
}
void EleVideo::paintEvent(QPaintEvent *e) {
QWidget::paintEvent(e);
QPainter painter(this);
painter.drawImage(QRectF(0, 0, width(), height()), img);
2022-01-20 10:08:17 +08:00
}