更新文档

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()
{
cpuPercent = (cpuPercent < 0 ? 0 : cpuPercent);
//cpuPercent = (cpuPercent < 0 ? 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);
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)
{
//判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
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);
QStringList listName = fontDb.applicationFontFamilies(fontId);
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)
{
//判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
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);
QStringList listName = fontDb.applicationFontFamilies(fontId);
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)
{
//判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
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);
QStringList listName = fontDb.applicationFontFamilies(fontId);
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)
{
//判断图形字体是否存在,不存在则加入
//这里暂时限制在同一个项目中只加载一次字体文件
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);
QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) {

View File

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

View File

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

View File

@ -28,12 +28,12 @@ bool frmVideoBox::eventFilter(QObject *watched, QEvent *event)
QLabel *widget = (QLabel *) watched;
if (!max) {
max = true;
box->hide_video_all();
box->hide_all();
ui->gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true);
} else {
max = false;
box->show_video_all();
box->show_all();
}
return true;
@ -69,9 +69,9 @@ void frmVideoBox::initForm()
//实例化盒子
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 等
box->setVideoType("1_16");
box->setLayoutType("1_16");
box->setLayout(ui->gridLayout);
box->setWidgets(widgets);
@ -89,7 +89,7 @@ void frmVideoBox::initForm()
//把菜单加到盒子上
box->initMenu(menu);
box->show_video_all();
box->show_all();
}
void frmVideoBox::doAction()
@ -99,7 +99,7 @@ void frmVideoBox::doAction()
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);
ui->label->setText(info);

View File

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

View File

