2021-11-09 12:39:42 +00:00
|
|
|
|
#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;
|
2024-02-26 02:34:39 +00:00
|
|
|
|
box->hide_all();
|
2021-11-09 12:39:42 +00:00
|
|
|
|
ui->gridLayout->addWidget(widget, 0, 0);
|
|
|
|
|
widget->setVisible(true);
|
|
|
|
|
} else {
|
|
|
|
|
max = false;
|
2024-02-26 02:34:39 +00:00
|
|
|
|
box->show_all();
|
2021-11-09 12:39:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2023-12-23 05:30:26 +00:00
|
|
|
|
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
label->setText(QString("通道 %1").arg(i + 1, 2, 10, QChar('0')));
|
2021-11-09 12:39:42 +00:00
|
|
|
|
widgets << label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//实例化盒子
|
|
|
|
|
box = new VideoBox(this);
|
|
|
|
|
//关联信号槽
|
2024-02-26 02:34:39 +00:00
|
|
|
|
connect(box, SIGNAL(changeLayout(int, QString, bool)), this, SLOT(changeLayout(int, QString, bool)));
|
2023-12-23 05:30:26 +00:00
|
|
|
|
//可以改成 1_4/5_8/1_36 等
|
2024-02-26 02:34:39 +00:00
|
|
|
|
box->setLayoutType("1_16");
|
2021-11-09 12:39:42 +00:00
|
|
|
|
box->setLayout(ui->gridLayout);
|
|
|
|
|
box->setWidgets(widgets);
|
|
|
|
|
|
2023-12-23 05:30:26 +00:00
|
|
|
|
//box->setMenuFlag("排列");
|
|
|
|
|
//box->setActionFlag("监控");
|
|
|
|
|
//增加自定义布局(通道1开始3行3列布局)
|
|
|
|
|
//box->appendType(1, 3, 4);
|
|
|
|
|
|
|
|
|
|
//实例化菜单/先添加自己的菜单
|
2021-11-09 12:39:42 +00:00
|
|
|
|
menu = new QMenu(this);
|
|
|
|
|
//这里关联到一个槽函数处理,也可以关联到不同的槽函数
|
|
|
|
|
menu->addAction("切换全屏模式", this, SLOT(doAction()));
|
|
|
|
|
menu->addAction("启动轮询视频", this, SLOT(doAction()));
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
2023-12-23 05:30:26 +00:00
|
|
|
|
//把菜单加到盒子上
|
|
|
|
|
box->initMenu(menu);
|
2024-02-26 02:34:39 +00:00
|
|
|
|
box->show_all();
|
2021-11-09 12:39:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void frmVideoBox::doAction()
|
|
|
|
|
{
|
|
|
|
|
//判断是哪个动作触发的
|
|
|
|
|
QAction *action = (QAction *)sender();
|
|
|
|
|
ui->label->setText(QString("触发了菜单: %1").arg(action->text()));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-26 02:34:39 +00:00
|
|
|
|
void frmVideoBox::changeLayout(int type, const QString &videoType, bool videoMax)
|
2021-11-09 12:39:42 +00:00
|
|
|
|
{
|
|
|
|
|
QString info = QString("主菜单:%1 子菜单:%2").arg(type).arg(videoType);
|
|
|
|
|
ui->label->setText(info);
|
|
|
|
|
}
|