更新文档

master
feiyangqingyun 2024-02-26 10:34:39 +08:00
parent 894e7179b9
commit 18bf44fb9e
17 changed files with 526 additions and 431 deletions

View File

@ -207,7 +207,7 @@ void CpuMemoryLabel::readData()
void CpuMemoryLabel::setData() void CpuMemoryLabel::setData()
{ {
cpuPercent = (cpuPercent < 0 ? 0 : cpuPercent); //cpuPercent = (cpuPercent < 0 ? 0 : cpuPercent);
cpuPercent = (cpuPercent > 100 ? 0 : cpuPercent); cpuPercent = (cpuPercent > 100 ? 0 : cpuPercent);
QString msg = QString("CPU %1% Mem %2% ( 已用 %3 MB / 共 %4 MB )").arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll); QString msg = QString("CPU %1% Mem %2% ( 已用 %3 MB / 共 %4 MB )").arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll);
if (showText) { if (showText) {

View File

@ -132,8 +132,10 @@ void IconHelper::setStyle(QWidget *widget, QList<QAbstractButton *> btns,
IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent)
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) { bool exist = false;//fontDb.families().contains(fontName);
if (!exist && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -132,8 +132,10 @@ void IconHelper::setStyle(QWidget *widget, QList<QAbstractButton *> btns,
IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent)
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) { bool exist = false;//fontDb.families().contains(fontName);
if (!exist && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -132,8 +132,10 @@ void IconHelper::setStyle(QWidget *widget, QList<QAbstractButton *> btns,
IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent)
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) { bool exist = false;//fontDb.families().contains(fontName);
if (!exist && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -132,8 +132,10 @@ void IconHelper::setStyle(QWidget *widget, QList<QAbstractButton *> btns,
IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent)
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) { bool exist = false;//fontDb.families().contains(fontName);
if (!exist && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -9,8 +9,6 @@ FFmpegThread::FFmpegThread(QObject *parent) : QThread(parent)
frameFinish = false; frameFinish = false;
videoWidth = 0; videoWidth = 0;
videoHeight = 0; videoHeight = 0;
oldWidth = 0;
oldHeight = 0;
videoStreamIndex = -1; videoStreamIndex = -1;
audioStreamIndex = -1; audioStreamIndex = -1;
@ -18,17 +16,16 @@ FFmpegThread::FFmpegThread(QObject *parent) : QThread(parent)
buffer = NULL; buffer = NULL;
avPacket = NULL; avPacket = NULL;
avFrame = NULL; yuvFrame = NULL;
avFrame2 = NULL; rgbFrame = NULL;
avFrame3 = NULL; formatCtx = NULL;
avFormatContext = NULL; videoCodecCtx = NULL;
videoCodec = NULL; audioCodecCtx = NULL;
audioCodec = NULL;
swsContext = NULL; swsContext = NULL;
options = NULL; options = NULL;
videoDecoder = NULL; videoCodec = NULL;
audioDecoder = NULL; audioCodec = NULL;
//初始化注册,一个软件中只注册一次即可 //初始化注册,一个软件中只注册一次即可
FFmpegThread::initlib(); FFmpegThread::initlib();
@ -81,9 +78,9 @@ bool FFmpegThread::init()
av_dict_set(&options, "threads", "auto", 0); av_dict_set(&options, "threads", "auto", 0);
//打开视频流 //打开视频流
avFormatContext = avformat_alloc_context(); formatCtx = avformat_alloc_context();
int result = avformat_open_input(&avFormatContext, url.toStdString().data(), NULL, &options); int result = avformat_open_input(&formatCtx, url.toStdString().data(), NULL, &options);
if (result < 0) { if (result < 0) {
qDebug() << TIMEMS << "open input error" << url; qDebug() << TIMEMS << "open input error" << url;
return false; return false;
@ -95,7 +92,7 @@ bool FFmpegThread::init()
} }
//获取流信息 //获取流信息
result = avformat_find_stream_info(avFormatContext, NULL); result = avformat_find_stream_info(formatCtx, NULL);
if (result < 0) { if (result < 0) {
qDebug() << TIMEMS << "find stream info error"; qDebug() << TIMEMS << "find stream info error";
return false; return false;
@ -103,30 +100,30 @@ bool FFmpegThread::init()
//----------视频流部分开始,打个标记方便折叠代码---------- //----------视频流部分开始,打个标记方便折叠代码----------
if (1) { if (1) {
videoStreamIndex = av_find_best_stream(avFormatContext, AVMEDIA_TYPE_VIDEO, -1, -1, &videoDecoder, 0); videoStreamIndex = av_find_best_stream(formatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &videoCodec, 0);
if (videoStreamIndex < 0) { if (videoStreamIndex < 0) {
qDebug() << TIMEMS << "find video stream index error"; qDebug() << TIMEMS << "find video stream index error";
return false; return false;
} }
//获取视频流 //获取视频流
AVStream *videoStream = avFormatContext->streams[videoStreamIndex]; AVStream *videoStream = formatCtx->streams[videoStreamIndex];
//获取视频流解码器,或者指定解码器 //获取视频流解码器,或者指定解码器
videoCodec = videoStream->codec; videoCodecCtx = videoStream->codec;
videoDecoder = avcodec_find_decoder(videoCodec->codec_id); videoCodec = avcodec_find_decoder(videoCodecCtx->codec_id);
//videoDecoder = avcodec_find_decoder_by_name("h264_qsv"); //videoCodec = avcodec_find_decoder_by_name("h264_qsv");
if (videoDecoder == NULL) { if (videoCodec == NULL) {
qDebug() << TIMEMS << "video decoder not found"; qDebug() << TIMEMS << "video decoder not found";
return false; return false;
} }
//设置加速解码 //设置加速解码
videoCodec->lowres = videoDecoder->max_lowres; videoCodecCtx->lowres = videoCodec->max_lowres;
videoCodec->flags2 |= AV_CODEC_FLAG2_FAST; videoCodecCtx->flags2 |= AV_CODEC_FLAG2_FAST;
//打开视频解码器 //打开视频解码器
result = avcodec_open2(videoCodec, videoDecoder, NULL); result = avcodec_open2(videoCodecCtx, videoCodec, NULL);
if (result < 0) { if (result < 0) {
qDebug() << TIMEMS << "open video codec error"; qDebug() << TIMEMS << "open video codec error";
return false; return false;
@ -143,8 +140,8 @@ bool FFmpegThread::init()
} }
QString videoInfo = QString("视频流信息 -> 索引: %1 解码: %2 格式: %3 时长: %4 秒 分辨率: %5*%6") QString videoInfo = QString("视频流信息 -> 索引: %1 解码: %2 格式: %3 时长: %4 秒 分辨率: %5*%6")
.arg(videoStreamIndex).arg(videoDecoder->name).arg(avFormatContext->iformat->name) .arg(videoStreamIndex).arg(videoCodec->name).arg(formatCtx->iformat->name)
.arg((avFormatContext->duration) / 1000000).arg(videoWidth).arg(videoHeight); .arg((formatCtx->duration) / 1000000).arg(videoWidth).arg(videoHeight);
qDebug() << TIMEMS << videoInfo; qDebug() << TIMEMS << videoInfo;
} }
//----------视频流部分开始---------- //----------视频流部分开始----------
@ -153,8 +150,8 @@ bool FFmpegThread::init()
if (1) { if (1) {
//循环查找音频流索引 //循环查找音频流索引
audioStreamIndex = -1; audioStreamIndex = -1;
for (uint i = 0; i < avFormatContext->nb_streams; i++) { for (uint i = 0; i < formatCtx->nb_streams; i++) {
if (avFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
audioStreamIndex = i; audioStreamIndex = i;
break; break;
} }
@ -165,27 +162,27 @@ bool FFmpegThread::init()
qDebug() << TIMEMS << "find audio stream index error"; qDebug() << TIMEMS << "find audio stream index error";
} else { } else {
//获取音频流 //获取音频流
AVStream *audioStream = avFormatContext->streams[audioStreamIndex]; AVStream *audioStream = formatCtx->streams[audioStreamIndex];
audioCodec = audioStream->codec; audioCodecCtx = audioStream->codec;
//获取音频流解码器,或者指定解码器 //获取音频流解码器,或者指定解码器
audioDecoder = avcodec_find_decoder(audioCodec->codec_id); audioCodec = avcodec_find_decoder(audioCodecCtx->codec_id);
//audioDecoder = avcodec_find_decoder_by_name("aac"); //audioCodec = avcodec_find_decoder_by_name("aac");
if (audioDecoder == NULL) { if (audioCodec == NULL) {
qDebug() << TIMEMS << "audio codec not found"; qDebug() << TIMEMS << "audio codec not found";
return false; return false;
} }
//打开音频解码器 //打开音频解码器
result = avcodec_open2(audioCodec, audioDecoder, NULL); result = avcodec_open2(audioCodecCtx, audioCodec, NULL);
if (result < 0) { if (result < 0) {
qDebug() << TIMEMS << "open audio codec error"; qDebug() << TIMEMS << "open audio codec error";
return false; return false;
} }
QString audioInfo = QString("音频流信息 -> 索引: %1 解码: %2 比特率: %3 声道数: %4 采样: %5") QString audioInfo = QString("音频流信息 -> 索引: %1 解码: %2 比特率: %3 声道数: %4 采样: %5")
.arg(audioStreamIndex).arg(audioDecoder->name).arg(avFormatContext->bit_rate) .arg(audioStreamIndex).arg(audioCodec->name).arg(formatCtx->bit_rate)
.arg(audioCodec->channels).arg(audioCodec->sample_rate); .arg(audioCodecCtx->channels).arg(audioCodecCtx->sample_rate);
qDebug() << TIMEMS << audioInfo; qDebug() << TIMEMS << audioInfo;
} }
} }
@ -193,37 +190,31 @@ bool FFmpegThread::init()
//预分配好内存 //预分配好内存
avPacket = av_packet_alloc(); avPacket = av_packet_alloc();
avFrame = av_frame_alloc(); yuvFrame = av_frame_alloc();
avFrame2 = av_frame_alloc(); rgbFrame = av_frame_alloc();
avFrame3 = av_frame_alloc();
//比较上一次文件的宽度高度,当改变时,需要重新分配内存 int byte = avpicture_get_size(AV_PIX_FMT_RGB32, videoWidth, videoHeight);
if (oldWidth != videoWidth || oldHeight != videoHeight) { buffer = (uint8_t *)av_malloc(byte * sizeof(uint8_t));
int byte = avpicture_get_size(AV_PIX_FMT_RGB32, videoWidth, videoHeight);
buffer = (uint8_t *)av_malloc(byte * sizeof(uint8_t));
oldWidth = videoWidth;
oldHeight = videoHeight;
}
//定义像素格式 //定义像素格式
AVPixelFormat srcFormat = AV_PIX_FMT_YUV420P; AVPixelFormat srcFormat = AV_PIX_FMT_YUV420P;
AVPixelFormat dstFormat = AV_PIX_FMT_RGB32; AVPixelFormat dstFormat = AV_PIX_FMT_RGB32;
//通过解码器获取解码格式 //通过解码器获取解码格式
srcFormat = videoCodec->pix_fmt; srcFormat = videoCodecCtx->pix_fmt;
//默认最快速度的解码采用的SWS_FAST_BILINEAR参数,可能会丢失部分图片数据,可以自行更改成其他参数 //默认最快速度的解码采用的SWS_FAST_BILINEAR参数,可能会丢失部分图片数据,可以自行更改成其他参数
int flags = SWS_FAST_BILINEAR; int flags = SWS_FAST_BILINEAR;
//开辟缓存存储一帧数据 //开辟缓存存储一帧数据
//以下两种方法都可以,avpicture_fill已经逐渐被废弃 //以下两种方法都可以,avpicture_fill已经逐渐被废弃
//avpicture_fill((AVPicture *)avFrame3, buffer, dstFormat, videoWidth, videoHeight); //avpicture_fill((AVPicture *)rgbFrame, buffer, dstFormat, videoWidth, videoHeight);
av_image_fill_arrays(avFrame3->data, avFrame3->linesize, buffer, dstFormat, videoWidth, videoHeight, 1); av_image_fill_arrays(rgbFrame->data, rgbFrame->linesize, buffer, dstFormat, videoWidth, videoHeight, 1);
//图像转换 //图像转换
swsContext = sws_getContext(videoWidth, videoHeight, srcFormat, videoWidth, videoHeight, dstFormat, flags, NULL, NULL, NULL); swsContext = sws_getContext(videoWidth, videoHeight, srcFormat, videoWidth, videoHeight, dstFormat, flags, NULL, NULL, NULL);
//输出视频信息 //输出视频信息
//av_dump_format(avFormatContext, 0, url.toStdString().data(), 0); //av_dump_format(formatCtx, 0, url.toStdString().data(), 0);
//qDebug() << TIMEMS << "init ffmpeg finsh"; //qDebug() << TIMEMS << "init ffmpeg finsh";
return true; return true;
@ -240,21 +231,28 @@ void FFmpegThread::run()
continue; continue;
} }
frameFinish = av_read_frame(avFormatContext, avPacket); frameFinish = av_read_frame(formatCtx, avPacket);
if (frameFinish >= 0) { if (frameFinish >= 0) {
//下面演示倍速播放
if (0) {
double speed = 2.0;
avPacket->pts = avPacket->pts / speed;
avPacket->dts = avPacket->dts / speed;
}
//判断当前包是视频还是音频 //判断当前包是视频还是音频
int index = avPacket->stream_index; int index = avPacket->stream_index;
if (index == videoStreamIndex) { if (index == videoStreamIndex) {
//解码视频流 avcodec_decode_video2 方法已被废弃 //解码视频流 avcodec_decode_video2 方法已被废弃
#if 0 #if 0
avcodec_decode_video2(videoCodec, avFrame2, &frameFinish, avPacket); avcodec_decode_video2(videoCodecCtx, yuvFrame, &frameFinish, avPacket);
#else #else
frameFinish = avcodec_send_packet(videoCodec, avPacket); frameFinish = avcodec_send_packet(videoCodecCtx, avPacket);
if (frameFinish < 0) { if (frameFinish < 0) {
continue; continue;
} }
frameFinish = avcodec_receive_frame(videoCodec, avFrame2); frameFinish = avcodec_receive_frame(videoCodecCtx, yuvFrame);
if (frameFinish < 0) { if (frameFinish < 0) {
continue; continue;
} }
@ -262,10 +260,10 @@ void FFmpegThread::run()
if (frameFinish >= 0) { if (frameFinish >= 0) {
//将数据转成一张图片 //将数据转成一张图片
sws_scale(swsContext, (const uint8_t *const *)avFrame2->data, avFrame2->linesize, 0, videoHeight, avFrame3->data, avFrame3->linesize); sws_scale(swsContext, (const uint8_t *const *)yuvFrame->data, yuvFrame->linesize, 0, videoHeight, rgbFrame->data, rgbFrame->linesize);
//以下两种方法都可以 //以下两种方法都可以
//QImage image(avFrame3->data[0], videoWidth, videoHeight, QImage::Format_RGB32); //QImage image(rgbFrame->data[0], videoWidth, videoHeight, QImage::Format_RGB32);
QImage image((uchar *)buffer, videoWidth, videoHeight, QImage::Format_RGB32); QImage image((uchar *)buffer, videoWidth, videoHeight, QImage::Format_RGB32);
if (!image.isNull()) { if (!image.isNull()) {
emit receiveImage(image); emit receiveImage(image);
@ -276,7 +274,7 @@ void FFmpegThread::run()
#if 1 #if 1
//延时(不然文件会立即全部播放完) //延时(不然文件会立即全部播放完)
AVRational timeBase = {1, AV_TIME_BASE}; AVRational timeBase = {1, AV_TIME_BASE};
int64_t ptsTime = av_rescale_q(avPacket->dts, avFormatContext->streams[videoStreamIndex]->time_base, timeBase); int64_t ptsTime = av_rescale_q(avPacket->dts, formatCtx->streams[videoStreamIndex]->time_base, timeBase);
int64_t nowTime = av_gettime() - startTime; int64_t nowTime = av_gettime() - startTime;
if (ptsTime > nowTime) { if (ptsTime > nowTime) {
av_usleep(ptsTime - nowTime); av_usleep(ptsTime - nowTime);
@ -316,34 +314,29 @@ void FFmpegThread::free()
avPacket = NULL; avPacket = NULL;
} }
if (avFrame != NULL) { if (yuvFrame != NULL) {
av_frame_free(&avFrame); av_frame_free(&yuvFrame);
avFrame = NULL; yuvFrame = NULL;
} }
if (avFrame2 != NULL) { if (rgbFrame != NULL) {
av_frame_free(&avFrame2); av_frame_free(&rgbFrame);
avFrame2 = NULL; rgbFrame = NULL;
} }
if (avFrame3 != NULL) { if (videoCodecCtx != NULL) {
av_frame_free(&avFrame3); avcodec_close(videoCodecCtx);
avFrame3 = NULL; videoCodecCtx = NULL;
} }
if (videoCodec != NULL) { if (audioCodecCtx != NULL) {
avcodec_close(videoCodec); avcodec_close(audioCodecCtx);
videoCodec = NULL; audioCodecCtx = NULL;
} }
if (audioCodec != NULL) { if (formatCtx != NULL) {
avcodec_close(audioCodec); avformat_close_input(&formatCtx);
audioCodec = NULL; formatCtx = NULL;
}
if (avFormatContext != NULL) {
avformat_close_input(&avFormatContext);
avFormatContext = NULL;
} }
av_dict_free(&options); av_dict_free(&options);

View File

@ -25,8 +25,6 @@ private:
int frameFinish; //一帧完成 int frameFinish; //一帧完成
int videoWidth; //视频宽度 int videoWidth; //视频宽度
int videoHeight; //视频高度 int videoHeight; //视频高度
int oldWidth; //上一次视频宽度
int oldHeight; //上一次视频高度
int videoStreamIndex; //视频流索引 int videoStreamIndex; //视频流索引
int audioStreamIndex; //音频流索引 int audioStreamIndex; //音频流索引
@ -34,17 +32,17 @@ private:
uint8_t *buffer; //存储解码后图片buffer uint8_t *buffer; //存储解码后图片buffer
AVPacket *avPacket; //包对象 AVPacket *avPacket; //包对象
AVFrame *avFrame; //帧对象 AVFrame *yuvFrame; //原始视频帧
AVFrame *avFrame2; //帧对象 AVFrame *rgbFrame; //转图片视频帧
AVFrame *avFrame3; //帧对象
AVFormatContext *avFormatContext;//格式对象 AVFormatContext *formatCtx; //格式上下文
AVCodecContext *videoCodec; //视频解码器 AVCodecContext *videoCodecCtx; //视频解码器上下文
AVCodecContext *audioCodec; //音频解码器 AVCodecContext *audioCodecCtx; //音频解码器上下文
SwsContext *swsContext; //处理图片数据对象 SwsContext *swsContext; //处理图片数据对象
AVDictionary *options; //参数对象 AVDictionary *options; //参数对象
AVCodec *videoDecoder; //视频解码 AVCodec *videoCodec; //视频解码器
AVCodec *audioDecoder; //音频解码 AVCodec *audioCodec; //音频解码器
signals: signals:
//收到图片信号 //收到图片信号

View File

@ -28,12 +28,12 @@ bool frmVideoBox::eventFilter(QObject *watched, QEvent *event)
QLabel *widget = (QLabel *) watched; QLabel *widget = (QLabel *) watched;
if (!max) { if (!max) {
max = true; max = true;
box->hide_video_all(); box->hide_all();
ui->gridLayout->addWidget(widget, 0, 0); ui->gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true); widget->setVisible(true);
} else { } else {
max = false; max = false;
box->show_video_all(); box->show_all();
} }
return true; return true;
@ -69,9 +69,9 @@ void frmVideoBox::initForm()
//实例化盒子 //实例化盒子
box = new VideoBox(this); box = new VideoBox(this);
//关联信号槽 //关联信号槽
connect(box, SIGNAL(changeVideo(int, QString, bool)), this, SLOT(changeVideo(int, QString, bool))); connect(box, SIGNAL(changeLayout(int, QString, bool)), this, SLOT(changeLayout(int, QString, bool)));
//可以改成 1_4/5_8/1_36 等 //可以改成 1_4/5_8/1_36 等
box->setVideoType("1_16"); box->setLayoutType("1_16");
box->setLayout(ui->gridLayout); box->setLayout(ui->gridLayout);
box->setWidgets(widgets); box->setWidgets(widgets);
@ -89,7 +89,7 @@ void frmVideoBox::initForm()
//把菜单加到盒子上 //把菜单加到盒子上
box->initMenu(menu); box->initMenu(menu);
box->show_video_all(); box->show_all();
} }
void frmVideoBox::doAction() void frmVideoBox::doAction()
@ -99,7 +99,7 @@ void frmVideoBox::doAction()
ui->label->setText(QString("触发了菜单: %1").arg(action->text())); ui->label->setText(QString("触发了菜单: %1").arg(action->text()));
} }
void frmVideoBox::changeVideo(int type, const QString &videoType, bool videoMax) void frmVideoBox::changeLayout(int type, const QString &videoType, bool videoMax)
{ {
QString info = QString("主菜单:%1 子菜单:%2").arg(type).arg(videoType); QString info = QString("主菜单:%1 子菜单:%2").arg(type).arg(videoType);
ui->label->setText(info); ui->label->setText(info);

View File

@ -32,7 +32,7 @@ private slots:
void doAction(); void doAction();
//画面布局切换信号 //画面布局切换信号
void changeVideo(int type, const QString &videoType, bool videoMax); void changeLayout(int type, const QString &videoType, bool videoMax);
}; };
#endif // FRMVIDEOBOX_H #endif // FRMVIDEOBOX_H

View File

@ -8,9 +8,9 @@
VideoBox::VideoBox(QObject *parent) : QObject(parent) VideoBox::VideoBox(QObject *parent) : QObject(parent)
{ {
gridLayout = 0; maxCount = 64;
videoCount = 64; layoutType = "1_16";
videoType = "1_16"; gridLayout = NULL;
menuFlag = "画面"; menuFlag = "画面";
actionFlag = "通道"; actionFlag = "通道";
@ -20,10 +20,10 @@ VideoBox::VideoBox(QObject *parent) : QObject(parent)
//自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型 //自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型
//1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照2行4列排列) //1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照2行4列排列)
//9_2x4表示通道9开始2x4行列布局画面(相当于通道9-16按照2行4列排列) //9_2x4表示通道9开始2x4行列布局画面(相当于通道9-16按照2行4列排列)
types.insert("x", QStringList() << "1_4x1" << "1_2x4" << "9_2x4" << "1_3x2" << "1_4x2" << "1_5x2" << "1_6x2" << "1_7x2" << "1_8x2"); types.insert("x", QStringList() << "1_1x1" << "1_4x1" << "1_2x4" << "9_2x4" << "1_3x2" << "1_4x2" << "1_5x2" << "1_6x2" << "1_7x2" << "1_8x2");
//自定义y布局/主要是一些用户定义的不规则的排列布局/加个y用于区分其他布局/可能有雷同 //自定义y布局/主要是一些用户定义的不规则的排列布局/加个y用于区分其他布局/可能有雷同
types.insert("y", QStringList() << "y_1_2" << "y_1_3" << "y_1_9" << "y_1_10" << "y_1_12" << "y_1_16"); types.insert("y", QStringList() << "y_1_2" << "y_1_3" << "y_1_5" << "y_1_8" << "y_1_9" << "y_1_10" << "y_1_12" << "y_1_16");
//1_4表示通道1-通道4/前面是通道开始的索引/后面是通道结束的索引 //1_4表示通道1-通道4/前面是通道开始的索引/后面是通道结束的索引
types.insert("4", QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36"); types.insert("4", QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36");
@ -87,7 +87,7 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
} }
//添加菜单动作 //添加菜单动作
QAction *action = menuSub->addAction(text, this, SLOT(show_video())); QAction *action = menuSub->addAction(text, this, SLOT(change_layout()));
//设置弱属性传入大类和子类布局标识等 //设置弱属性传入大类和子类布局标识等
action->setProperty("index", start); action->setProperty("index", start);
action->setProperty("type", type); action->setProperty("type", type);
@ -97,17 +97,17 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
//行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式 //行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式
//按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面 //按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面
void VideoBox::change_video_normal(int index, int row, int column) void VideoBox::change_layout_normal(int index, int row, int column)
{ {
int size = 0; int size = 0;
int rowCount = 0; int rowCount = 0;
int columnCount = 0; int columnCount = 0;
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//按照指定的行列数逐个添加 //按照指定的行列数逐个添加
for (int i = 0; i < videoCount; ++i) { for (int i = 0; i < maxCount; ++i) {
if (i >= index) { if (i >= index) {
//添加到对应布局并设置可见 //添加到对应布局并设置可见
gridLayout->addWidget(widgets.at(i), rowCount, columnCount); gridLayout->addWidget(widgets.at(i), rowCount, columnCount);
@ -128,7 +128,7 @@ void VideoBox::change_video_normal(int index, int row, int column)
} }
} }
void VideoBox::change_video_custom(int index, int type) void VideoBox::change_layout_custom(int index, int type)
{ {
//从开始索引开始往后衍生多少个通道 //从开始索引开始往后衍生多少个通道
QList<int> indexs; QList<int> indexs;
@ -142,13 +142,13 @@ void VideoBox::change_video_custom(int index, int type)
} }
if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) { if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) {
change_video_l(indexs); change_layout_l(indexs);
} else if (type == 13) { } else if (type == 13) {
change_video_o(indexs); change_layout_o(indexs);
} }
} }
void VideoBox::change_video_visible(int start, int end) void VideoBox::change_layout_visible(int start, int end)
{ {
//设置通道控件可见 //设置通道控件可见
for (int i = start; i <= end; ++i) { for (int i = start; i <= end; ++i) {
@ -156,7 +156,7 @@ void VideoBox::change_video_visible(int start, int end)
} }
} }
void VideoBox::change_video_l(const QList<int> &indexs) void VideoBox::change_layout_l(const QList<int> &indexs)
{ {
//通过观察发现这种都是左上角一个大通道/右侧和底部排列几个小通道 //通过观察发现这种都是左上角一个大通道/右侧和底部排列几个小通道
int count = indexs.count(); int count = indexs.count();
@ -164,7 +164,7 @@ void VideoBox::change_video_l(const QList<int> &indexs)
int flag = num - 1; int flag = num - 1;
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//添加大通道 //添加大通道
gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, flag, flag); gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, flag, flag);
@ -188,13 +188,13 @@ void VideoBox::change_video_l(const QList<int> &indexs)
#endif #endif
//设置通道控件可见 //设置通道控件可见
change_video_visible(indexs.first(), indexs.last()); change_layout_visible(indexs.first(), indexs.last());
} }
void VideoBox::change_video_o(const QList<int> &indexs) void VideoBox::change_layout_o(const QList<int> &indexs)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//挨个重新添加到布局 //挨个重新添加到布局
gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 1, 1);
gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 1, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 1, 1, 1);
@ -210,17 +210,17 @@ void VideoBox::change_video_o(const QList<int> &indexs)
gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(indexs.first(), indexs.last()); change_layout_visible(indexs.first(), indexs.last());
} }
QString VideoBox::getVideoType() const QString VideoBox::getLayoutType() const
{ {
return this->videoType; return this->layoutType;
} }
void VideoBox::setVideoType(const QString &videoType) void VideoBox::setLayoutType(const QString &layoutType)
{ {
this->videoType = videoType; this->layoutType = layoutType;
} }
QWidgetList VideoBox::getWidgets() const QWidgetList VideoBox::getWidgets() const
@ -231,7 +231,7 @@ QWidgetList VideoBox::getWidgets() const
void VideoBox::setWidgets(QWidgetList widgets) void VideoBox::setWidgets(QWidgetList widgets)
{ {
this->widgets = widgets; this->widgets = widgets;
this->videoCount = widgets.count(); this->maxCount = widgets.count();
} }
void VideoBox::setLayout(QGridLayout *gridLayout) void VideoBox::setLayout(QGridLayout *gridLayout)
@ -257,7 +257,7 @@ void VideoBox::setVisibles(const QList<bool> &visibles)
void VideoBox::appendType(int index, int row, int column) void VideoBox::appendType(int index, int row, int column)
{ {
//先要过滤下是否满足最大通道数量/start从1开始 //先要过滤下是否满足最大通道数量/start从1开始
if (((index - 1) + (row * column)) > videoCount) { if (((index - 1) + (row * column)) > maxCount) {
return; return;
} }
@ -316,131 +316,168 @@ void VideoBox::initMenu(QMenu *menu)
} }
} }
void VideoBox::show_video_all() void VideoBox::show_all()
{ {
//一般是从配置文件读取到了最后的通道画面类型进行设置 //一般是从配置文件读取到了最后的通道画面类型进行设置
int type = 1; int type = 1;
if (videoType.startsWith("0_")) { int index = layoutType.split("_").first().toInt() - 1;
int index = videoType.split("_").last().toInt() - 1; //y开头的布局需要重置索引=0
change_video_1(index); if (layoutType.startsWith("y")) {
Q_EMIT changeVideo(type, videoType, true); index = 0;
} else {
int index = videoType.split("_").first().toInt() - 1;
//y开头的布局需要重置索引=0
if (videoType.startsWith("y")) {
index = 0;
}
QMap<QString, QStringList>::iterator iter = types.begin();
while (iter != types.end()) {
QStringList flags = iter.value();
if (flags.contains(videoType)) {
type = iter.key().toInt();
show_video(type, index);
return;
}
iter++;
}
//如果运行到这里说明设置了不存在的布局/强制纠正
videoType = "1_4";
this->show_video_all();
} }
QMap<QString, QStringList>::iterator iter = types.begin();
while (iter != types.end()) {
QStringList flags = iter.value();
if (flags.contains(layoutType)) {
type = iter.key().toInt();
change_layout(type, index);
return;
}
iter++;
}
//如果运行到这里说明设置了不存在的布局/强制纠正
layoutType = "1_4";
this->show_all();
} }
void VideoBox::hide_video_all() void VideoBox::hide_all()
{ {
for (int i = 0; i < videoCount; ++i) { for (int i = 0; i < maxCount; ++i) {
gridLayout->removeWidget(widgets.at(i)); gridLayout->removeWidget(widgets.at(i));
widgets.at(i)->setVisible(false); widgets.at(i)->setVisible(false);
} }
} }
void VideoBox::show_video() void VideoBox::change_layout()
{ {
//识别具体是哪个动作菜单触发的 //识别具体是哪个动作菜单触发的
QAction *action = (QAction *)sender(); QAction *action = (QAction *)sender();
//从弱属性取出值 //从弱属性取出值
int index = action->property("index").toInt() - 1; int index = action->property("index").toInt() - 1;
int type = action->property("type").toInt(); int type = action->property("type").toInt();
QString videoType = action->property("flag").toString(); QString layoutType = action->property("flag").toString();
//只有当画面布局类型改变了才需要切换 //只有当画面布局类型改变了才需要切换
if (this->videoType != videoType) { if (this->layoutType != layoutType) {
this->videoType = videoType; this->layoutType = layoutType;
show_video(type, index); change_layout(type, index);
} }
} }
void VideoBox::show_video(int type, int index) void VideoBox::change_layout(int type, int index)
{ {
//根据不同的父菜单类型执行对应的函数 //根据不同的父菜单类型执行对应的函数
if (type == 0) { if (type == 0) {
if (videoType.contains("x")) { if (layoutType.contains("x")) {
//取出行列 //取出行列
QString text = videoType.split("_").last(); QString text = layoutType.split("_").last();
QStringList list = text.split("x"); QStringList list = text.split("x");
int row = list.at(0).toInt(); int row = list.at(0).toInt();
int column = list.at(1).toInt(); int column = list.at(1).toInt();
change_video_normal(index, row, column); change_layout_normal(index, row, column);
} else if (videoType == "y_1_2") {
change_video_y_1_2(index); //只有1个通道需要更改类型/方便外面区分当前是1通道
} else if (videoType == "y_1_3") { if (layoutType.endsWith("1x1")) {
change_video_y_1_3(index); type = 1;
} else if (videoType == "y_1_9") { }
change_video_y_1_9(index); } else if (layoutType == "y_1_2") {
} else if (videoType == "y_1_10") { change_layout_y_1_2(index);
change_video_y_1_10(index); } else if (layoutType == "y_1_3") {
} else if (videoType == "y_1_12") { change_layout_y_1_3(index);
change_video_y_1_12(index); } else if (layoutType == "y_1_5") {
} else if (videoType == "y_1_16") { change_layout_y_1_5(index);
change_video_y_1_16(index); } else if (layoutType == "y_1_8") {
change_layout_y_1_8(index);
} else if (layoutType == "y_1_9") {
change_layout_y_1_9(index);
} else if (layoutType == "y_1_10") {
change_layout_y_1_10(index);
} else if (layoutType == "y_1_12") {
change_layout_y_1_12(index);
} else if (layoutType == "y_1_16") {
change_layout_y_1_16(index);
} }
} else if (type == 1) { } else if (type == 1) {
change_video_1(index); change_layout_1(index);
} else if (type == 4) { } else if (type == 4) {
change_video_4(index); change_layout_4(index);
} else if (type == 6) { } else if (type == 6) {
change_video_6(index); change_layout_6(index);
} else if (type == 8) { } else if (type == 8) {
change_video_8(index); change_layout_8(index);
} else if (type == 9) { } else if (type == 9) {
change_video_9(index); change_layout_9(index);
} else if (type == 13) { } else if (type == 13) {
change_video_13(index); change_layout_13(index);
} else if (type == 16) { } else if (type == 16) {
change_video_16(index); change_layout_16(index);
} else if (type == 25) { } else if (type == 25) {
change_video_25(index); change_layout_25(index);
} else if (type == 36) { } else if (type == 36) {
change_video_36(index); change_layout_36(index);
} else if (type == 64) { } else if (type == 64) {
change_video_64(index); change_layout_64(index);
} }
Q_EMIT changeVideo(type, videoType, false); Q_EMIT changeLayout(type, layoutType, false);
} }
void VideoBox::change_video_y_1_2(int index) void VideoBox::change_layout_y_1_2(int index)
{ {
change_video_normal(index, 1, 2); change_layout_normal(index, 1, 2);
} }
void VideoBox::change_video_y_1_3(int index) void VideoBox::change_layout_y_1_3(int index)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//添加通道到布局 //添加通道到布局
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2); gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2);
gridLayout->addWidget(widgets.at(index + 1), 1, 0); gridLayout->addWidget(widgets.at(index + 1), 1, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 2), 1, 1); gridLayout->addWidget(widgets.at(index + 2), 1, 1, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(index, index + 2); change_layout_visible(index, index + 2);
} }
void VideoBox::change_video_y_1_9(int index) void VideoBox::change_layout_y_1_5(int index)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//依次左上/左下/
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2);
gridLayout->addWidget(widgets.at(index + 1), 1, 0, 2, 1);
gridLayout->addWidget(widgets.at(index + 2), 1, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 3), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 4), 0, 2, 3, 1);
//设置通道控件可见
change_layout_visible(index, index + 4);
}
void VideoBox::change_layout_y_1_8(int index)
{
//首先隐藏所有通道
hide_all();
//添加上面4个通道
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 1), 0, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 2), 0, 2, 1, 1);
gridLayout->addWidget(widgets.at(index + 3), 0, 3, 1, 1);
//添加中间全景通道
gridLayout->addWidget(widgets.at(index + 8), 1, 0, 1, 4);
//添加下面4个通道
gridLayout->addWidget(widgets.at(index + 4), 2, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 5), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 6), 2, 2, 1, 1);
gridLayout->addWidget(widgets.at(index + 7), 2, 3, 1, 1);
//设置通道控件可见
change_layout_visible(index, index + 8);
}
void VideoBox::change_layout_y_1_9(int index)
{
//首先隐藏所有通道
hide_all();
//添加通道到布局 //添加通道到布局
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 2, 2); gridLayout->addWidget(widgets.at(index + 0), 0, 0, 2, 2);
gridLayout->addWidget(widgets.at(index + 1), 0, 2, 1, 1); gridLayout->addWidget(widgets.at(index + 1), 0, 2, 1, 1);
@ -452,70 +489,70 @@ void VideoBox::change_video_y_1_9(int index)
gridLayout->addWidget(widgets.at(index + 7), 2, 1, 1, 1); gridLayout->addWidget(widgets.at(index + 7), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 8), 2, 0, 1, 1); gridLayout->addWidget(widgets.at(index + 8), 2, 0, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(index, index + 8); change_layout_visible(index, index + 8);
} }
void VideoBox::change_video_y_1_10(int index) void VideoBox::change_layout_y_1_10(int index)
{ {
change_video_custom(index, 10); change_layout_custom(index, 10);
} }
void VideoBox::change_video_y_1_12(int index) void VideoBox::change_layout_y_1_12(int index)
{ {
change_video_custom(index, 12); change_layout_custom(index, 12);
} }
void VideoBox::change_video_y_1_16(int index) void VideoBox::change_layout_y_1_16(int index)
{ {
change_video_custom(index, 16); change_layout_custom(index, 16);
} }
void VideoBox::change_video_1(int index) void VideoBox::change_layout_1(int index)
{ {
change_video_normal(index, 1, 1); change_layout_normal(index, 1, 1);
} }
void VideoBox::change_video_4(int index) void VideoBox::change_layout_4(int index)
{ {
change_video_normal(index, 2, 2); change_layout_normal(index, 2, 2);
} }
void VideoBox::change_video_6(int index) void VideoBox::change_layout_6(int index)
{ {
change_video_custom(index, 6); change_layout_custom(index, 6);
} }
void VideoBox::change_video_8(int index) void VideoBox::change_layout_8(int index)
{ {
change_video_custom(index, 8); change_layout_custom(index, 8);
} }
void VideoBox::change_video_9(int index) void VideoBox::change_layout_9(int index)
{ {
change_video_normal(index, 3, 3); change_layout_normal(index, 3, 3);
} }
void VideoBox::change_video_13(int index) void VideoBox::change_layout_13(int index)
{ {
change_video_custom(index, 13); change_layout_custom(index, 13);
} }
void VideoBox::change_video_16(int index) void VideoBox::change_layout_16(int index)
{ {
change_video_normal(index, 4, 4); change_layout_normal(index, 4, 4);
} }
void VideoBox::change_video_25(int index) void VideoBox::change_layout_25(int index)
{ {
change_video_normal(index, 5, 5); change_layout_normal(index, 5, 5);
} }
void VideoBox::change_video_36(int index) void VideoBox::change_layout_36(int index)
{ {
change_video_normal(index, 6, 6); change_layout_normal(index, 6, 6);
} }
void VideoBox::change_video_64(int index) void VideoBox::change_layout_64(int index)
{ {
change_video_normal(index, 8, 8); change_layout_normal(index, 8, 8);
} }

