diff --git a/devicesizetable/devicesizetable.cpp b/devicesizetable/devicesizetable.cpp index b25413b..416b8d2 100644 --- a/devicesizetable/devicesizetable.cpp +++ b/devicesizetable/devicesizetable.cpp @@ -53,8 +53,8 @@ DeviceSizeTable::DeviceSizeTable(QWidget *parent) : QTableWidget(parent) this->setSelectionMode(QAbstractItemView::SingleSelection); this->verticalHeader()->setVisible(true); this->horizontalHeader()->setStretchLastSection(true); - //QMetaObject::invokeMethod(this, "load"); - QTimer::singleShot(10, this, SLOT(load())); + QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection); + //QTimer::singleShot(10, this, SLOT(load())); } QColor DeviceSizeTable::getBgColor() const diff --git a/docs/video_system/index.html b/docs/video_system/index.html index cb97387..91cfdaf 100644 --- a/docs/video_system/index.html +++ b/docs/video_system/index.html @@ -134,7 +134,7 @@ a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; .md-fn-count::after { content: "."; } code, pre, samp, tt { font-family: var(--monospace); } kbd { margin: 0px 0.1em; padding: 0.1em 0.6em; font-size: 0.8em; color: rgb(36, 39, 41); background: rgb(255, 255, 255); border: 1px solid rgb(173, 179, 185); border-radius: 3px; box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset; white-space: nowrap; vertical-align: middle; } -.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: var(--monospace); } +.md-comment { color: rgb(162, 127, 3); opacity: 0.6; font-family: var(--monospace); } code { text-align: left; vertical-align: initial; } a.md-print-anchor { white-space: pre !important; border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; } .os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; } @@ -674,11 +674,11 @@ header, .context-menu, .megamenu-content, footer{
使用说明
写法举例
V20210922
V20210705
V20210603
V20210425
V20210403
V20210322
V20210305
V20201212
V20201108
20200828
V20200730
V20200620
V20191105
+}
使用说明
写法举例
V20211101
V20211005
V20210922
V20210705
V20210603
V20210425
V20210403
V20210322
V20210305
V20201212
V20201108
20200828
V20200730
V20200620
V20191105
系统默认开启了自动登录,可以在系统设置中将自动登录按钮关闭即可,可以在用户登录界面勾选记住密码和自动登录复选框,如果勾选了记住密码,则下次弹出的登录窗体会自动把最后一次的密码填进去,如果勾选了自动登录,则直接以上一次的用户登录到系统。
如果开启了自动登录机制,在单击右上角的关闭按钮,会弹出用户退出窗体,需要输入密码才能退出,也可以在代码中屏蔽掉自动登录的判断,这样任何时候关闭系统都会弹出窗体要求输入密码来退出。用户登录和退出内置了超级密码 a ,在记不住密码或者密码丢失的时候使用。
@@ -702,7 +702,7 @@ header, .context-menu, .megamenu-content, footer{ 设备控制部分,目前可以获取和设置图片参数、手动校时、重启设备等,上面那一堆复选框对应功能需要用厂家sdk去实现,后期可能会增加一些onvif能够处理的功能。和云台控制操作一样,操作前也是需要选中某个通道,然后才是对选中的通道进行设备控制,比如图片参数中的明亮度、对比度、饱和度。
本系统默认支持海康摄像机的报警事件订阅,默认已经订阅,如果摄像机已经开启了报警事件的话,默认一般是关闭的,比如摄像机后面的开关量输入报警接口,需要web页面进去设置开启。报警订阅走的是onvif协议,默认测试过海康的摄像机,其余摄像机有些没有测试成功,后期会详细查下原因并改进,会持续更新完善。
本系统中将视频显示这块都封装成了一个控件,每个视频控件都有自己独立的悬浮条,悬浮条的位置可以自行修改两三行代码调整,默认悬浮条在顶部,自动拉伸填充显示,你也可以改成左侧右侧等位置显示,高度可调。悬浮条是一排按钮组成,具体按钮什么名称标识符和功能,可以自定义,控件的封装只是默认放了一排按钮,除了关闭按钮实现了功能外,其余都是信号的形式发出去的,具体操作由程序员本身根据不同的厂家来定义不同的功能。
- 视频控件已经将OSD标签封装好了,默认提供两路OSD设置,每个OSD都可以设置是否启用、位置、文字内容、文字颜色、图片、文字大小等,这些设置都提供了友好的接口设置。
在frmvideopanel.cpp文件中有设置示例,默认注释的,参数含义如下:
xxxxxxxxxx
141enum OSDFormat {
2 OSDFormat_Text = 0, //文本
3 OSDFormat_Date = 1, //日期
4 OSDFormat_Time = 2, //时间
5 OSDFormat_DateTime = 3, //日期时间
6 OSDFormat_Image = 4 //图片
7};
8
+ 视频控件已经将OSD标签封装好了,默认提供两路OSD设置,每个OSD都可以设置是否启用、位置、文字内容、文字颜色、图片、文字大小等,这些设置都提供了友好的接口设置。在frmvideopanel.cpp文件中有设置示例,默认注释的,参数含义如下:
- 设置标签可见:setOSD1Visible
- 设置文字大小:setOSD1FontSize
- 设置文本文字:setOSD1Text
- 设置文字颜色:setOSD1Color
- 设置标签格式:setOSD1Format
- 设置标签位置:setOSD1Position
x1enum OSDFormat {
2 OSDFormat_Text = 0, //文本
3 OSDFormat_Date = 1, //日期
4 OSDFormat_Time = 2, //时间
5 OSDFormat_DateTime = 3, //日期时间
6 OSDFormat_Image = 4 //图片
7};
8
9enum OSDPosition {
10 OSDPosition_Left_Top = 0, //左上角
11 OSDPosition_Left_Bottom = 1, //左下角
12 OSDPosition_Right_Top = 2, //右上角
13 OSDPosition_Right_Bottom = 3 //右下角
14};
3 视频回放
视频回放中有多个子模块,分别是不同的含义:
- 本地回放:回放存储在本地电脑的视频文件。
- 远程回放:通过sdk方式回放NVR上的存储录像(暂未实现,每个厂家不一样)。
- 设备播放:通用的rtsp取流形式的播放实时视频和回放录像文件。
- 图片回放:查找对应文件夹下的所有通道图片,按照设定的间隔回复,类似视频效果,一般用在存储一堆图片序列的应用场景中。
- 视频上传:将查询的本地存储的视频文件上传到云端服务器。类似于将视频文件存储到服务器上,需要手动填写服务器地址和端口。
3.1 本地回放
3.1.1 视频查询
本地回放模块主要用来回放存储在本地电脑上的视频,先从右侧选择要回放的通道,默认是所有通道,然后选择类型:存储视频还是报警视频,默认选择存储视频(目前也只有存储的视频,没有报警视频,报警视频的规则还没定好,一般都是买过去自己定义),然后选择要查询的开始时间和结束时间,单击查询按钮,会自动列出来,双击对应的视频文件名称就会播放,除了查询按钮,其余按钮均没有实现具体功能。
3.1.2 存储规则
- 默认存储主目录 video_normal。
- 主目录下按照日期目录存放 比如 2021-04-07 2021-04-08。
- 日期目录下是单个的视频文件 比如 Ch1_2021-04-07-14-08-11.mp4。
- 拓展功能可以存储对应的数据文件比如经纬度数据和视频文件一个目录 名称一样 拓展名可以是 txt。
3.1.3 视频下载
视频下载是将查询出来的视频文件,按照勾选了的文件保存到选择的目录中。
3.2 远程回放
diff --git a/savelog/savelog.cpp b/savelog/savelog.cpp
index 1059074..7832988 100644
--- a/savelog/savelog.cpp
+++ b/savelog/savelog.cpp
@@ -237,7 +237,6 @@ void SaveLog::save(const QString &content)
//用文本流的输出速度更快
QTextStream stream(file);
- stream.setCodec("utf-8");
stream << content << "\n";
}
}
diff --git a/videobox/frmvideobox.cpp b/videobox/frmvideobox.cpp
new file mode 100644
index 0000000..206db09
--- /dev/null
+++ b/videobox/frmvideobox.cpp
@@ -0,0 +1,105 @@
+#pragma execution_character_set("utf-8")
+#include "frmvideobox.h"
+#include "ui_frmvideobox.h"
+#include "videobox.h"
+#include "qapplication.h"
+#include "qevent.h"
+#include "qlabel.h"
+#include "qmenu.h"
+#include "qcursor.h"
+#include "qlist.h"
+#include "qdebug.h"
+
+frmVideoBox::frmVideoBox(QWidget *parent) : QWidget(parent), ui(new Ui::frmVideoBox)
+{
+ ui->setupUi(this);
+ this->initForm();
+}
+
+frmVideoBox::~frmVideoBox()
+{
+ delete ui;
+}
+
+bool frmVideoBox::eventFilter(QObject *watched, QEvent *event)
+{
+ if (event->type() == QEvent::MouseButtonDblClick) {
+ //双击最大化再次双击还原
+ QLabel *widget = (QLabel *) watched;
+ if (!max) {
+ max = true;
+ box->hide_video_all();
+ ui->gridLayout->addWidget(widget, 0, 0);
+ widget->setVisible(true);
+ } else {
+ max = false;
+ box->show_video_all();
+ }
+
+ return true;
+ } else if (event->type() == QEvent::MouseButtonPress) {
+ //鼠标右键的地方弹出菜单
+ if (qApp->mouseButtons() == Qt::RightButton) {
+ menu->exec(QCursor::pos());
+ }
+ }
+
+ return QWidget::eventFilter(watched, event);
+}
+
+void frmVideoBox::initForm()
+{
+ max = false;
+ //安装事件过滤器
+ this->installEventFilter(this);
+
+ //实例化子对象
+ QWidgetList widgets;
+ for (int i = 0; i < 64; ++i) {
+ //这里用QLabel做演示可以改成自己的窗体类比如视频监控窗体
+ QLabel *label = new QLabel;
+ label->installEventFilter(this);
+ label->setFrameShape(QLabel::Box);
+ label->setAlignment(Qt::AlignCenter);
+ label->setText(QString("通道 %1").arg(i + 1));
+ widgets << label;
+ }
+
+ //实例化盒子
+ box = new VideoBox(this);
+ //关联信号槽
+ connect(box, SIGNAL(changeVideo(int, QString, bool)), this, SLOT(changeVideo(int, QString, bool)));
+ //可以改成 1_4 5_8 1_36 等
+ box->setVideoType("1_16");
+ box->setLayout(ui->gridLayout);
+ box->setWidgets(widgets);
+ box->setMenuFlag("排列");
+ box->setActionFlag("监控");
+ box->show_video_all();
+
+ //实例化菜单
+ menu = new QMenu(this);
+ //先安排自己的菜单
+ //这里关联到一个槽函数处理,也可以关联到不同的槽函数
+ menu->addAction("切换全屏模式", this, SLOT(doAction()));
+ menu->addAction("启动轮询视频", this, SLOT(doAction()));
+ menu->addSeparator();
+
+ //把菜单加到盒子上,并控制布局切换菜单是否可用(默认9个布局切换菜单)
+ QList enable;
+ enable << true << true << true << true << true << true << true << true << true;
+ box->initMenu(menu, enable);
+}
+
+void frmVideoBox::doAction()
+{
+ //判断是哪个动作触发的
+ QAction *action = (QAction *)sender();
+ ui->label->setText(QString("触发了菜单: %1").arg(action->text()));
+}
+
+void frmVideoBox::changeVideo(int type, const QString &videoType, bool videoMax)
+{
+ QString info = QString("主菜单:%1 子菜单:%2").arg(type).arg(videoType);
+ ui->label->setText(info);
+}
diff --git a/videobox/frmvideobox.h b/videobox/frmvideobox.h
new file mode 100644
index 0000000..93a46f2
--- /dev/null
+++ b/videobox/frmvideobox.h
@@ -0,0 +1,38 @@
+#ifndef FRMVIDEOBOX_H
+#define FRMVIDEOBOX_H
+
+#include
+class QMenu;
+class VideoBox;
+
+namespace Ui {
+class frmVideoBox;
+}
+
+class frmVideoBox : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit frmVideoBox(QWidget *parent = 0);
+ ~frmVideoBox();
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event);
+
+private:
+ Ui::frmVideoBox *ui;
+
+ bool max;
+ QMenu *menu;
+ VideoBox *box;
+
+private slots:
+ void initForm();
+ void doAction();
+
+ //画面布局切换信号
+ void changeVideo(int type, const QString &videoType, bool videoMax);
+};
+
+#endif // FRMVIDEOBOX_H
diff --git a/videobox/frmvideobox.ui b/videobox/frmvideobox.ui
new file mode 100644
index 0000000..40f6544
--- /dev/null
+++ b/videobox/frmvideobox.ui
@@ -0,0 +1,43 @@
+
+
+ frmVideoBox
+
+
+
+ 0
+ 0
+ 800
+ 600
+
+
+
+ Form
+
+
+ -
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QFrame::Box
+
+
+ QFrame::Sunken
+
+
+
+
+
+
+
+
+
+
+
diff --git a/videobox/main.cpp b/videobox/main.cpp
new file mode 100644
index 0000000..283922d
--- /dev/null
+++ b/videobox/main.cpp
@@ -0,0 +1,32 @@
+#pragma execution_character_set("utf-8")
+
+#include "frmvideobox.h"
+#include
+#include
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ a.setFont(QFont("Microsoft Yahei", 9));
+
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
+#if _MSC_VER
+ QTextCodec *codec = QTextCodec::codecForName("gbk");
+#else
+ QTextCodec *codec = QTextCodec::codecForName("utf-8");
+#endif
+ QTextCodec::setCodecForLocale(codec);
+ QTextCodec::setCodecForCStrings(codec);
+ QTextCodec::setCodecForTr(codec);
+#else
+ QTextCodec *codec = QTextCodec::codecForName("utf-8");
+ QTextCodec::setCodecForLocale(codec);
+#endif
+
+ frmVideoBox w;
+ w.setWindowTitle("视频监控布局");
+ w.resize(800, 600);
+ w.show();
+
+ return a.exec();
+}
diff --git a/videobox/videobox.cpp b/videobox/videobox.cpp
new file mode 100644
index 0000000..375ac91
--- /dev/null
+++ b/videobox/videobox.cpp
@@ -0,0 +1,381 @@
+#pragma execution_character_set("utf-8")
+
+#include "videobox.h"
+#include "qmenu.h"
+#include "qaction.h"
+#include "qgridlayout.h"
+#include "qdebug.h"
+
+VideoBox::VideoBox(QObject *parent) : QObject(parent)
+{
+ gridLayout = 0;
+ videoCount = 64;
+ videoType = "1_16";
+
+ menuFlag = "画面";
+ actionFlag = "通道";
+
+ //通过这里设置好数据下面只需要循环添加和判断就行
+ //灵活性大大增强,只需要这里改动下就行
+ types.insert(4, QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36");
+ types.insert(6, QStringList() << "1_6" << "7_12" << "13_18" << "19_24" << "25_30" << "31_36");
+ types.insert(8, QStringList() << "1_8" << "9_16" << "17_24" << "25_32" << "33_40" << "41_48" << "49_57" << "57_64");
+ types.insert(9, QStringList() << "1_9" << "9_17" << "18_26" << "27_35" << "36_42" << "43_50" << "51_59");
+ types.insert(13, QStringList() << "1_13" << "14_26" << "27_39" << "40_52" << "52_64");
+ types.insert(16, QStringList() << "1_16" << "17_32" << "33_48" << "49_64");
+ types.insert(25, QStringList() << "1_25");
+ types.insert(36, QStringList() << "1_36");
+ types.insert(64, QStringList() << "1_64");
+}
+
+void VideoBox::addMenu(QMenu *menu, int type)
+{
+ //父菜单文字
+ QString name = QString("切换到%1%2").arg(type).arg(menuFlag);
+ //链表中取出该布局大类下的小类集合
+ QStringList flags = types.value(type);
+
+ //超过一个子元素则添加子菜单
+ QMenu *menuSub;
+ if (flags.count() > 1) {
+ menuSub = menu->addMenu(name);
+ } else {
+ menuSub = menu;
+ }
+
+ foreach (QString flag, flags) {
+ QStringList list = flag.split("_");
+ QString start = list.at(0);
+ QString end = list.at(1);
+
+ //对应菜单文本
+ QString text = QString("%1%2-%1%3").arg(actionFlag).arg(start).arg(end);
+ if (flags.count() == 1) {
+ text = name;
+ }
+
+ //添加菜单动作
+ QAction *action = menuSub->addAction(text, this, SLOT(show_video()));
+ //设置弱属性传入大类和子类布局标识等
+ action->setProperty("index", start);
+ action->setProperty("type", type);
+ action->setProperty("flag", flag);
+ }
+}
+
+void VideoBox::setVideoType(const QString &videoType)
+{
+ this->videoType = videoType;
+}
+
+void VideoBox::setLayout(QGridLayout *gridLayout)
+{
+ this->gridLayout = gridLayout;
+}
+
+void VideoBox::setWidgets(QWidgetList widgets)
+{
+ this->widgets = widgets;
+ this->videoCount = widgets.count();
+}
+
+void VideoBox::setMenuFlag(const QString &menuFlag)
+{
+ this->menuFlag = menuFlag;
+}
+
+void VideoBox::setActionFlag(const QString &actionFlag)
+{
+ this->actionFlag = actionFlag;
+}
+
+void VideoBox::setTypes(const QMap &types)
+{
+ this->types = types;
+}
+
+void VideoBox::initMenu(QMenu *menu, const QList &enable)
+{
+ //通过菜单是否可见设置每个菜单可见与否
+ if (enable.count() < 9) {
+ return;
+ }
+
+ if (enable.at(0)) {
+ addMenu(menu, 4);
+ }
+ if (enable.at(1)) {
+ addMenu(menu, 6);
+ }
+ if (enable.at(2)) {
+ addMenu(menu, 8);
+ }
+ if (enable.at(3)) {
+ addMenu(menu, 9);
+ }
+ if (enable.at(4)) {
+ addMenu(menu, 13);
+ }
+ if (enable.at(5)) {
+ addMenu(menu, 16);
+ }
+ if (enable.at(6)) {
+ addMenu(menu, 25);
+ }
+ if (enable.at(7)) {
+ addMenu(menu, 36);
+ }
+ if (enable.at(8)) {
+ addMenu(menu, 64);
+ }
+}
+
+void VideoBox::show_video(int type, int index)
+{
+ //根据不同的父菜单类型执行对应的函数
+ if (type == 4) {
+ change_video_4(index);
+ } else if (type == 6) {
+ change_video_6(index);
+ } else if (type == 8) {
+ change_video_8(index);
+ } else if (type == 9) {
+ change_video_9(index);
+ } else if (type == 13) {
+ change_video_13(index);
+ } else if (type == 16) {
+ change_video_16(index);
+ } else if (type == 25) {
+ change_video_25(index);
+ } else if (type == 36) {
+ change_video_36(index);
+ } else if (type == 64) {
+ change_video_64(index);
+ }
+
+ emit changeVideo(type, videoType, false);
+}
+
+void VideoBox::show_video()
+{
+ //识别具体是哪个动作菜单触发的
+ QAction *action = (QAction *)sender();
+ //从弱属性取出值
+ int index = action->property("index").toInt() - 1;
+ int type = action->property("type").toInt();
+ QString videoType = action->property("flag").toString();
+
+ //只有当画面布局类型改变了才需要切换
+ if (this->videoType != videoType) {
+ this->videoType = videoType;
+ show_video(type, index);
+ }
+}
+
+void VideoBox::show_video_all()
+{
+ //一般是从配置文件读取到了最后的通道画面类型进行设置
+ int type = 1;
+ if (videoType.startsWith("0_")) {
+ int index = videoType.split("_").last().toInt() - 1;
+ change_video_1(index);
+ emit changeVideo(type, videoType, true);
+ } else {
+ int index = videoType.split("_").first().toInt() - 1;
+ QMap::iterator iter = types.begin();
+ while (iter != types.end()) {
+ QStringList flags = iter.value();
+ if (flags.contains(videoType)) {
+ type = iter.key();
+ show_video(type, index);
+ break;
+ }
+ iter++;
+ }
+ }
+}
+
+void VideoBox::hide_video_all()
+{
+ for (int i = 0; i < videoCount; ++i) {
+ gridLayout->removeWidget(widgets.at(i));
+ widgets.at(i)->setVisible(false);
+ }
+}
+
+void VideoBox::change_video_normal(int index, int flag)
+{
+ //首先隐藏所有通道
+ hide_video_all();
+ int count = 0;
+ int row = 0;
+ int column = 0;
+
+ //行列数一致的比如 2*2 3*4 4*4 5*5 等可以直接套用通用的公式
+ //按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面
+ for (int i = 0; i < videoCount; i++) {
+ if (i >= index) {
+ //添加到对应布局并设置可见
+ gridLayout->addWidget(widgets.at(i), row, column);
+ widgets.at(i)->setVisible(true);
+
+ count++;
+ column++;
+ if (column == flag) {
+ row++;
+ column = 0;
+ }
+ }
+
+ if (count == (flag * flag)) {
+ break;
+ }
+ }
+}
+
+void VideoBox::change_video_custom(int index, int type)
+{
+ //从开始索引开始往后衍生多少个通道
+ QList indexs;
+ for (int i = index; i < (index + type); ++i) {
+ indexs << i;
+ }
+
+ if (type == 6) {
+ change_video_6(indexs);
+ } else if (type == 8) {
+ change_video_8(indexs);
+ } else if (type == 13) {
+ change_video_13(indexs);
+ }
+}
+
+void VideoBox::change_video_6(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 6) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 2, 2);
+ gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 2, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_8(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 8) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 3, 3);
+ gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 3, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 3, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(6)), 3, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(7)), 3, 0, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_13(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 13) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ 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(2)), 0, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 0, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 1, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(6)), 1, 1, 2, 2);
+ gridLayout->addWidget(widgets.at(indexs.at(7)), 1, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(8)), 2, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(9)), 3, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(10)), 3, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_1(int index)
+{
+ //首先隐藏所有通道
+ hide_video_all();
+ //添加通道到布局
+ gridLayout->addWidget(widgets.at(index), 0, 0);
+ //设置可见
+ widgets.at(index)->setVisible(true);
+}
+
+void VideoBox::change_video_4(int index)
+{
+ change_video_normal(index, 2);
+}
+
+void VideoBox::change_video_6(int index)
+{
+ change_video_custom(index, 6);
+}
+
+void VideoBox::change_video_8(int index)
+{
+ change_video_custom(index, 8);
+}
+
+void VideoBox::change_video_9(int index)
+{
+ change_video_normal(index, 3);
+}
+
+void VideoBox::change_video_13(int index)
+{
+ change_video_custom(index, 13);
+}
+
+void VideoBox::change_video_16(int index)
+{
+ change_video_normal(index, 4);
+}
+
+void VideoBox::change_video_25(int index)
+{
+ change_video_normal(index, 5);
+}
+
+void VideoBox::change_video_36(int index)
+{
+ change_video_normal(index, 6);
+}
+
+void VideoBox::change_video_64(int index)
+{
+ change_video_normal(index, 8);
+}
diff --git a/videobox/videobox.h b/videobox/videobox.h
new file mode 100644
index 0000000..6d6474c
--- /dev/null
+++ b/videobox/videobox.h
@@ -0,0 +1,106 @@
+#ifndef VIDEOBOX_H
+#define VIDEOBOX_H
+
+/**
+ * 监控画面切换控件 作者:feiyangqingyun(QQ:517216493) 2021-11-08
+ * 1. 将所有通道切换处理全部集中到一个类。
+ * 2. 通用整数倍数布局切换函数,可方便拓展到100、255通道等。
+ * 3. 通用异形布局切换函数,可以参考进行自定义异形布局。
+ * 4. 通道布局切换发出信号通知。
+ * 5. 可控每种布局切换菜单是否启用。
+ * 6. 支持自定义子菜单布局内容。
+ * 7. 支持设置对应的菜单标识比如默认的通道字样改成设备。
+ */
+
+#include
+#include
+#include
+
+class QMenu;
+class QWidget;
+class QGridLayout;
+
+#ifdef quc
+class Q_DECL_EXPORT VideoBox : public QObject
+#else
+class VideoBox : public QObject
+#endif
+
+{
+ Q_OBJECT
+
+public:
+ explicit VideoBox(QObject *parent = 0);
+
+private:
+ //表格布局存放通道
+ QGridLayout *gridLayout;
+ //视频控件集合
+ QWidgetList widgets;
+
+ //通道数量
+ int videoCount;
+ //当前画面类型
+ QString videoType;
+
+ //主菜单子菜单文字标识
+ QString menuFlag;
+ QString actionFlag;
+
+ //布局方案标识集合
+ QMap types;
+ void addMenu(QMenu *menu, int type);
+
+public Q_SLOTS:
+ //设置当前画面类型
+ void setVideoType(const QString &videoType);
+ //设置表格布局
+ void setLayout(QGridLayout *gridLayout);
+ //设置视频控件集合
+ void setWidgets(QWidgetList widgets);
+
+ //设置主菜单子菜单文字标识
+ void setMenuFlag(const QString &menuFlag);
+ void setActionFlag(const QString &actionFlag);
+
+ //设置子菜单类型集合
+ void setTypes(const QMap &types);
+ //初始化菜单
+ void initMenu(QMenu *menu, const QList &enable);
+
+ //通用设置函数
+ void show_video(int type, int index);
+ //菜单切换布局槽函数
+ void show_video();
+
+ //显示和隐藏所有通道
+ void show_video_all();
+ void hide_video_all();
+
+ //常规及异形通道布局
+ void change_video_normal(int index, int flag);
+ void change_video_custom(int index, int type);
+
+ //异形布局
+ void change_video_6(const QList &indexs);
+ void change_video_8(const QList &indexs);
+ void change_video_13(const QList &indexs);
+
+ //具体通道切换函数
+ 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);
+
+Q_SIGNALS:
+ //画面布局切换信号
+ void changeVideo(int type, const QString &videoType, bool videoMax);
+};
+
+#endif // VIDEOBOX_H
diff --git a/videobox/videobox.pro b/videobox/videobox.pro
new file mode 100644
index 0000000..49900a5
--- /dev/null
+++ b/videobox/videobox.pro
@@ -0,0 +1,17 @@
+QT += core gui
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
+
+TARGET = videobox
+TEMPLATE = app
+DESTDIR = $$PWD/../bin
+CONFIG += warn_off
+
+SOURCES += main.cpp
+SOURCES += frmvideobox.cpp
+SOURCES += videobox.cpp
+
+HEADERS += frmvideobox.h
+HEADERS += videobox.h
+
+FORMS += frmvideobox.ui
diff --git a/videopanel/frmvideopanel.ui b/videopanel/frmvideopanel.ui
index 8e10325..35d7b1d 100644
--- a/videopanel/frmvideopanel.ui
+++ b/videopanel/frmvideopanel.ui
@@ -6,8 +6,8 @@
0
0
- 400
- 300
+ 800
+ 600
diff --git a/videopanel/main.cpp b/videopanel/main.cpp
index bb45590..49f388b 100644
--- a/videopanel/main.cpp
+++ b/videopanel/main.cpp
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9));
-#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
diff --git a/videopanel/videobox.cpp b/videopanel/videobox.cpp
new file mode 100644
index 0000000..375ac91
--- /dev/null
+++ b/videopanel/videobox.cpp
@@ -0,0 +1,381 @@
+#pragma execution_character_set("utf-8")
+
+#include "videobox.h"
+#include "qmenu.h"
+#include "qaction.h"
+#include "qgridlayout.h"
+#include "qdebug.h"
+
+VideoBox::VideoBox(QObject *parent) : QObject(parent)
+{
+ gridLayout = 0;
+ videoCount = 64;
+ videoType = "1_16";
+
+ menuFlag = "画面";
+ actionFlag = "通道";
+
+ //通过这里设置好数据下面只需要循环添加和判断就行
+ //灵活性大大增强,只需要这里改动下就行
+ types.insert(4, QStringList() << "1_4" << "5_8" << "9_12" << "13_16" << "17_20" << "21_24" << "25_28" << "29_32" << "33_36");
+ types.insert(6, QStringList() << "1_6" << "7_12" << "13_18" << "19_24" << "25_30" << "31_36");
+ types.insert(8, QStringList() << "1_8" << "9_16" << "17_24" << "25_32" << "33_40" << "41_48" << "49_57" << "57_64");
+ types.insert(9, QStringList() << "1_9" << "9_17" << "18_26" << "27_35" << "36_42" << "43_50" << "51_59");
+ types.insert(13, QStringList() << "1_13" << "14_26" << "27_39" << "40_52" << "52_64");
+ types.insert(16, QStringList() << "1_16" << "17_32" << "33_48" << "49_64");
+ types.insert(25, QStringList() << "1_25");
+ types.insert(36, QStringList() << "1_36");
+ types.insert(64, QStringList() << "1_64");
+}
+
+void VideoBox::addMenu(QMenu *menu, int type)
+{
+ //父菜单文字
+ QString name = QString("切换到%1%2").arg(type).arg(menuFlag);
+ //链表中取出该布局大类下的小类集合
+ QStringList flags = types.value(type);
+
+ //超过一个子元素则添加子菜单
+ QMenu *menuSub;
+ if (flags.count() > 1) {
+ menuSub = menu->addMenu(name);
+ } else {
+ menuSub = menu;
+ }
+
+ foreach (QString flag, flags) {
+ QStringList list = flag.split("_");
+ QString start = list.at(0);
+ QString end = list.at(1);
+
+ //对应菜单文本
+ QString text = QString("%1%2-%1%3").arg(actionFlag).arg(start).arg(end);
+ if (flags.count() == 1) {
+ text = name;
+ }
+
+ //添加菜单动作
+ QAction *action = menuSub->addAction(text, this, SLOT(show_video()));
+ //设置弱属性传入大类和子类布局标识等
+ action->setProperty("index", start);
+ action->setProperty("type", type);
+ action->setProperty("flag", flag);
+ }
+}
+
+void VideoBox::setVideoType(const QString &videoType)
+{
+ this->videoType = videoType;
+}
+
+void VideoBox::setLayout(QGridLayout *gridLayout)
+{
+ this->gridLayout = gridLayout;
+}
+
+void VideoBox::setWidgets(QWidgetList widgets)
+{
+ this->widgets = widgets;
+ this->videoCount = widgets.count();
+}
+
+void VideoBox::setMenuFlag(const QString &menuFlag)
+{
+ this->menuFlag = menuFlag;
+}
+
+void VideoBox::setActionFlag(const QString &actionFlag)
+{
+ this->actionFlag = actionFlag;
+}
+
+void VideoBox::setTypes(const QMap &types)
+{
+ this->types = types;
+}
+
+void VideoBox::initMenu(QMenu *menu, const QList &enable)
+{
+ //通过菜单是否可见设置每个菜单可见与否
+ if (enable.count() < 9) {
+ return;
+ }
+
+ if (enable.at(0)) {
+ addMenu(menu, 4);
+ }
+ if (enable.at(1)) {
+ addMenu(menu, 6);
+ }
+ if (enable.at(2)) {
+ addMenu(menu, 8);
+ }
+ if (enable.at(3)) {
+ addMenu(menu, 9);
+ }
+ if (enable.at(4)) {
+ addMenu(menu, 13);
+ }
+ if (enable.at(5)) {
+ addMenu(menu, 16);
+ }
+ if (enable.at(6)) {
+ addMenu(menu, 25);
+ }
+ if (enable.at(7)) {
+ addMenu(menu, 36);
+ }
+ if (enable.at(8)) {
+ addMenu(menu, 64);
+ }
+}
+
+void VideoBox::show_video(int type, int index)
+{
+ //根据不同的父菜单类型执行对应的函数
+ if (type == 4) {
+ change_video_4(index);
+ } else if (type == 6) {
+ change_video_6(index);
+ } else if (type == 8) {
+ change_video_8(index);
+ } else if (type == 9) {
+ change_video_9(index);
+ } else if (type == 13) {
+ change_video_13(index);
+ } else if (type == 16) {
+ change_video_16(index);
+ } else if (type == 25) {
+ change_video_25(index);
+ } else if (type == 36) {
+ change_video_36(index);
+ } else if (type == 64) {
+ change_video_64(index);
+ }
+
+ emit changeVideo(type, videoType, false);
+}
+
+void VideoBox::show_video()
+{
+ //识别具体是哪个动作菜单触发的
+ QAction *action = (QAction *)sender();
+ //从弱属性取出值
+ int index = action->property("index").toInt() - 1;
+ int type = action->property("type").toInt();
+ QString videoType = action->property("flag").toString();
+
+ //只有当画面布局类型改变了才需要切换
+ if (this->videoType != videoType) {
+ this->videoType = videoType;
+ show_video(type, index);
+ }
+}
+
+void VideoBox::show_video_all()
+{
+ //一般是从配置文件读取到了最后的通道画面类型进行设置
+ int type = 1;
+ if (videoType.startsWith("0_")) {
+ int index = videoType.split("_").last().toInt() - 1;
+ change_video_1(index);
+ emit changeVideo(type, videoType, true);
+ } else {
+ int index = videoType.split("_").first().toInt() - 1;
+ QMap::iterator iter = types.begin();
+ while (iter != types.end()) {
+ QStringList flags = iter.value();
+ if (flags.contains(videoType)) {
+ type = iter.key();
+ show_video(type, index);
+ break;
+ }
+ iter++;
+ }
+ }
+}
+
+void VideoBox::hide_video_all()
+{
+ for (int i = 0; i < videoCount; ++i) {
+ gridLayout->removeWidget(widgets.at(i));
+ widgets.at(i)->setVisible(false);
+ }
+}
+
+void VideoBox::change_video_normal(int index, int flag)
+{
+ //首先隐藏所有通道
+ hide_video_all();
+ int count = 0;
+ int row = 0;
+ int column = 0;
+
+ //行列数一致的比如 2*2 3*4 4*4 5*5 等可以直接套用通用的公式
+ //按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面
+ for (int i = 0; i < videoCount; i++) {
+ if (i >= index) {
+ //添加到对应布局并设置可见
+ gridLayout->addWidget(widgets.at(i), row, column);
+ widgets.at(i)->setVisible(true);
+
+ count++;
+ column++;
+ if (column == flag) {
+ row++;
+ column = 0;
+ }
+ }
+
+ if (count == (flag * flag)) {
+ break;
+ }
+ }
+}
+
+void VideoBox::change_video_custom(int index, int type)
+{
+ //从开始索引开始往后衍生多少个通道
+ QList indexs;
+ for (int i = index; i < (index + type); ++i) {
+ indexs << i;
+ }
+
+ if (type == 6) {
+ change_video_6(indexs);
+ } else if (type == 8) {
+ change_video_8(indexs);
+ } else if (type == 13) {
+ change_video_13(indexs);
+ }
+}
+
+void VideoBox::change_video_6(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 6) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 2, 2);
+ gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 2, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_8(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 8) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 3, 3);
+ gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 3, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 3, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(6)), 3, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(7)), 3, 0, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_13(const QList &indexs)
+{
+ //过滤防止索引越界
+ if (indexs.count() < 13) {
+ return;
+ }
+
+ //首先隐藏所有通道
+ hide_video_all();
+ //挨个重新添加到布局
+ 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(2)), 0, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(3)), 0, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(4)), 1, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(6)), 1, 1, 2, 2);
+ gridLayout->addWidget(widgets.at(indexs.at(7)), 1, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(8)), 2, 3, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(9)), 3, 0, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(10)), 3, 1, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
+ gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
+ //设置通道控件可见
+ for (int i = indexs.first(); i <= indexs.last(); i++) {
+ widgets.at(i)->setVisible(true);
+ }
+}
+
+void VideoBox::change_video_1(int index)
+{
+ //首先隐藏所有通道
+ hide_video_all();
+ //添加通道到布局
+ gridLayout->addWidget(widgets.at(index), 0, 0);
+ //设置可见
+ widgets.at(index)->setVisible(true);
+}
+
+void VideoBox::change_video_4(int index)
+{
+ change_video_normal(index, 2);
+}
+
+void VideoBox::change_video_6(int index)
+{
+ change_video_custom(index, 6);
+}
+
+void VideoBox::change_video_8(int index)
+{
+ change_video_custom(index, 8);
+}
+
+void VideoBox::change_video_9(int index)
+{
+ change_video_normal(index, 3);
+}
+
+void VideoBox::change_video_13(int index)
+{
+ change_video_custom(index, 13);
+}
+
+void VideoBox::change_video_16(int index)
+{
+ change_video_normal(index, 4);
+}
+
+void VideoBox::change_video_25(int index)
+{
+ change_video_normal(index, 5);
+}
+
+void VideoBox::change_video_36(int index)
+{
+ change_video_normal(index, 6);
+}
+
+void VideoBox::change_video_64(int index)
+{
+ change_video_normal(index, 8);
+}
diff --git a/videopanel/videobox.h b/videopanel/videobox.h
new file mode 100644
index 0000000..6d6474c
--- /dev/null
+++ b/videopanel/videobox.h
@@ -0,0 +1,106 @@
+#ifndef VIDEOBOX_H
+#define VIDEOBOX_H
+
+/**
+ * 监控画面切换控件 作者:feiyangqingyun(QQ:517216493) 2021-11-08
+ * 1. 将所有通道切换处理全部集中到一个类。
+ * 2. 通用整数倍数布局切换函数,可方便拓展到100、255通道等。
+ * 3. 通用异形布局切换函数,可以参考进行自定义异形布局。
+ * 4. 通道布局切换发出信号通知。
+ * 5. 可控每种布局切换菜单是否启用。
+ * 6. 支持自定义子菜单布局内容。
+ * 7. 支持设置对应的菜单标识比如默认的通道字样改成设备。
+ */
+
+#include
+#include
+#include
+
+class QMenu;
+class QWidget;
+class QGridLayout;
+
+#ifdef quc
+class Q_DECL_EXPORT VideoBox : public QObject
+#else
+class VideoBox : public QObject
+#endif
+
+{
+ Q_OBJECT
+
+public:
+ explicit VideoBox(QObject *parent = 0);
+
+private:
+ //表格布局存放通道
+ QGridLayout *gridLayout;
+ //视频控件集合
+ QWidgetList widgets;
+
+ //通道数量
+ int videoCount;
+ //当前画面类型
+ QString videoType;
+
+ //主菜单子菜单文字标识
+ QString menuFlag;
+ QString actionFlag;
+
+ //布局方案标识集合
+ QMap types;
+ void addMenu(QMenu *menu, int type);
+
+public Q_SLOTS:
+ //设置当前画面类型
+ void setVideoType(const QString &videoType);
+ //设置表格布局
+ void setLayout(QGridLayout *gridLayout);
+ //设置视频控件集合
+ void setWidgets(QWidgetList widgets);
+
+ //设置主菜单子菜单文字标识
+ void setMenuFlag(const QString &menuFlag);
+ void setActionFlag(const QString &actionFlag);
+
+ //设置子菜单类型集合
+ void setTypes(const QMap &types);
+ //初始化菜单
+ void initMenu(QMenu *menu, const QList &enable);
+
+ //通用设置函数
+ void show_video(int type, int index);
+ //菜单切换布局槽函数
+ void show_video();
+
+ //显示和隐藏所有通道
+ void show_video_all();
+ void hide_video_all();
+
+ //常规及异形通道布局
+ void change_video_normal(int index, int flag);
+ void change_video_custom(int index, int type);
+
+ //异形布局
+ void change_video_6(const QList &indexs);
+ void change_video_8(const QList &indexs);
+ void change_video_13(const QList &indexs);
+
+ //具体通道切换函数
+ 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);
+
+Q_SIGNALS:
+ //画面布局切换信号
+ void changeVideo(int type, const QString &videoType, bool videoMax);
+};
+
+#endif // VIDEOBOX_H
diff --git a/videopanel/videopanel.cpp b/videopanel/videopanel.cpp
index 1beebc4..1c16e7e 100644
--- a/videopanel/videopanel.cpp
+++ b/videopanel/videopanel.cpp
@@ -1,6 +1,7 @@
#pragma execution_character_set("utf-8")
#include "videopanel.h"
+#include "videobox.h"
#include "qevent.h"
#include "qmenu.h"
#include "qlayout.h"
@@ -13,7 +14,6 @@ VideoPanel::VideoPanel(QWidget *parent) : QWidget(parent)
this->initControl();
this->initForm();
this->initMenu();
- this->show_video_all();
QTimer::singleShot(1000, this, SLOT(play_video_all()));
}
@@ -23,12 +23,12 @@ bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
QLabel *widget = (QLabel *) watched;
if (!videoMax) {
videoMax = true;
- hide_video_all();
+ videoBox->hide_video_all();
gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true);
} else {
videoMax = false;
- show_video_all();
+ videoBox->show_video_all();
}
widget->setFocus();
@@ -57,7 +57,6 @@ void VideoPanel::initControl()
gridLayout = new QGridLayout;
gridLayout->setSpacing(1);
gridLayout->setContentsMargins(0, 0, 0, 0);
- gridLayout->setObjectName("gridLayout");
this->setLayout(gridLayout);
}
@@ -86,7 +85,7 @@ void VideoPanel::initForm()
//二选一可以选择显示文字,也可以选择显示背景图片
widget->setText(QString("通道 %1").arg(i + 1));
//widget->setPixmap(QPixmap(":/bg_novideo.png"));
- widgets.append(widget);
+ widgets << widget;
}
}
@@ -94,46 +93,31 @@ void VideoPanel::initMenu()
{
videoMenu = new QMenu(this);
+ //单独关联信号槽
actionFull = new QAction("切换全屏模式", videoMenu);
connect(actionFull, SIGNAL(triggered(bool)), this, SLOT(full()));
actionPoll = new QAction("启动轮询视频", videoMenu);
connect(actionPoll, SIGNAL(triggered(bool)), this, SLOT(poll()));
+ //通过QAction类方式添加子菜单
videoMenu->addAction(actionFull);
videoMenu->addAction(actionPoll);
videoMenu->addSeparator();
+ //直接通过文字的形式添加子菜单
videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one()));
videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all()));
videoMenu->addSeparator();
- QMenu *menu4 = videoMenu->addMenu("切换到4画面");
- menu4->addAction("通道1-通道4", this, SLOT(show_video_4()));
- menu4->addAction("通道5-通道8", this, SLOT(show_video_4()));
- menu4->addAction("通道9-通道12", this, SLOT(show_video_4()));
- menu4->addAction("通道13-通道16", this, SLOT(show_video_4()));
-
- QMenu *menu6 = videoMenu->addMenu("切换到6画面");
- menu6->addAction("通道1-通道6", this, SLOT(show_video_6()));
- menu6->addAction("通道6-通道11", this, SLOT(show_video_6()));
- menu6->addAction("通道11-通道16", this, SLOT(show_video_6()));
-
- QMenu *menu8 = videoMenu->addMenu("切换到8画面");
- menu8->addAction("通道1-通道8", this, SLOT(show_video_8()));
- menu8->addAction("通道9-通道16", this, SLOT(show_video_8()));
-
- QMenu *menu9 = videoMenu->addMenu("切换到9画面");
- menu9->addAction("通道1-通道9", this, SLOT(show_video_9()));
- menu9->addAction("通道8-通道16", this, SLOT(show_video_9()));
-
- QMenu *menu13 = videoMenu->addMenu("切换到13画面");
- menu13->addAction("通道1-通道13", this, SLOT(show_video_13()));
- menu13->addAction("通道4-通道16", this, SLOT(show_video_13()));
-
- videoMenu->addAction("切换到16画面", this, SLOT(show_video_16()));
- videoMenu->addAction("切换到25画面", this, SLOT(show_video_25()));
- videoMenu->addAction("切换到36画面", this, SLOT(show_video_36()));
- videoMenu->addAction("切换到64画面", this, SLOT(show_video_64()));
+ //实例化通道布局类
+ videoBox = new VideoBox(this);
+ QList enable;
+ enable << true << true << true << true << true << true << true << true << true;
+ videoBox->initMenu(videoMenu, enable);
+ videoBox->setVideoType(videoType);
+ videoBox->setLayout(gridLayout);
+ videoBox->setWidgets(widgets);
+ videoBox->show_video_all();
}
void VideoPanel::full()
@@ -174,373 +158,3 @@ void VideoPanel::snapshot_video_all()
{
}
-
-void VideoPanel::show_video_all()
-{
- if (videoType == "1_4") {
- change_video_4(0);
- } else if (videoType == "5_8") {
- change_video_4(4);
- } else if (videoType == "9_12") {
- change_video_4(8);
- } else if (videoType == "13_16") {
- change_video_4(12);
- } else if (videoType == "1_6") {
- change_video_6(0);
- } else if (videoType == "6_11") {
- change_video_6(5);
- } else if (videoType == "11_16") {
- change_video_6(10);
- } else if (videoType == "1_8") {
- change_video_8(0);
- } else if (videoType == "9_16") {
- change_video_8(8);
- } else if (videoType == "1_9") {
- change_video_9(0);
- } else if (videoType == "8_16") {
- change_video_9(7);
- } else if (videoType == "1_13") {
- change_video_13(0);
- } else if (videoType == "4_16") {
- change_video_13(3);
- } else if (videoType == "1_16") {
- change_video_16(0);
- } else if (videoType == "1_25") {
- change_video_25(0);
- } else if (videoType == "1_36") {
- change_video_36(0);
- } else if (videoType == "1_64") {
- change_video_64(0);
- }
-}
-
-void VideoPanel::show_video_4()
-{
- QAction *action = (QAction *)sender();
- QString name = action->text();
-
- int index = 0;
- QString videoType;
- if (name == "通道1-通道4") {
- index = 0;
- videoType = "1_4";
- } else if (name == "通道5-通道8") {
- index = 4;
- videoType = "5_8";
- } else if (name == "通道9-通道12") {
- index = 8;
- videoType = "9_12";
- } else if (name == "通道13-通道16") {
- index = 12;
- videoType = "13_16";
- }
-
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_4(index);
- }
-}
-
-void VideoPanel::show_video_6()
-{
- QAction *action = (QAction *)sender();
- QString name = action->text();
-
- int index = 0;
- QString videoType;
- if (name == "通道1-通道6") {
- index = 0;
- videoType = "1_6";
- } else if (name == "通道6-通道11") {
- index = 5;
- videoType = "6_11";
- } else if (name == "通道11-通道16") {
- index = 10;
- videoType = "11_16";
- }
-
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_6(index);
- }
-}
-
-void VideoPanel::show_video_8()
-{
- QAction *action = (QAction *)sender();
- QString name = action->text();
-
- int index = 0;
- QString videoType;
- if (name == "通道1-通道8") {
- index = 0;
- videoType = "1_8";
- } else if (name == "通道9-通道16") {
- index = 8;
- videoType = "9_16";
- }
-
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_8(index);
- }
-}
-
-void VideoPanel::show_video_9()
-{
- QAction *action = (QAction *)sender();
- QString name = action->text();
-
- int index = 0;
- QString videoType;
- if (name == "通道1-通道9") {
- index = 0;
- videoType = "1_9";
- } else if (name == "通道8-通道16") {
- index = 7;
- videoType = "8_16";
- }
-
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_9(index);
- }
-}
-
-void VideoPanel::show_video_13()
-{
- QAction *action = (QAction *)sender();
- QString name = action->text();
-
- int index = 0;
- QString videoType;
- if (name == "通道1-通道13") {
- index = 0;
- videoType = "1_13";
- } else if (name == "通道4-通道16") {
- index = 3;
- videoType = "4_16";
- }
-
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_13(index);
- }
-}
-
-void VideoPanel::show_video_16()
-{
- int index = 0;
- QString videoType = "1_16";
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_16(index);
- }
-}
-
-void VideoPanel::show_video_25()
-{
- int index = 0;
- QString videoType = "1_25";
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_25(index);
- }
-}
-
-void VideoPanel::show_video_36()
-{
- int index = 0;
- QString videoType = "1_36";
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_36(index);
- }
-}
-
-void VideoPanel::show_video_64()
-{
- int index = 0;
- QString videoType = "1_64";
- if (this->videoType != videoType) {
- this->videoType = videoType;
- this->videoMax = false;
- change_video_64(index);
- }
-}
-
-void VideoPanel::hide_video_all()
-{
- for (int i = 0; i < videoCount; i++) {
- gridLayout->removeWidget(widgets.at(i));
- widgets.at(i)->setVisible(false);
- }
-}
-
-void VideoPanel::change_video(int index, int flag)
-{
- int count = 0;
- int row = 0;
- int column = 0;
-
- //行列数一致的比如 2*2 3*4 4*4 5*5 等可以直接套用通用的公式
- //按照这个函数还可以非常容易的拓展出 10*10 16*16=256 通道界面
- for (int i = 0; i < videoCount; i++) {
- if (i >= index) {
- gridLayout->addWidget(widgets.at(i), row, column);
- widgets.at(i)->setVisible(true);
-
- count++;
- column++;
- if (column == flag) {
- row++;
- column = 0;
- }
- }
-
- if (count == (flag * flag)) {
- break;
- }
- }
-}
-
-void VideoPanel::change_video_4(int index)
-{
- hide_video_all();
- change_video(index, 2);
-}
-
-void VideoPanel::change_video_6(const QList &indexs)
-{
- gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 2, 2);
- gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(4)), 2, 1, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
-
- for (int i = indexs.first(); i <= indexs.last(); i++) {
- widgets.at(i)->setVisible(true);
- }
-}
-
-void VideoPanel::change_video_6(int index)
-{
- hide_video_all();
- if (index == 0) {
- QList indexs;
- indexs << 0 << 1 << 2 << 3 << 4 << 5;
- change_video_6(indexs);
- } else if (index == 5) {
- QList indexs;
- indexs << 5 << 6 << 7 << 8 << 9 << 10;
- change_video_6(indexs);
- } else if (index == 10) {
- QList indexs;
- indexs << 10 << 11 << 12 << 13 << 14 << 15;
- change_video_6(indexs);
- }
-}
-
-void VideoPanel::change_video_8(const QList &indexs)
-{
- gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 3, 3);
- gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(4)), 3, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(5)), 3, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(6)), 3, 1, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(7)), 3, 0, 1, 1);
-
- for (int i = indexs.first(); i <= indexs.last(); i++) {
- widgets.at(i)->setVisible(true);
- }
-}
-
-void VideoPanel::change_video_8(int index)
-{
- hide_video_all();
- if (index == 0) {
- QList indexs;
- indexs << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7;
- change_video_8(indexs);
- } else if (index == 8) {
- QList indexs;
- indexs << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15;
- change_video_8(indexs);
- }
-}
-
-void VideoPanel::change_video_9(int index)
-{
- hide_video_all();
- change_video(index, 3);
-}
-
-void VideoPanel::change_video_13(const QList &indexs)
-{
- 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(2)), 0, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(3)), 0, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(4)), 1, 0, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(6)), 1, 1, 2, 2);
- gridLayout->addWidget(widgets.at(indexs.at(7)), 1, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(8)), 2, 3, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(9)), 3, 0, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(10)), 3, 1, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
- gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
-
- for (int i = indexs.first(); i <= indexs.last(); i++) {
- widgets.at(i)->setVisible(true);
- }
-}
-
-void VideoPanel::change_video_13(int index)
-{
- hide_video_all();
- if (index == 0) {
- QList indexs;
- indexs << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
- change_video_13(indexs);
- } else if (index == 3) {
- QList indexs;
- indexs << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15;
- change_video_13(indexs);
- }
-}
-
-void VideoPanel::change_video_16(int index)
-{
- hide_video_all();
- change_video(index, 4);
-}
-
-void VideoPanel::change_video_25(int index)
-{
- hide_video_all();
- change_video(index, 5);
-}
-
-void VideoPanel::change_video_36(int index)
-{
- hide_video_all();
- change_video(index, 6);
-}
-
-void VideoPanel::change_video_64(int index)
-{
- hide_video_all();
- change_video(index, 8);
-}
diff --git a/videopanel/videopanel.h b/videopanel/videopanel.h
index 099c68e..f33fa7b 100644
--- a/videopanel/videopanel.h
+++ b/videopanel/videopanel.h
@@ -3,7 +3,11 @@
/**
* 视频监控画面控件 整理:feiyangqingyun(QQ:517216493) 2019-04-11
- * 1. 目前颜色都写死在样式表,可自行更改或者拓展属性设置。
+ * 1. 可设定视频通道数量。
+ * 2. 支持双击最大化再次双击还原。
+ * 3. 支持4/6/8/9/13/16/25/36/64等通道布局。
+ * 4. 内置了选中边框高亮等样式。
+ * 5. 通用的视频通道布局盒子类,方便拓展其他布局。
*/
#include
@@ -11,6 +15,7 @@
class QMenu;
class QLabel;
class QGridLayout;
+class VideoBox;
#ifdef quc
class Q_DECL_EXPORT VideoPanel : public QWidget
@@ -28,14 +33,16 @@ protected:
bool eventFilter(QObject *watched, QEvent *event);
private:
- QGridLayout *gridLayout; //表格布局存放视频标签
bool videoMax; //是否最大化
int videoCount; //视频通道个数
QString videoType; //当前画面类型
QMenu *videoMenu; //右键菜单
QAction *actionFull; //全屏动作
QAction *actionPoll; //轮询动作
- QList widgets; //视频标签集合
+
+ QGridLayout *gridLayout; //通道表格布局
+ QWidgetList widgets; //视频控件集合
+ VideoBox *videoBox; //通道布局类
public:
QSize sizeHint() const;
@@ -51,35 +58,10 @@ private slots:
private slots:
void play_video_all();
void snapshot_video_one();
- void snapshot_video_all();
-
- void show_video_all();
- void show_video_4();
- void show_video_6();
- void show_video_8();
- void show_video_9();
- void show_video_13();
- void show_video_16();
- void show_video_25();
- void show_video_36();
- void show_video_64();
-
- void hide_video_all();
- void change_video(int index, int flag);
- void change_video_4(int index);
- void change_video_6(const QList &indexs);
- void change_video_6(int index);
- void change_video_8(const QList &indexs);
- void change_video_8(int index);
- void change_video_9(int index);
- void change_video_13(const QList &indexs);
- 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 snapshot_video_all();
signals:
+ //全屏切换信号
void fullScreen(bool full);
};
diff --git a/videopanel/videopanel.pro b/videopanel/videopanel.pro
index 47b94b6..3bda784 100644
--- a/videopanel/videopanel.pro
+++ b/videopanel/videopanel.pro
@@ -10,8 +10,10 @@ CONFIG += warn_off
SOURCES += main.cpp
SOURCES += frmvideopanel.cpp
SOURCES += videopanel.cpp
+SOURCES += videobox.cpp
HEADERS += frmvideopanel.h
HEADERS += videopanel.h
+HEADERS += videobox.h
FORMS += frmvideopanel.ui
diff --git a/videowidget/font/iconfont.ttf b/videowidget/font/iconfont.ttf
new file mode 100644
index 0000000..ba15da8
Binary files /dev/null and b/videowidget/font/iconfont.ttf differ
diff --git a/videowidget/frmvideowidget.ui b/videowidget/frmvideowidget.ui
index 014ea15..db40a0a 100644
--- a/videowidget/frmvideowidget.ui
+++ b/videowidget/frmvideowidget.ui
@@ -6,8 +6,8 @@
0
0
- 500
- 300
+ 800
+ 600
@@ -65,9 +65,6 @@
-
- Qt::AlignCenter
-
diff --git a/videowidget/main.cpp b/videowidget/main.cpp
index 8b7d649..b4e3fb6 100644
--- a/videowidget/main.cpp
+++ b/videowidget/main.cpp
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9));
-#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
diff --git a/videowidget/main.qrc b/videowidget/main.qrc
new file mode 100644
index 0000000..1544a9a
--- /dev/null
+++ b/videowidget/main.qrc
@@ -0,0 +1,5 @@
+
+
+ font/iconfont.ttf
+
+
diff --git a/videowidget/videowidget.cpp b/videowidget/videowidget.cpp
index b0642ac..14bb56c 100644
--- a/videowidget/videowidget.cpp
+++ b/videowidget/videowidget.cpp
@@ -179,7 +179,11 @@ void VideoWidget::resizeEvent(QResizeEvent *)
//flowPanel->setGeometry(borderWidth, this->height() - height - borderWidth, this->width() - (borderWidth * 2), height);
}
+#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
+void VideoWidget::enterEvent(QEnterEvent *)
+#else
void VideoWidget::enterEvent(QEvent *)
+#endif
{
//这里还可以增加一个判断,是否获取了焦点的才需要显示
//if (this->hasFocus()) {}
diff --git a/videowidget/videowidget.h b/videowidget/videowidget.h
index 73c6f58..ffb0c44 100644
--- a/videowidget/videowidget.h
+++ b/videowidget/videowidget.h
@@ -24,9 +24,9 @@ class QTimer;
#ifdef quc
class Q_DECL_EXPORT VideoWidget : public QWidget
-#else
+ #else
class VideoWidget : public QWidget
-#endif
+ #endif
{
Q_OBJECT
@@ -89,7 +89,11 @@ public:
protected:
void resizeEvent(QResizeEvent *);
+#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
+ void enterEvent(QEnterEvent *);
+#else
void enterEvent(QEvent *);
+#endif
void leaveEvent(QEvent *);
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
diff --git a/videowidget/videowidget.pro b/videowidget/videowidget.pro
index 52f8294..3e6076c 100644
--- a/videowidget/videowidget.pro
+++ b/videowidget/videowidget.pro
@@ -15,3 +15,5 @@ HEADERS += frmvideowidget.h
HEADERS += videowidget.h
FORMS += frmvideowidget.ui
+
+RESOURCES += main.qrc