彻底改版2.0

This commit is contained in:
feiyangqingyun
2021-11-17 16:41:30 +08:00
parent a7f4347959
commit ebfd531a91
2622 changed files with 8915 additions and 7263 deletions

View File

@@ -0,0 +1,13 @@
#pragma execution_character_set("utf-8")
#include "frmvideopanel.h"
#include "ui_frmvideopanel.h"
frmVideoPanel::frmVideoPanel(QWidget *parent) : QWidget(parent), ui(new Ui::frmVideoPanel)
{
ui->setupUi(this);
}
frmVideoPanel::~frmVideoPanel()
{
delete ui;
}

View File

@@ -0,0 +1,22 @@
#ifndef FRMVIDEOPANEL_H
#define FRMVIDEOPANEL_H
#include <QWidget>
namespace Ui {
class frmVideoPanel;
}
class frmVideoPanel : public QWidget
{
Q_OBJECT
public:
explicit frmVideoPanel(QWidget *parent = 0);
~frmVideoPanel();
private:
Ui::frmVideoPanel *ui;
};
#endif // FRMVIDEOPANEL_H

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frmVideoPanel</class>
<widget class="QWidget" name="frmVideoPanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="VideoPanel" name="widget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VideoPanel</class>
<extends>QWidget</extends>
<header>videopanel.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

32
video/videopanel/main.cpp Normal file
View File

@@ -0,0 +1,32 @@
#pragma execution_character_set("utf-8")
#include "frmvideopanel.h"
#include <QApplication>
#include <QTextCodec>
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
frmVideoPanel w;
w.setWindowTitle("视频监控画面");
w.resize(800, 600);
w.show();
return a.exec();
}

View File

@@ -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<int, QStringList> &types)
{
this->types = types;
}
void VideoBox::initMenu(QMenu *menu, const QList<bool> &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<int, QStringList>::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<int> 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<int> &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<int> &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<int> &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);
}

106
video/videopanel/videobox.h Normal file
View File

@@ -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 <QObject>
#include <QWidget>
#include <QMap>
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<int, QStringList> 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<int, QStringList> &types);
//初始化菜单
void initMenu(QMenu *menu, const QList<bool> &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<int> &indexs);
void change_video_8(const QList<int> &indexs);
void change_video_13(const QList<int> &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

View File

@@ -0,0 +1,160 @@
#pragma execution_character_set("utf-8")
#include "videopanel.h"
#include "videobox.h"
#include "qevent.h"
#include "qmenu.h"
#include "qlayout.h"
#include "qlabel.h"
#include "qtimer.h"
#include "qdebug.h"
VideoPanel::VideoPanel(QWidget *parent) : QWidget(parent)
{
this->initControl();
this->initForm();
this->initMenu();
QTimer::singleShot(1000, this, SLOT(play_video_all()));
}
bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick) {
QLabel *widget = (QLabel *) watched;
if (!videoMax) {
videoMax = true;
videoBox->hide_video_all();
gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true);
} else {
videoMax = false;
videoBox->show_video_all();
}
widget->setFocus();
} else if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = (QMouseEvent *)event;
if (mouseEvent->button() == Qt::RightButton) {
videoMenu->exec(QCursor::pos());
}
}
return QWidget::eventFilter(watched, event);
}
QSize VideoPanel::sizeHint() const
{
return QSize(800, 600);
}
QSize VideoPanel::minimumSizeHint() const
{
return QSize(80, 60);
}
void VideoPanel::initControl()
{
gridLayout = new QGridLayout;
gridLayout->setSpacing(1);
gridLayout->setContentsMargins(0, 0, 0, 0);
this->setLayout(gridLayout);
}
void VideoPanel::initForm()
{
//设置样式表
#ifndef no_style
QStringList qss;
qss.append("QFrame{border:2px solid #000000;}");
qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#303030;}");
qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}");
this->setStyleSheet(qss.join(""));
#endif
videoMax = false;
videoCount = 64;
videoType = "1_16";
for (int i = 0; i < videoCount; i++) {
QLabel *widget = new QLabel;
widget->setObjectName(QString("video%1").arg(i + 1));
widget->installEventFilter(this);
widget->setFocusPolicy(Qt::StrongFocus);
widget->setAlignment(Qt::AlignCenter);
//二选一可以选择显示文字,也可以选择显示背景图片
widget->setText(QString("通道 %1").arg(i + 1));
//widget->setPixmap(QPixmap(":/bg_novideo.png"));
widgets << widget;
}
}
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();
//实例化通道布局类
videoBox = new VideoBox(this);
QList<bool> 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()
{
if (actionFull->text() == "切换全屏模式") {
emit fullScreen(true);
actionFull->setText("切换正常模式");
} else {
emit fullScreen(false);
actionFull->setText("切换全屏模式");
}
//执行全屏处理
}
void VideoPanel::poll()
{
if (actionPoll->text() == "启动轮询视频") {
actionPoll->setText("停止轮询视频");
} else {
actionPoll->setText("启动轮询视频");
}
//执行轮询处理
}
void VideoPanel::play_video_all()
{
}
void VideoPanel::snapshot_video_one()
{
}
void VideoPanel::snapshot_video_all()
{
}

View File

@@ -0,0 +1,68 @@
#ifndef VIDEOPANEL_H
#define VIDEOPANEL_H
/**
* 视频监控画面控件 整理:feiyangqingyun(QQ:517216493) 2019-04-11
* 1. 可设定视频通道数量。
* 2. 支持双击最大化再次双击还原。
* 3. 支持4/6/8/9/13/16/25/36/64等通道布局。
* 4. 内置了选中边框高亮等样式。
* 5. 通用的视频通道布局盒子类,方便拓展其他布局。
*/
#include <QWidget>
class QMenu;
class QLabel;
class QGridLayout;
class VideoBox;
#ifdef quc
class Q_DECL_EXPORT VideoPanel : public QWidget
#else
class VideoPanel : public QWidget
#endif
{
Q_OBJECT
public:
explicit VideoPanel(QWidget *parent = 0);
protected:
bool eventFilter(QObject *watched, QEvent *event);
private:
bool videoMax; //是否最大化
int videoCount; //视频通道个数
QString videoType; //当前画面类型
QMenu *videoMenu; //右键菜单
QAction *actionFull; //全屏动作
QAction *actionPoll; //轮询动作
QGridLayout *gridLayout; //通道表格布局
QWidgetList widgets; //视频控件集合
VideoBox *videoBox; //通道布局类
public:
QSize sizeHint() const;
QSize minimumSizeHint() const;
private slots:
void initControl();
void initForm();
void initMenu();
void full();
void poll();
private slots:
void play_video_all();
void snapshot_video_one();
void snapshot_video_all();
signals:
//全屏切换信号
void fullScreen(bool full);
};
#endif // VIDEOPANEL_H

View File

@@ -0,0 +1,19 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = videopanel
TEMPLATE = app
DESTDIR = $$PWD/../bin
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