View File

@ -35,16 +35,16 @@ public:
explicit VideoBox(QObject *parent = 0); explicit VideoBox(QObject *parent = 0);
private: private:
//最大通道数量
int maxCount;
//当前布局类型
QString layoutType;
//表格布局存放通道 //表格布局存放通道
QGridLayout *gridLayout; QGridLayout *gridLayout;
//视频控件集合 //视频控件集合
QWidgetList widgets; QWidgetList widgets;
//通道数量
int videoCount;
//当前画面类型
QString videoType;
//主菜单子菜单文字标识 //主菜单子菜单文字标识
QString menuFlag; QString menuFlag;
QString actionFlag; QString actionFlag;
@ -58,20 +58,20 @@ private:
private: private:
//常规及异形通道布局 //常规及异形通道布局
void change_video_normal(int index, int row, int column); void change_layout_normal(int index, int row, int column);
void change_video_custom(int index, int type); void change_layout_custom(int index, int type);
//设置可见 //设置可见
void change_video_visible(int start, int end); void change_layout_visible(int start, int end);
//异形布局(l表示右侧底部环绕布局/o表示上下左右环绕布局) //异形布局(l表示右侧底部环绕布局/o表示上下左右环绕布局)
void change_video_l(const QList<int> &indexs); void change_layout_l(const QList<int> &indexs);
void change_video_o(const QList<int> &indexs); void change_layout_o(const QList<int> &indexs);
public: public:
//获取和设置当前画面类型 //获取和设置当前布局类型
QString getVideoType() const; QString getLayoutType() const;
void setVideoType(const QString &videoType); void setLayoutType(const QString &layoutType);
//获取和设置视频控件集合 //获取和设置视频控件集合
QWidgetList getWidgets() const; QWidgetList getWidgets() const;
@ -94,36 +94,38 @@ public:
public Q_SLOTS: public Q_SLOTS:
//显示和隐藏所有通道 //显示和隐藏所有通道
void show_video_all(); void show_all();
void hide_video_all(); void hide_all();
//菜单切换布局槽函数 //菜单切换布局槽函数
void show_video(); void change_layout();
void show_video(int type, int index); void change_layout(int type, int index);
//自定义布局通道切换函数 //自定义布局通道切换函数
void change_video_y_1_2(int index); void change_layout_y_1_2(int index);
void change_video_y_1_3(int index); void change_layout_y_1_3(int index);
void change_video_y_1_9(int index); void change_layout_y_1_5(int index);
void change_video_y_1_10(int index); void change_layout_y_1_8(int index);
void change_video_y_1_12(int index); void change_layout_y_1_9(int index);
void change_video_y_1_16(int index); void change_layout_y_1_10(int index);
void change_layout_y_1_12(int index);
void change_layout_y_1_16(int index);
//常规布局通道切换函数 //常规布局通道切换函数
void change_video_1(int index); void change_layout_1(int index);
void change_video_4(int index); void change_layout_4(int index);
void change_video_6(int index); void change_layout_6(int index);
void change_video_8(int index); void change_layout_8(int index);
void change_video_9(int index); void change_layout_9(int index);
void change_video_13(int index); void change_layout_13(int index);
void change_video_16(int index); void change_layout_16(int index);
void change_video_25(int index); void change_layout_25(int index);
void change_video_36(int index); void change_layout_36(int index);
void change_video_64(int index); void change_layout_64(int index);
Q_SIGNALS: Q_SIGNALS:
//画面布局切换信号 //画面布局切换信号
void changeVideo(int type, const QString &videoType, bool videoMax); void changeLayout(int type, const QString &layoutType, bool max);
}; };
#endif // VIDEOBOX_H #endif // VIDEOBOX_H