@ -8,9 +8,9 @@
VideoBox::VideoBox(QObject *parent) : QObject(parent)
{
gridLayout = 0;
videoCount = 64;
videoType = "1_16";
maxCount = 64;
layoutType = "1_16";
gridLayout = NULL;
menuFlag = "画面";
actionFlag = "通道";
@ -20,10 +20,10 @@ VideoBox::VideoBox(QObject *parent) : QObject(parent)
//自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型
//1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照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用于区分其他布局/可能有雷同
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/前面是通道开始的索引/后面是通道结束的索引
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("type", type);
@ -97,17 +97,17 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
//行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式
//按照这个函数还可以非常容易的拓展出 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 rowCount = 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) {
//添加到对应布局并设置可见
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;
@ -142,13 +142,13 @@ void VideoBox::change_video_custom(int index, int type)
}
if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) {
change_video_l(indexs);
change_layout_l(indexs);
} 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) {
@ -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();
@ -164,7 +164,7 @@ void VideoBox::change_video_l(const QList<int> &indexs)
int flag = num - 1;
//首先隐藏所有通道
hide_video_all();
hide_all();
//添加大通道
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
//设置通道控件可见
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(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(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
@ -231,7 +231,7 @@ QWidgetList VideoBox::getWidgets() const
void VideoBox::setWidgets(QWidgetList widgets)
{
this->widgets = widgets;
this->videoCount = widgets.count();
this->maxCount = widgets.count();
}
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)
{
//先要过滤下是否满足最大通道数量/start从1开始
if (((index - 1) + (row * column)) > videoCount) {
if (((index - 1) + (row * column)) > maxCount) {
return;
}
@ -316,131 +316,168 @@ void VideoBox::initMenu(QMenu *menu)
}
}
void VideoBox::show_video_all()
void VideoBox::show_all()
{
//一般是从配置文件读取到了最后的通道画面类型进行设置
int type = 1;
if (videoType.startsWith("0_")) {
int index = videoType.split("_").last().toInt() - 1;
change_video_1(index);
Q_EMIT changeVideo(type, videoType, true);
} 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();
int index = layoutType.split("_").first().toInt() - 1;
//y开头的布局需要重置索引=0
if (layoutType.startsWith("y")) {
index = 0;
}
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));
widgets.at(i)->setVisible(false);
}
}
void VideoBox::show_video()
void VideoBox::change_layout()
{
//识别具体是哪个动作菜单触发的
QAction *action = (QAction *)sender();
//从弱属性取出值
int index = action->property("index").toInt() - 1;
int type = action->property("type").toInt();
QString videoType = action->property("flag").toString();
QString layoutType = action->property("flag").toString();
//只有当画面布局类型改变了才需要切换
if (this->videoType != videoType) {
this->videoType = videoType;
show_video(type, index);
if (this->layoutType != layoutType) {
this->layoutType = layoutType;
change_layout(type, index);
}
}
void VideoBox::show_video(int type, int index)
void VideoBox::change_layout(int type, int index)
{
//根据不同的父菜单类型执行对应的函数
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");
int row = list.at(0).toInt();
int column = list.at(1).toInt();
change_video_normal(index, row, column);
} else if (videoType == "y_1_2") {
change_video_y_1_2(index);
} else if (videoType == "y_1_3") {
change_video_y_1_3(index);
} else if (videoType == "y_1_9") {
change_video_y_1_9(index);
} else if (videoType == "y_1_10") {
change_video_y_1_10(index);
} else if (videoType == "y_1_12") {
change_video_y_1_12(index);
} else if (videoType == "y_1_16") {
change_video_y_1_16(index);
change_layout_normal(index, row, column);
//只有1个通道需要更改类型/方便外面区分当前是1通道
if (layoutType.endsWith("1x1")) {
type = 1;
}
} else if (layoutType == "y_1_2") {
change_layout_y_1_2(index);
} else if (layoutType == "y_1_3") {
change_layout_y_1_3(index);
} else if (layoutType == "y_1_5") {
change_layout_y_1_5(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) {
change_video_1(index);
change_layout_1(index);
} else if (type == 4) {
change_video_4(index);
change_layout_4(index);
} else if (type == 6) {
change_video_6(index);
change_layout_6(index);
} else if (type == 8) {
change_video_8(index);
change_layout_8(index);
} else if (type == 9) {
change_video_9(index);
change_layout_9(index);
} else if (type == 13) {
change_video_13(index);
change_layout_13(index);
} else if (type == 16) {
change_video_16(index);
change_layout_16(index);
} else if (type == 25) {
change_video_25(index);
change_layout_25(index);
} else if (type == 36) {
change_video_36(index);
change_layout_36(index);
} 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 + 1), 1, 0);
gridLayout->addWidget(widgets.at(index + 2), 1, 1);
gridLayout->addWidget(widgets.at(index + 1), 1, 0, 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 + 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 + 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);
private:
//最大通道数量
int maxCount;
//当前布局类型
QString layoutType;
//表格布局存放通道
QGridLayout *gridLayout;
//视频控件集合
QWidgetList widgets;
//通道数量
int videoCount;
//当前画面类型
QString videoType;
//主菜单子菜单文字标识
QString menuFlag;
QString actionFlag;
@ -58,20 +58,20 @@ private:
private:
//常规及异形通道布局
void change_video_normal(int index, int row, int column);
void change_video_custom(int index, int type);
void change_layout_normal(int index, int row, int column);
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表示上下左右环绕布局)
void change_video_l(const QList<int> &indexs);
void change_video_o(const QList<int> &indexs);
void change_layout_l(const QList<int> &indexs);
void change_layout_o(const QList<int> &indexs);
public:
//获取和设置当前画面类型
QString getVideoType() const;
void setVideoType(const QString &videoType);
//获取和设置当前布局类型
QString getLayoutType() const;
void setLayoutType(const QString &layoutType);
//获取和设置视频控件集合
QWidgetList getWidgets() const;
@ -94,36 +94,38 @@ public:
public Q_SLOTS:
//显示和隐藏所有通道
void show_video_all();
void hide_video_all();
void show_all();
void hide_all();
//菜单切换布局槽函数
void show_video();
void show_video(int type, int index);
void change_layout();
void change_layout(int type, int index);
//自定义布局通道切换函数
void change_video_y_1_2(int index);
void change_video_y_1_3(int index);
void change_video_y_1_9(int index);
void change_video_y_1_10(int index);
void change_video_y_1_12(int index);
void change_video_y_1_16(int index);
void change_layout_y_1_2(int index);
void change_layout_y_1_3(int index);
void change_layout_y_1_5(int index);
void change_layout_y_1_8(int index);
void change_layout_y_1_9(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_video_4(int index);
void change_video_6(int index);
void change_video_8(int index);
void change_video_9(int index);
void change_video_13(int index);
void change_video_16(int index);
void change_video_25(int index);
void change_video_36(int index);
void change_video_64(int index);
void change_layout_1(int index);
void change_layout_4(int index);
void change_layout_6(int index);
void change_layout_8(int index);
void change_layout_9(int index);
void change_layout_13(int index);
void change_layout_16(int index);
void change_layout_25(int index);
void change_layout_36(int index);
void change_layout_64(int index);
Q_SIGNALS:
//画面布局切换信号
void changeVideo(int type, const QString &videoType, bool videoMax);
void changeLayout(int type, const QString &layoutType, bool max);
};
#endif // VIDEOBOX_H

View File

