#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget){
ui->setupUi(this);
Widgets::registerRenderers();
showList = false;
timer = new QTimer(this);
setObjectName("myWiget");
setWindowTitle("播放器");
setWindowIcon(QIcon(":/resources/myLogo.ico"));
setStyleSheet("#myWiget{border-image:url(:/resources/backImg.png);}");
setContentsMargins(0,0,0,0);
resize(1280,720);
//实例化布局
this->vbox = new QVBoxLayout(this);// 上下排列布局
vbox->setContentsMargins(0,0,0,0);
// **********************************************************************************初始化管理栏***************
this->hboxTop = new QHBoxLayout(this);
hboxTop->setContentsMargins(0,0,0,0);
bar = new QMenuBar();
bar->setStyleSheet("margin: 2px 0;width:50px;background-color:rgba(0,0,0,0);color:white;");//透明背景色
bar->setAutoFillBackground(false);
bar->setMinimumWidth(70);
bar->setMaximumWidth(70);
// 一级菜单
file = bar->addMenu("文件");
// file->setStyleSheet("background-color:none;");//background-color:green;
file->setMinimumWidth(150);
file->setAutoFillBackground(false);
QList<QAction*> list;
QAction *action1=new QAction("打开文件");//QAction(QIcon(":/resource/image/向右箭头.jpg"),"action1"); 可显示图标
QAction *action2=new QAction("多个文件");
QAction *action3=new QAction("打开文件夹");
QAction *action4=new QAction("退出");
list.append(action1);
list.append(action2);
list.append(action3);
list.append(action4);
file->addActions(list);
// file->addMenu("打开文件");// 下级菜单
hboxTop->addWidget(bar);
fileVal = new QLabel();
fileVal->setStyleSheet("color:white;");
fileVal->setText("播放的文件名..........");
fileVal->setAlignment(Qt::AlignCenter);// 文字 居中
hboxTop->addWidget(fileVal);
hideButton = new QPushButton();
QPixmap pi = QPixmap(":/resources/hide.png");
hideButton->setStyleSheet("background-color:rgba(0,0,0,0);");
QIcon btnBack = QIcon(pi);
hideButton->setIcon(btnBack);
QSize s = QSize(50,25);
hideButton->setIconSize(s);
hideButton->setMaximumWidth(50);
hboxTop->addWidget(hideButton);
maxButton = new QPushButton();
maxButton->setStyleSheet("background-color:rgba(0,0,0,0);");
QPixmap maxpi = QPixmap(":/resources/maxPro.png");
QIcon maxbtnBack = QIcon(maxpi);
maxButton->setIcon(maxbtnBack);
QSize s2 = QSize(50,25);
maxButton->setIconSize(s2);
maxButton->setMaximumWidth(50);
maxButton->setMinimumWidth(50);
hboxTop->addWidget(maxButton);
closeButton = new QPushButton();
// closeButton->setStyleSheet("background-color:rgba(0,0,0,0);");
QPixmap closepi = QPixmap(":/resources/closePro.png");
QIcon closebtnBack = QIcon(closepi);
closeButton->setIcon(closebtnBack);
QSize s3 = QSize(50,25);
closeButton->setIconSize(s3);
closeButton->setMaximumWidth(50);
closeButton->setMinimumWidth(50);
hboxTop->addWidget(closeButton);
// **********************************************************************************初始化播放栏***************
QWidget* video = new QWidget(this);// 使用wiget来实现大小自适应,QHBoxLayout只能被动的被子组件撑起来
video->setContentsMargins(0,0,0,0);
this->hboxVideo = new QHBoxLayout(this);
hboxVideo->setContentsMargins(0,0,0,0);
//实例化媒体播放器及视频播放
mOut = new VideoOutput(this);;
mPlayer = new AVPlayer(this);
mPlayer->setRenderer(mOut);
// 默认实时流 连接方式是UDP模式,可能出现丢包,卡顿等,改为tcp模式
QHash<QString, QVariant> dict;
dict.insert("rtsp_transport", "tcp");
mPlayer->setOptionsForFormat(dict);
// 开启解码加速
mPlayer->setVideoDecoderPriority(QStringList() << "CUDA" << "D3D11" << "DXVA" << "FFmpeg");//"VAAPI"
// 新增一个大小随显示屏走的button,且设置为透明的
QVBoxLayout* gbox = new QVBoxLayout(mOut->widget());
b2 = new QPushButton(this);
QPixmap statpi2 = QPixmap(":/resources/stat2.png");
QIcon statbtnBack2 = QIcon(statpi2);
b2->setIcon(statbtnBack2);
b2->setIconSize(QSize(0,0));
b2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
b2->setStyleSheet("background-color:rgba(0,0,0,0);");
gbox->addWidget(b2);
mOut->widget()->setLayout(gbox);
hboxVideo->addWidget(mOut->widget());
// hboxVideo->setStretchFactor(videoWidget,1);// 设置该控件为可伸缩,其他控件自动设置为不可伸缩
showListButton = new QPushButton(this);
showListButton->setMaximumWidth(20);
// 设置宽度固定,高度随父组件大小
showListButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
showListButton->setStyleSheet("border-image:url(:/resources/showList.png);");
hboxVideo->addWidget(showListButton);
// 历史列表
listWidget = new QListWidget(this);
// listWidget->setStyleSheet("background-color:white;color:black;");
listWidget->setMaximumWidth(270);
listWidget->setMinimumWidth(270);
hboxVideo->addWidget(listWidget);
video->setLayout(hboxVideo);
// **********************************************************************************初始化视频时间显示栏***************
this->hboxVideoTime = new QHBoxLayout(this);
hboxVideoTime->setContentsMargins(0,0,0,0);
timeLable = new QLabel("00:00:00/00:00:00",this);
timeLable->setStyleSheet("color:white;");//margin-bottom:3px;
hboxVideoTime->addWidget(timeLable);
// **********************************************************************************初始化视频进度条显示栏***************
this->hboxVideoIndex = new QHBoxLayout(this);
hboxVideoIndex->setContentsMargins(0,0,0,0);
timeSlider = new QSlider(this);
timeSlider->setContentsMargins(0,0,0,0);
// groove表示槽的部分,handle表示滑块,add-page表示未滑过的槽部分,sub-page 表示已滑过的槽部分
// 横向展示
timeSlider->setOrientation(Qt::Horizontal);// Vertical
QString timeSliderStr = "";//"margin:3px;background-color:white;";
// 主体样式(样式中注意 horizontal 和 vertical)
timeSliderStr += "QSlider{border-color: #bcbcbc;}QSlider::groove:horizontal {border: 1px solid #999999;height: 6px;"
"left: 5px; right: 5px;}";// 左右留出一定位置,这样进度键才能显示全
// 滑块样式
timeSliderStr.append("QSlider::handle:horizontal {border: 0px;border-image: url(:/resources/rate.png);"
"width: 13px;margin: 0px -7px 0px -7px;}");
// 已划过槽的样式
timeSliderStr.append("QSlider::sub-page:horizontal {background-color:#87CEEB;height: 8px;}");//padding: 2px 0;
timeSlider->setStyleSheet(timeSliderStr);
timeSlider->installEventFilter(this);// 重载eventFilter事件
hboxVideoIndex->addWidget(timeSlider);
// **********************************************************************************初始化视频操作显示栏***************
this->hboxVideoWork = new QHBoxLayout(this);
hboxVideoWork->setContentsMargins(0,0,0,0);
// 布局:间隔/组件1/间隔/组件2
hboxVideoWork->addStretch();
btnLeft = new QLabel(" ");
btnLeft->setStyleSheet("margin:0 0 5px 0;background-color:rgba(0,0,0,0);");
hboxVideoWork->addWidget(btnLeft);
hboxVideoWork->addStretch();
backButton = new QPushButton();
backButton->setStyleSheet("margin:0 0 5px 0;background-color:rgba(0,0,0,0);");
QPixmap backpi = QPixmap(":/resources/back.png");
QIcon backbtnBack = QIcon(back