View File

@ -8,9 +8,9 @@
VideoBox::VideoBox(QObject *parent) : QObject(parent) VideoBox::VideoBox(QObject *parent) : QObject(parent)
{ {
gridLayout = 0; maxCount = 64;
videoCount = 64; layoutType = "1_16";
videoType = "1_16"; gridLayout = NULL;
menuFlag = "画面"; menuFlag = "画面";
actionFlag = "通道"; actionFlag = "通道";
@ -20,10 +20,10 @@ VideoBox::VideoBox(QObject *parent) : QObject(parent)
//自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型 //自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型
//1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照2行4列排列) //1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照2行4列排列)
//9_2x4表示通道9开始2x4行列布局画面(相当于通道9-16按照2行4列排列) //9_2x4表示通道9开始2x4行列布局画面(相当于通道9-16按照2行4列排列)
types.insert("x", QStringList() << "1_4x1" << "1_2x4" << "9_2x4" << "1_3x2" << "1_4x2" << "1_5x2" << "1_6x2" << "1_7x2" << "1_8x2"); types.insert("x", QStringList() << "1_1x1" << "1_4x1" << "1_2x4" << "9_2x4" << "1_3x2" << "1_4x2" << "1_5x2" << "1_6x2" << "1_7x2" << "1_8x2");
//自定义y布局/主要是一些用户定义的不规则的排列布局/加个y用于区分其他布局/可能有雷同 //自定义y布局/主要是一些用户定义的不规则的排列布局/加个y用于区分其他布局/可能有雷同
types.insert("y", QStringList() << "y_1_2" << "y_1_3" << "y_1_9" << "y_1_10" << "y_1_12" << "y_1_16"); types.insert("y", QStringList() << "y_1_2" << "y_1_3" << "y_1_5" << "y_1_8" << "y_1_9" << "y_1_10" << "y_1_12" << "y_1_16");
//1_4表示通道1-通道4/前面是通道开始的索引/后面是通道结束的索引 //1_4表示通道1-通道4/前面是通道开始的索引/后面是通道结束的索引
types.insert("4", QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36"); types.insert("4", QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36");
@ -87,7 +87,7 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
} }
//添加菜单动作 //添加菜单动作
QAction *action = menuSub->addAction(text, this, SLOT(show_video())); QAction *action = menuSub->addAction(text, this, SLOT(change_layout()));
//设置弱属性传入大类和子类布局标识等 //设置弱属性传入大类和子类布局标识等
action->setProperty("index", start); action->setProperty("index", start);
action->setProperty("type", type); action->setProperty("type", type);
@ -97,17 +97,17 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
//行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式 //行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式
//按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面 //按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面
void VideoBox::change_video_normal(int index, int row, int column) void VideoBox::change_layout_normal(int index, int row, int column)
{ {
int size = 0; int size = 0;
int rowCount = 0; int rowCount = 0;
int columnCount = 0; int columnCount = 0;
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//按照指定的行列数逐个添加 //按照指定的行列数逐个添加
for (int i = 0; i < videoCount; ++i) { for (int i = 0; i < maxCount; ++i) {
if (i >= index) { if (i >= index) {
//添加到对应布局并设置可见 //添加到对应布局并设置可见
gridLayout->addWidget(widgets.at(i), rowCount, columnCount); gridLayout->addWidget(widgets.at(i), rowCount, columnCount);
@ -128,7 +128,7 @@ void VideoBox::change_video_normal(int index, int row, int column)
} }
} }
void VideoBox::change_video_custom(int index, int type) void VideoBox::change_layout_custom(int index, int type)
{ {
//从开始索引开始往后衍生多少个通道 //从开始索引开始往后衍生多少个通道
QList<int> indexs; QList<int> indexs;
@ -142,13 +142,13 @@ void VideoBox::change_video_custom(int index, int type)
} }
if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) { if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) {
change_video_l(indexs); change_layout_l(indexs);
} else if (type == 13) { } else if (type == 13) {
change_video_o(indexs); change_layout_o(indexs);
} }
} }
void VideoBox::change_video_visible(int start, int end) void VideoBox::change_layout_visible(int start, int end)
{ {
//设置通道控件可见 //设置通道控件可见
for (int i = start; i <= end; ++i) { for (int i = start; i <= end; ++i) {
@ -156,7 +156,7 @@ void VideoBox::change_video_visible(int start, int end)
} }
} }
void VideoBox::change_video_l(const QList<int> &indexs) void VideoBox::change_layout_l(const QList<int> &indexs)
{ {
//通过观察发现这种都是左上角一个大通道/右侧和底部排列几个小通道 //通过观察发现这种都是左上角一个大通道/右侧和底部排列几个小通道
int count = indexs.count(); int count = indexs.count();
@ -164,7 +164,7 @@ void VideoBox::change_video_l(const QList<int> &indexs)
int flag = num - 1; int flag = num - 1;
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//添加大通道 //添加大通道
gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, flag, flag); gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, flag, flag);
@ -188,13 +188,13 @@ void VideoBox::change_video_l(const QList<int> &indexs)
#endif #endif
//设置通道控件可见 //设置通道控件可见
change_video_visible(indexs.first(), indexs.last()); change_layout_visible(indexs.first(), indexs.last());
} }
void VideoBox::change_video_o(const QList<int> &indexs) void VideoBox::change_layout_o(const QList<int> &indexs)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//挨个重新添加到布局 //挨个重新添加到布局
gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 1, 1);
gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 1, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 1, 1, 1);
@ -210,17 +210,17 @@ void VideoBox::change_video_o(const QList<int> &indexs)
gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1); gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(indexs.first(), indexs.last()); change_layout_visible(indexs.first(), indexs.last());
} }
QString VideoBox::getVideoType() const QString VideoBox::getLayoutType() const
{ {
return this->videoType; return this->layoutType;
} }
void VideoBox::setVideoType(const QString &videoType) void VideoBox::setLayoutType(const QString &layoutType)
{ {
this->videoType = videoType; this->layoutType = layoutType;
} }
QWidgetList VideoBox::getWidgets() const QWidgetList VideoBox::getWidgets() const
@ -231,7 +231,7 @@ QWidgetList VideoBox::getWidgets() const
void VideoBox::setWidgets(QWidgetList widgets) void VideoBox::setWidgets(QWidgetList widgets)
{ {
this->widgets = widgets; this->widgets = widgets;
this->videoCount = widgets.count(); this->maxCount = widgets.count();
} }
void VideoBox::setLayout(QGridLayout *gridLayout) void VideoBox::setLayout(QGridLayout *gridLayout)
@ -257,7 +257,7 @@ void VideoBox::setVisibles(const QList<bool> &visibles)
void VideoBox::appendType(int index, int row, int column) void VideoBox::appendType(int index, int row, int column)
{ {
//先要过滤下是否满足最大通道数量/start从1开始 //先要过滤下是否满足最大通道数量/start从1开始
if (((index - 1) + (row * column)) > videoCount) { if (((index - 1) + (row * column)) > maxCount) {
return; return;
} }
@ -316,131 +316,168 @@ void VideoBox::initMenu(QMenu *menu)
} }
} }
void VideoBox::show_video_all() void VideoBox::show_all()
{ {
//一般是从配置文件读取到了最后的通道画面类型进行设置 //一般是从配置文件读取到了最后的通道画面类型进行设置
int type = 1; int type = 1;
if (videoType.startsWith("0_")) { int index = layoutType.split("_").first().toInt() - 1;
int index = videoType.split("_").last().toInt() - 1; //y开头的布局需要重置索引=0
change_video_1(index); if (layoutType.startsWith("y")) {
Q_EMIT changeVideo(type, videoType, true); index = 0;
} else {
int index = videoType.split("_").first().toInt() - 1;
//y开头的布局需要重置索引=0
if (videoType.startsWith("y")) {
index = 0;
}
QMap<QString, QStringList>::iterator iter = types.begin();
while (iter != types.end()) {
QStringList flags = iter.value();
if (flags.contains(videoType)) {
type = iter.key().toInt();
show_video(type, index);
return;
}
iter++;
}
//如果运行到这里说明设置了不存在的布局/强制纠正
videoType = "1_4";
this->show_video_all();
} }
QMap<QString, QStringList>::iterator iter = types.begin();
while (iter != types.end()) {
QStringList flags = iter.value();
if (flags.contains(layoutType)) {
type = iter.key().toInt();
change_layout(type, index);
return;
}
iter++;
}
//如果运行到这里说明设置了不存在的布局/强制纠正
layoutType = "1_4";
this->show_all();
} }
void VideoBox::hide_video_all() void VideoBox::hide_all()
{ {
for (int i = 0; i < videoCount; ++i) { for (int i = 0; i < maxCount; ++i) {
gridLayout->removeWidget(widgets.at(i)); gridLayout->removeWidget(widgets.at(i));
widgets.at(i)->setVisible(false); widgets.at(i)->setVisible(false);
} }
} }
void VideoBox::show_video() void VideoBox::change_layout()
{ {
//识别具体是哪个动作菜单触发的 //识别具体是哪个动作菜单触发的
QAction *action = (QAction *)sender(); QAction *action = (QAction *)sender();
//从弱属性取出值 //从弱属性取出值
int index = action->property("index").toInt() - 1; int index = action->property("index").toInt() - 1;
int type = action->property("type").toInt(); int type = action->property("type").toInt();
QString videoType = action->property("flag").toString(); QString layoutType = action->property("flag").toString();
//只有当画面布局类型改变了才需要切换 //只有当画面布局类型改变了才需要切换
if (this->videoType != videoType) { if (this->layoutType != layoutType) {
this->videoType = videoType; this->layoutType = layoutType;
show_video(type, index); change_layout(type, index);
} }
} }
void VideoBox::show_video(int type, int index) void VideoBox::change_layout(int type, int index)
{ {
//根据不同的父菜单类型执行对应的函数 //根据不同的父菜单类型执行对应的函数
if (type == 0) { if (type == 0) {
if (videoType.contains("x")) { if (layoutType.contains("x")) {
//取出行列 //取出行列
QString text = videoType.split("_").last(); QString text = layoutType.split("_").last();
QStringList list = text.split("x"); QStringList list = text.split("x");
int row = list.at(0).toInt(); int row = list.at(0).toInt();
int column = list.at(1).toInt(); int column = list.at(1).toInt();
change_video_normal(index, row, column); change_layout_normal(index, row, column);
} else if (videoType == "y_1_2") {
change_video_y_1_2(index); //只有1个通道需要更改类型/方便外面区分当前是1通道
} else if (videoType == "y_1_3") { if (layoutType.endsWith("1x1")) {
change_video_y_1_3(index); type = 1;
} else if (videoType == "y_1_9") { }
change_video_y_1_9(index); } else if (layoutType == "y_1_2") {
} else if (videoType == "y_1_10") { change_layout_y_1_2(index);
change_video_y_1_10(index); } else if (layoutType == "y_1_3") {
} else if (videoType == "y_1_12") { change_layout_y_1_3(index);
change_video_y_1_12(index); } else if (layoutType == "y_1_5") {
} else if (videoType == "y_1_16") { change_layout_y_1_5(index);
change_video_y_1_16(index); } else if (layoutType == "y_1_8") {
change_layout_y_1_8(index);
} else if (layoutType == "y_1_9") {
change_layout_y_1_9(index);
} else if (layoutType == "y_1_10") {
change_layout_y_1_10(index);
} else if (layoutType == "y_1_12") {
change_layout_y_1_12(index);
} else if (layoutType == "y_1_16") {
change_layout_y_1_16(index);
} }
} else if (type == 1) { } else if (type == 1) {
change_video_1(index); change_layout_1(index);
} else if (type == 4) { } else if (type == 4) {
change_video_4(index); change_layout_4(index);
} else if (type == 6) { } else if (type == 6) {
change_video_6(index); change_layout_6(index);
} else if (type == 8) { } else if (type == 8) {
change_video_8(index); change_layout_8(index);
} else if (type == 9) { } else if (type == 9) {
change_video_9(index); change_layout_9(index);
} else if (type == 13) { } else if (type == 13) {
change_video_13(index); change_layout_13(index);
} else if (type == 16) { } else if (type == 16) {
change_video_16(index); change_layout_16(index);
} else if (type == 25) { } else if (type == 25) {
change_video_25(index); change_layout_25(index);
} else if (type == 36) { } else if (type == 36) {
change_video_36(index); change_layout_36(index);
} else if (type == 64) { } else if (type == 64) {
change_video_64(index); change_layout_64(index);
} }
Q_EMIT changeVideo(type, videoType, false); Q_EMIT changeLayout(type, layoutType, false);
} }
void VideoBox::change_video_y_1_2(int index) void VideoBox::change_layout_y_1_2(int index)
{ {
change_video_normal(index, 1, 2); change_layout_normal(index, 1, 2);
} }
void VideoBox::change_video_y_1_3(int index) void VideoBox::change_layout_y_1_3(int index)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//添加通道到布局 //添加通道到布局
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2); gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2);
gridLayout->addWidget(widgets.at(index + 1), 1, 0); gridLayout->addWidget(widgets.at(index + 1), 1, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 2), 1, 1); gridLayout->addWidget(widgets.at(index + 2), 1, 1, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(index, index + 2); change_layout_visible(index, index + 2);
} }
void VideoBox::change_video_y_1_9(int index) void VideoBox::change_layout_y_1_5(int index)
{ {
//首先隐藏所有通道 //首先隐藏所有通道
hide_video_all(); hide_all();
//依次左上/左下/
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 2);
gridLayout->addWidget(widgets.at(index + 1), 1, 0, 2, 1);
gridLayout->addWidget(widgets.at(index + 2), 1, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 3), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 4), 0, 2, 3, 1);
//设置通道控件可见
change_layout_visible(index, index + 4);
}
void VideoBox::change_layout_y_1_8(int index)
{
//首先隐藏所有通道
hide_all();
//添加上面4个通道
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 1), 0, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 2), 0, 2, 1, 1);
gridLayout->addWidget(widgets.at(index + 3), 0, 3, 1, 1);
//添加中间全景通道
gridLayout->addWidget(widgets.at(index + 8), 1, 0, 1, 4);
//添加下面4个通道
gridLayout->addWidget(widgets.at(index + 4), 2, 0, 1, 1);
gridLayout->addWidget(widgets.at(index + 5), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 6), 2, 2, 1, 1);
gridLayout->addWidget(widgets.at(index + 7), 2, 3, 1, 1);
//设置通道控件可见
change_layout_visible(index, index + 8);
}
void VideoBox::change_layout_y_1_9(int index)
{
//首先隐藏所有通道
hide_all();
//添加通道到布局 //添加通道到布局
gridLayout->addWidget(widgets.at(index + 0), 0, 0, 2, 2); gridLayout->addWidget(widgets.at(index + 0), 0, 0, 2, 2);
gridLayout->addWidget(widgets.at(index + 1), 0, 2, 1, 1); gridLayout->addWidget(widgets.at(index + 1), 0, 2, 1, 1);
@ -452,70 +489,70 @@ void VideoBox::change_video_y_1_9(int index)
gridLayout->addWidget(widgets.at(index + 7), 2, 1, 1, 1); gridLayout->addWidget(widgets.at(index + 7), 2, 1, 1, 1);
gridLayout->addWidget(widgets.at(index + 8), 2, 0, 1, 1); gridLayout->addWidget(widgets.at(index + 8), 2, 0, 1, 1);
//设置通道控件可见 //设置通道控件可见
change_video_visible(index, index + 8); change_layout_visible(index, index + 8);
} }
void VideoBox::change_video_y_1_10(int index) void VideoBox::change_layout_y_1_10(int index)
{ {
change_video_custom(index, 10); change_layout_custom(index, 10);
} }
void VideoBox::change_video_y_1_12(int index) void VideoBox::change_layout_y_1_12(int index)
{ {
change_video_custom(index, 12); change_layout_custom(index, 12);
} }
void VideoBox::change_video_y_1_16(int index) void VideoBox::change_layout_y_1_16(int index)
{ {
change_video_custom(index, 16); change_layout_custom(index, 16);
} }
void VideoBox::change_video_1(int index) void VideoBox::change_layout_1(int index)
{ {
change_video_normal(index, 1, 1); change_layout_normal(index, 1, 1);
} }
void VideoBox::change_video_4(int index) void VideoBox::change_layout_4(int index)
{ {
change_video_normal(index, 2, 2); change_layout_normal(index, 2, 2);
} }
void VideoBox::change_video_6(int index) void VideoBox::change_layout_6(int index)
{ {
change_video_custom(index, 6); change_layout_custom(index, 6);
} }
void VideoBox::change_video_8(int index) void VideoBox::change_layout_8(int index)
{ {
change_video_custom(index, 8); change_layout_custom(index, 8);
} }
void VideoBox::change_video_9(int index) void VideoBox::change_layout_9(int index)
{ {
change_video_normal(index, 3, 3); change_layout_normal(index, 3, 3);
} }
void VideoBox::change_video_13(int index) void VideoBox::change_layout_13(int index)
{ {
change_video_custom(index, 13); change_layout_custom(index, 13);
} }
void VideoBox::change_video_16(int index) void VideoBox::change_layout_16(int index)
{ {
change_video_normal(index, 4, 4); change_layout_normal(index, 4, 4);
} }
void VideoBox::change_video_25(int index) void VideoBox::change_layout_25(int index)
{ {
change_video_normal(index, 5, 5); change_layout_normal(index, 5, 5);
} }
void VideoBox::change_video_36(int index) void VideoBox::change_layout_36(int index)
{ {
change_video_normal(index, 6, 6); change_layout_normal(index, 6, 6);
} }
void VideoBox::change_video_64(int index) void VideoBox::change_layout_64(int index)
{ {
change_video_normal(index, 8, 8); change_layout_normal(index, 8, 8);
} }

