1 Star 0 Fork 20

MumiWHN/24041智能安防_3

forked from 刘军/24041智能安防 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainwidget.cpp 8.68 KB
一键复制 编辑 原始数据 按行查看 历史
卢杰 提交于 2024-09-19 14:15 . 界面
#include "mainwidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDebug>
#include <QMenu>
#include "myonvif.h"
#include "mywin.h"
#include <QDateTime>
bool mainWidget::flag_snap = false;
bool mainWidget::flag_record = false;
bool mainWidget::flag_login = false;
QString mainWidget::user = "";
QString mainWidget::pwd = "";
V4l2Api* mainWidget::v412 = new V4l2Api;
mainWidget::mainWidget(QWidget *parent) : QWidget(parent)
{
qDebug() << "MyNewWidget constructor start";
this->setMinimumSize(1024, 1024);
this->setWindowTitle("实时监控画面");
this->showGas.start();
this->showHum.start();
this->showTemp.start();
this->showLocalTempHum.start();
QHBoxLayout *hbox1 = new QHBoxLayout;
QHBoxLayout *hbox2 = new QHBoxLayout;
QHBoxLayout *hbox3 = new QHBoxLayout;
QHBoxLayout *hbox4 = new QHBoxLayout;
for(int i =0;i<8;i++)
{
this->lab_record[i] = new QLabel(this);
this->lab_record[i]->setFrameShape(QLabel::Box);
this->lab_record[i]->setScaledContents(true);
this->lab_record[i]->setContextMenuPolicy(Qt::CustomContextMenu);
this->lab_record[i]->setFixedSize(400,170);
if(i<2)
hbox1->addWidget(this->lab_record[i]);
else if(i<4)
hbox2->addWidget(this->lab_record[i]);
else if(i<6)
hbox3->addWidget(this->lab_record[i]);
else
hbox4->addWidget(this->lab_record[i]);
// 创建菜单并为每个 QLabel 连接自定义上下文菜单
QMenu *menu = new QMenu(lab_record[i]);
// 添加菜单项
QAction *action1 = menu->addAction("添加摄像头");
QAction *action2 = menu->addAction("拍照");
QAction *action3 = menu->addAction("开始录制");
QAction *action4 = menu->addAction("----");
QAction *action5 = menu->addAction("--9-");
QAction *action6 = menu->addAction("----");
connect(action1, &QAction::triggered, [=]() {
if(mainWidget::flag_login)
{
qDebug() << "菜单项 1 被点击--add";
connect(myWin::getWin()->dealPage[i], &Deal::sendImage, this, &mainWidget::showLabel);
myWin::getWin()->dealPage[i]->show();
}
else
QMessageBox::warning(this,"警告","请先进行登录");
});
connect(action2, &QAction::triggered, [=]() {
if(mainWidget::flag_login)
{
this->flag_snap = true;
}
else
QMessageBox::warning(this,"警告","请先进行登录");
});
connect(action3, &QAction::triggered, [=]() {
qDebug() << "菜单项 3 被点击--record";
if(mainWidget::flag_login)
{
if(action3->text() == "开始录制")
{
this->flag_record = true;
action3->setText("结束录制");
}
else
{
this->flag_record = false;
action3->setText("开始录制");
}
}
else
QMessageBox::warning(this,"警告","请先进行登录");
});
connect(action4, &QAction::triggered, [=]() {
qDebug() << "菜单项 4 被点击";
});
connect(action5, &QAction::triggered, [=]() {
qDebug() << "菜单项 5 被点击";
});
connect(action6, &QAction::triggered, [=]() {
qDebug() << "菜单项 6 被点击";
});
/*
customContextMenuRequested 信号是一个特殊的信号,它在用户请求上下文菜单时被发出。
这个信号通常是当用户在某个控件上点击鼠标右键时触发的,但本质上,它并不仅仅与鼠标右键点击绑定。
它是 Qt 中的一个可重写的虚函数,可以被用来触发上下文菜单的显示。
当用户在界面上点击鼠标右键时,操作系统会发送一个特殊的消息给应用程序,告诉它用户请求了一个上下文菜单。
Qt 框架会截获这个消息,并将其转换为 customContextMenuRequested 信号。
*/
// 连接 QLabel 的 customContextMenuRequested 信号到 QMenu 的 exec 方法
connect(this->lab_record[i], &QLabel::customContextMenuRequested, [=](const QPoint &pos) {
menu->exec(this->lab_record[i]->mapToGlobal(pos));
});
}
this->lab_recordState = new QLabel("未录制",this);
this->lab_recordState->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
this->lab_recordState->setStyleSheet("background-color: transparent; color: white;");
this->isRecording = false;
//
QVBoxLayout *vbox = new QVBoxLayout();
this->MBar = new QMenuBar(this);
//菜单栏中添加菜单
QMenu *Begin = new QMenu("开始",this);
this->MBar->addMenu(Begin);
// 添加菜单项
QAction *Baction1 = Begin->addAction("主菜单");
QAction *Baction2 = Begin->addAction("文件管理");
QAction *Baction3 = Begin->addAction("用户管理");
QAction *Baction4 = Begin->addAction("");
QAction *Baction5 = Begin->addAction("搜索");
connect(Baction1, &QAction::triggered, [=]() {
qDebug() << "菜单项 1 被点击";
this->close();
myWin::getWin()->Mmenu->show();
});
connect(Baction2, &QAction::triggered, [=]() {
qDebug() << "菜单项 2 被点击";
});
connect(Baction3, &QAction::triggered, [=]() {
qDebug() << "菜单项 3 被点击--用户管理";
this->close();
myWin::getWin()->user->show();
});
connect(Baction4, &QAction::triggered, [=]() {
qDebug() << "菜单项 4 被点击";
});
connect(Baction5, &QAction::triggered, [=]() {
qDebug() << "菜单项 5 被点击---搜索";
MyOnvif Onv;
Onv.searchOnvifCamera();
});
vbox->addLayout(hbox1);
vbox->addLayout(hbox2);
vbox->addLayout(hbox3);
vbox->addLayout(hbox4);
vbox->addWidget(MBar);
QHBoxLayout *hbox5 = new QHBoxLayout;
this->lab = new QLabel;
this->lab->setFixedSize(100,256);
this->lab->setFrameShape(QLabel::Box);
hbox5->addWidget(this->lab);
hbox5->addLayout(vbox);
this->setLayout(hbox5);
connect(&this->showLocalTempHum,&GetTemHum::sendate,this,&mainWidget::showLocalLabel);
// // 将 lab_recordState 添加到布局中
// hbox->addWidget(lab_recordState,Qt::AlignBottom | Qt::AlignLeft);
// // 设置 lab_record 的布局
// for(int i=0;i<8;i++)
// {
// lab_record[i]->setLayout(hbox);
// }
// this->setLayout(vbox);
// this->threadShow = new showThread;
// connect(this->threadShow, &showThread::sendImage, this, &mainWidget::showLabel);
// if(this->lab_recordState->text() == "...正在录制")
// {
// this->lab_recordState->setText("未录制");
// this->lab_recordState->setStyleSheet("color: white;");
// this->isRecording = false;
// }
// else
// {
// this->lab_recordState->setText("...正在录制");
// this->lab_recordState->setStyleSheet("color: green;");
// this->isRecording = true;
// }
qDebug() << "MyNewWidget constructor end";
QPalette palette;
palette.setBrush(QPalette::Background,
QBrush(QPixmap(":/icon/arouad.jpg").scaled(this->size())));
//调色板设置给界面
this->setPalette(palette);
}
int mainWidget::findIndexByThread(showThread *thread)
{
// for (int i = 0; i < 8; ++i) {
// if (showVideo[i] == thread) {
// return i;
// }
// }
return -1; // 如果没有找到,返回 -1 或其他错误指示
}
void mainWidget::showLabel(int chanel,QImage image)
{
// qDebug() <<"into showLabel";
this->lab_record[chanel]->setPixmap(QPixmap::fromImage(image));
if(this->isRecording == true)
{
qDebug() << image.byteCount();
}
// else
// {
// }
}
void mainWidget::showLocalLabel(float temp, float hum)
{
if(GetWeather::time != "")
{
this->lab->setText("时间:\n"+GetWeather::time.split(" ").at(0)+"\n"+GetWeather::time.split(" ").at(1)+"\n"+"温度:"+QString::number(temp, 'f', 2)+"\n"+"湿度:"+QString::number(hum, 'f', 2)+"\n"
+"天气:"+ GetWeather::weather+"\n"+"风向:"+ GetWeather::windDirect+"\n"+"风级:"+ GetWeather::windPower+"\n"+"风速:"+QString::number(GetWeather::windSpeed, 'f', 2));
}
}
void mainWidget::showEvent(QShowEvent *event)
{
// 调用基类的 showEvent
QWidget::showEvent(event);
this->getweater.start();
qDebug()<<"mainWidget::showEvent";
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mumiwhn/24041-intelligent-security_3.git
git@gitee.com:mumiwhn/24041-intelligent-security_3.git
mumiwhn
24041-intelligent-security_3
24041智能安防_3
master

搜索帮助