@ -8,9 +8,9 @@
VideoBox::VideoBox(QObject *parent) : QObject(parent)
{
gridLayout = 0;
videoCount = 64;
videoType = "1_16";
maxCount = 64;
layoutType = "1_16";
gridLayout = NULL;
menuFlag = "画面";
actionFlag = "通道";
@ -20,10 +20,10 @@ VideoBox::VideoBox(QObject *parent) : QObject(parent)
//自定义x布局/按照行列数生成/可以通过appendtype函数添加其他类型
//1_2x4表示通道1开始2x4行列布局画面(相当于通道1-8按照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用于区分其他布局/可能有雷同
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/前面是通道开始的索引/后面是通道结束的索引
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("type", type);
@ -97,17 +97,17 @@ void VideoBox::addMenu(QMenu *menu, const QString &type)
//行列数一致的比如 2*2 3*3 4*4 5*5 等可以直接套用通用的公式
//按照这个函数还可以非常容易的拓展出 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 rowCount = 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) {
//添加到对应布局并设置可见
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;
@ -142,13 +142,13 @@ void VideoBox::change_video_custom(int index, int type)
}
if (type == 6 || type == 8 || type == 10 || type == 12 || type == 16) {
change_video_l(indexs);
change_layout_l(indexs);
} 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) {
@ -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();
@ -164,7 +164,7 @@ void VideoBox::change_video_l(const QList<int> &indexs)
int flag = num - 1;
//首先隐藏所有通道
hide_video_all();
hide_all();
//添加大通道
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
//设置通道控件可见
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(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(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
@ -231,7 +231,7 @@ QWidgetList VideoBox::getWidgets() const
void VideoBox::setWidgets(QWidgetList widgets)
{
this->widgets = widgets;
this->videoCount = widgets.count();
this->maxCount = widgets.count();
}
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)
{
//先要过滤下是否满足最大通道数量/start从1开始
if (((index - 1) + (row * column)) > videoCount) {
if (((index - 1) + (row * column)) > maxCount) {
return;
}
@ -316,131 +316,168 @@ void VideoBox::initMenu(QMenu *menu)
}
}
void VideoBox::show_video_all()
void VideoBox::show_all()
{
//一般是从配置文件读取到了最后的通道画面类型进行设置
int type = 1;
if (videoType.startsWith("0_")) {
int index = videoType.split("_").last().toInt() - 1;
change_video_1(index);
Q_EMIT changeVideo(type, videoType, true);
} 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();
int index = layoutType.split("_").first().toInt() - 1;
//y开头的布局需要重置索引=0
if (layoutType.startsWith("y")) {
index = 0;
}
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));
widgets.at(i)->setVisible(false);
}
}
void VideoBox::show_video()
void VideoBox::change_layout()
{
//识别具体是哪个动作菜单触发的
QAction *action = (QAction *)sender();
//从弱属性取出值
int index = action->property("index").toInt() - 1;
int type = action->property("type").toInt();
QString videoType = action->property("flag").toString();
QString layoutType = action->property("flag").toString();
//只有当画面布局类型改变了才需要切换
if (this->videoType != videoType) {
this->videoType = videoType;
show_video(type, index);
if (this->layoutType != layoutType) {
this->layoutType = layoutType;
change_layout(type, index);
}
}
void VideoBox::show_video(int type, int index)
void VideoBox::change_layout(int type, int index)
{
//根据不同的父菜单类型执行对应的函数
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");
int row = list.at(0).toInt();
int column = list.at(1).toInt();
change_video_normal(index, row, column);
} else if (videoType == "y_1_2") {
change_video_y_1_2(index);
} else if (videoType == "y_1_3") {
change_video_y_1_3(index);
} else if (videoType == "y_1_9") {
change_video_y_1_9(index);
} else if (videoType == "y_1_10") {
change_video_y_1_10(index);
} else if (videoType == "y_1_12") {
change_video_y_1_12(index);
} else if (videoType == "y_1_16") {
change_video_y_1_16(index);
change_layout_normal(index, row, column);
//只有1个通道需要更改类型/方便外面区分当前是1通道
if (layoutType.endsWith("1x1")) {
type = 1;
}
} else if (layoutType == "y_1_2") {
change_layout_y_1_2(index);
} else if (layoutType == "y_1_3") {
change_layout_y_1_3(index);
} else if (layoutType == "y_1_5") {
change_layout_y_1_5(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) {
change_video_1(index);
change_layout_1(index);
} else if (type == 4) {
change_video_4(index);
change_layout_4(index);
} else if (type == 6) {
change_video_6(index);
change_layout_6(index);
} else if (type == 8) {
change_video_8(index);
change_layout_8(index);
} else if (type == 9) {
change_video_9(index);
change_layout_9(index);
} else if (type == 13) {
change_video_13(index);
change_layout_13(index);
} else if (type == 16) {
change_video_16(index);
change_layout_16(index);
} else if (type == 25) {
change_video_25(index);
change_layout_25(index);
} else if (type == 36) {
change_video_36(index);
change_layout_36(index);
} 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 + 1), 1, 0);
gridLayout->addWidget(widgets.at(index + 2), 1, 1);
gridLayout->addWidget(widgets.at(index + 1), 1, 0, 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 + 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 + 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);
private:
//最大通道数量
int maxCount;
//当前布局类型
QString layoutType;
//表格布局存放通道
QGridLayout *gridLayout;
//视频控件集合
QWidgetList widgets;
//通道数量
int videoCount;
//当前画面类型
QString videoType;
//主菜单子菜单文字标识
QString menuFlag;
QString actionFlag;
@ -58,20 +58,20 @@ private:
private:
//常规及异形通道布局
void change_video_normal(int index, int row, int column);
void change_video_custom(int index, int type);
void change_layout_normal(int index, int row, int column);
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表示上下左右环绕布局)
void change_video_l(const QList<int> &indexs);
void change_video_o(const QList<int> &indexs);
void change_layout_l(const QList<int> &indexs);
void change_layout_o(const QList<int> &indexs);
public:
//获取和设置当前画面类型
QString getVideoType() const;
void setVideoType(const QString &videoType);
//获取和设置当前布局类型
QString getLayoutType() const;
void setLayoutType(const QString &layoutType);
//获取和设置视频控件集合
QWidgetList getWidgets() const;
@ -94,36 +94,38 @@ public:
public Q_SLOTS:
//显示和隐藏所有通道
void show_video_all();
void hide_video_all();
void show_all();
void hide_all();
//菜单切换布局槽函数
void show_video();
void show_video(int type, int index);
void change_layout();
void change_layout(int type, int index);
//自定义布局通道切换函数
void change_video_y_1_2(int index);
void change_video_y_1_3(int index);
void change_video_y_1_9(int index);
void change_video_y_1_10(int index);
void change_video_y_1_12(int index);
void change_video_y_1_16(int index);
void change_layout_y_1_2(int index);
void change_layout_y_1_3(int index);
void change_layout_y_1_5(int index);
void change_layout_y_1_8(int index);
void change_layout_y_1_9(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_video_4(int index);
void change_video_6(int index);
void change_video_8(int index);
void change_video_9(int index);
void change_video_13(int index);
void change_video_16(int index);
void change_video_25(int index);
void change_video_36(int index);
void change_video_64(int index);
void change_layout_1(int index);
void change_layout_4(int index);
void change_layout_6(int index);
void change_layout_8(int index);
void change_layout_9(int index);
void change_layout_13(int index);
void change_layout_16(int index);
void change_layout_25(int index);
void change_layout_36(int index);
void change_layout_64(int index);
Q_SIGNALS:
//画面布局切换信号
void changeVideo(int type, const QString &videoType, bool videoMax);
void changeLayout(int type, const QString &layoutType, bool max);
};
#endif // VIDEOBOX_H