View File

@ -35,16 +35,16 @@ public:
explicit VideoBox(QObject *parent = 0); explicit VideoBox(QObject *parent = 0);
private: private:
//最大通道数量
int maxCount;
//当前布局类型
QString layoutType;
//表格布局存放通道 //表格布局存放通道
QGridLayout *gridLayout; QGridLayout *gridLayout;
//视频控件集合 //视频控件集合
QWidgetList widgets; QWidgetList widgets;
//通道数量
int videoCount;
//当前画面类型
QString videoType;
//主菜单子菜单文字标识 //主菜单子菜单文字标识
QString menuFlag; QString menuFlag;
QString actionFlag; QString actionFlag;
@ -58,20 +58,20 @@ private:
private: private:
//常规及异形通道布局 //常规及异形通道布局
void change_video_normal(int index, int row, int column); void change_layout_normal(int index, int row, int column);
void change_video_custom(int index, int type); void change_layout_custom(int index, int type);
//设置可见 //设置可见
void change_video_visible(int start, int end); void change_layout_visible(int start, int end);
//异形布局(l表示右侧底部环绕布局/o表示上下左右环绕布局) //异形布局(l表示右侧底部环绕布局/o表示上下左右环绕布局)
void change_video_l(const QList<int> &indexs); void change_layout_l(const QList<int> &indexs);
void change_video_o(const QList<int> &indexs); void change_layout_o(const QList<int> &indexs);
public: public:
//获取和设置当前画面类型 //获取和设置当前布局类型
QString getVideoType() const; QString getLayoutType() const;
void setVideoType(const QString &videoType); void setLayoutType(const QString &layoutType);
//获取和设置视频控件集合 //获取和设置视频控件集合
QWidgetList getWidgets() const; QWidgetList getWidgets() const;
@ -94,36 +94,38 @@ public:
public Q_SLOTS: public Q_SLOTS:
//显示和隐藏所有通道 //显示和隐藏所有通道
void show_video_all(); void show_all();
void hide_video_all(); void hide_all();
//菜单切换布局槽函数 //菜单切换布局槽函数
void show_video(); void change_layout();
void show_video(int type, int index); void change_layout(int type, int index);
//自定义布局通道切换函数 //自定义布局通道切换函数
void change_video_y_1_2(int index); void change_layout_y_1_2(int index);
void change_video_y_1_3(int index); void change_layout_y_1_3(int index);
void change_video_y_1_9(int index); void change_layout_y_1_5(int index);
void change_video_y_1_10(int index); void change_layout_y_1_8(int index);
void change_video_y_1_12(int index); void change_layout_y_1_9(int index);
void change_video_y_1_16(int index); void change_layout_y_1_10(int index);
void change_layout_y_1_12(int index);
void change_layout_y_1_16(int index);
//常规布局通道切换函数 //常规布局通道切换函数
void change_video_1(int index); void change_layout_1(int index);
void change_video_4(int index); void change_layout_4(int index);
void change_video_6(int index); void change_layout_6(int index);
void change_video_8(int index); void change_layout_8(int index);
void change_video_9(int index); void change_layout_9(int index);
void change_video_13(int index); void change_layout_13(int index);
void change_video_16(int index); void change_layout_16(int index);
void change_video_25(int index); void change_layout_25(int index);
void change_video_36(int index); void change_layout_36(int index);
void change_video_64(int index); void change_layout_64(int index);
Q_SIGNALS: Q_SIGNALS:
//画面布局切换信号 //画面布局切换信号
void changeVideo(int type, const QString &videoType, bool videoMax); void changeLayout(int type, const QString &layoutType, bool max);
}; };
#endif // VIDEOBOX_H #endif // VIDEOBOX_H

