#include "widget.h"
#include "./ui_widget.h"

#include <QTimer>
#include "spdlog/spdlog.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    m_playerGLWidget = new PlayerGLWidget(this);
    m_playerGLWidget->setGeometry(0, 0, ui->widget_display->width(), ui->widget_display->height());
    m_playerGLWidget->setStyleSheet(R"(border-radius:10px;)");

    /* 设置背景颜色 */
    this->setAutoFillBackground(true);
    QPalette palette = m_playerGLWidget->palette();
    palette.setColor(QPalette::Window, Qt::black); // 设置背景颜色为黑色
    this->setPalette(palette);

    QImage image = QImage(":/image/1.jpg");
    connect(&m_timer, &QTimer::timeout, this, [=]() {
        // SPDLOG_DEBUG("刷新一帧");
        m_playerGLWidget->testShowYUV420Image(image); // 显示一张测试图片
    });
    m_timer.setSingleShot(false);
    m_timer.start(10); // 60 FPS
    
}

Widget::~Widget()
{

    delete ui;
}

void Widget::resizeEvent(QResizeEvent *event) 
{
    if (m_playerGLWidget) {
        m_playerGLWidget->setGeometry(0, 0, ui->widget_display->width(), ui->widget_display->height());
    }
    QWidget::resizeEvent(event);
}