View File

@ -14,7 +14,7 @@ VideoPanel::VideoPanel(QWidget *parent) : QWidget(parent)
this->initControl();
this->initForm();
this->initMenu();
QTimer::singleShot(1000, this, SLOT(play_video_all()));
QTimer::singleShot(1000, this, SLOT(playAll()));
}
bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
@ -24,12 +24,12 @@ bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
QLabel *widget = (QLabel *) watched;
if (!videoMax) {
videoMax = true;
videoBox->hide_video_all();
videoBox->hide_all();
gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true);
} else {
videoMax = false;
videoBox->show_video_all();
videoBox->show_all();
}
widget->setFocus();
@ -74,7 +74,7 @@ void VideoPanel::initForm()
videoMax = false;
videoCount = 64;
videoType = "1_16";
layoutType = "1_16";
for (int i = 0; i < videoCount; ++i) {
QLabel *widget = new QLabel;
@ -107,17 +107,17 @@ void VideoPanel::initMenu()
videoMenu->addSeparator();
//直接通过文字的形式添加子菜单
videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one()));
videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all()));
videoMenu->addAction("截图当前视频", this, SLOT(snapOne()));
videoMenu->addAction("截图所有视频", this, SLOT(snapAll()));
videoMenu->addSeparator();
//实例化通道布局类
videoBox = new VideoBox(this);
videoBox->initMenu(videoMenu);
videoBox->setVideoType(videoType);
videoBox->setLayoutType(layoutType);
videoBox->setLayout(gridLayout);
videoBox->setWidgets(widgets);
videoBox->show_video_all();
videoBox->show_all();
}
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:
bool videoMax; //是否最大化
int videoCount; //视频通道个
QString videoType; //当前画面类型
int videoCount; //最大通道
QString layoutType; //当前画面类型
QMenu *videoMenu; //右键菜单
QAction *actionFull; //全屏动作
QAction *actionPoll; //轮询动作
@ -56,9 +56,9 @@ private slots:
void poll();
private slots:
void play_video_all();
void snapshot_video_one();
void snapshot_video_all();
void playAll();
void snapOne();
void snapAll();
Q_SIGNALS:
//全屏切换信号