View File

@ -14,7 +14,7 @@ VideoPanel::VideoPanel(QWidget *parent) : QWidget(parent)
this->initControl(); this->initControl();
this->initForm(); this->initForm();
this->initMenu(); this->initMenu();
QTimer::singleShot(1000, this, SLOT(play_video_all())); QTimer::singleShot(1000, this, SLOT(playAll()));
} }
bool VideoPanel::eventFilter(QObject *watched, QEvent *event) bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
@ -24,12 +24,12 @@ bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
QLabel *widget = (QLabel *) watched; QLabel *widget = (QLabel *) watched;
if (!videoMax) { if (!videoMax) {
videoMax = true; videoMax = true;
videoBox->hide_video_all(); videoBox->hide_all();
gridLayout->addWidget(widget, 0, 0); gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true); widget->setVisible(true);
} else { } else {
videoMax = false; videoMax = false;
videoBox->show_video_all(); videoBox->show_all();
} }
widget->setFocus(); widget->setFocus();
@ -74,7 +74,7 @@ void VideoPanel::initForm()
videoMax = false; videoMax = false;
videoCount = 64; videoCount = 64;
videoType = "1_16"; layoutType = "1_16";
for (int i = 0; i < videoCount; ++i) { for (int i = 0; i < videoCount; ++i) {
QLabel *widget = new QLabel; QLabel *widget = new QLabel;
@ -107,17 +107,17 @@ void VideoPanel::initMenu()
videoMenu->addSeparator(); videoMenu->addSeparator();
//直接通过文字的形式添加子菜单 //直接通过文字的形式添加子菜单
videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one())); videoMenu->addAction("截图当前视频", this, SLOT(snapOne()));
videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all())); videoMenu->addAction("截图所有视频", this, SLOT(snapAll()));
videoMenu->addSeparator(); videoMenu->addSeparator();
//实例化通道布局类 //实例化通道布局类
videoBox = new VideoBox(this); videoBox = new VideoBox(this);
videoBox->initMenu(videoMenu); videoBox->initMenu(videoMenu);
videoBox->setVideoType(videoType); videoBox->setLayoutType(layoutType);
videoBox->setLayout(gridLayout); videoBox->setLayout(gridLayout);
videoBox->setWidgets(widgets); videoBox->setWidgets(widgets);
videoBox->show_video_all(); videoBox->show_all();
} }
void VideoPanel::full() void VideoPanel::full()
@ -144,17 +144,17 @@ void VideoPanel::poll()
//执行轮询处理 //执行轮询处理
} }
void VideoPanel::play_video_all() void VideoPanel::playAll()
{ {
} }
void VideoPanel::snapshot_video_one() void VideoPanel::snapOne()
{ {
} }
void VideoPanel::snapshot_video_all() void VideoPanel::snapAll()
{ {
} }

View File

@ -34,8 +34,8 @@ protected:
private: private:
bool videoMax; //是否最大化 bool videoMax; //是否最大化
int videoCount; //视频通道个 int videoCount; //最大通道
QString videoType; //当前画面类型 QString layoutType; //当前画面类型
QMenu *videoMenu; //右键菜单 QMenu *videoMenu; //右键菜单
QAction *actionFull; //全屏动作 QAction *actionFull; //全屏动作
QAction *actionPoll; //轮询动作 QAction *actionPoll; //轮询动作
@ -56,9 +56,9 @@ private slots:
void poll(); void poll();
private slots: private slots:
void play_video_all(); void playAll();
void snapshot_video_one(); void snapOne();
void snapshot_video_all(); void snapAll();
Q_SIGNALS: Q_SIGNALS:
//全屏切换信号 //全屏切换信号