You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
5.0 KiB

6 months ago
#include "set.h"
#include "ui_set.h"
Comnet::Comnet(QObject *parent) : QObject(parent)
{
}
set::set(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::set)
{
ui->setupUi(this);
layout_init();
m_realLoad=false;
m_windowShow=false;
m_engine=new QQmlApplicationEngine;
cmd = new QProcess(this);
cmd_stop = new QProcess(this);
/* 连接信号槽 */
connect(cmd , SIGNAL(readyReadStandardOutput()) , this , SLOT(readoutput()));
connect(cmd , SIGNAL(readyReadStandardError()) , this , SLOT(readerror()));
floatingbutton= new FloatingButton (this);
// 将悬浮球的pressed()信号连接到槽函数onButtonPressed()上
connect(floatingbutton, &FloatingButton::pressed, this, &set::onButtonPressed);
}
set::~set()
{
delete device;
delete pushButton[0];
delete label[0];
delete m_engine;
delete cmd;
delete cmd_stop;
delete floatingbutton;
delete ui;
delete switchButton;
cmd_stop->close();
cmd_stop->waitForFinished();
}
void set::onButtonPressed()
{
emit set_close(false);
qDebug() << "悬浮球被按下了!";
}
void set::layout_init()
{
/*初始化按键*/
switchButton = new SwitchButton(this);
switchButton->setMaximumSize(60, 30);
switchButton->setMinimumSize(60, 30);
for(i=0;i<4;i++)
{
pushButton[i] =new QPushButton(this);
pushButton[i]->setMaximumSize(40, 40);
pushButton[i]->setMinimumSize(40, 40);
pushButton[i]->setStyleSheet("QPushButton{border-image: url(:/set/images/next2.png); "
"background-position:center;border:none}QPushButton:hover{border-image: url(:/set/images/next.png);}");
}
/*初始化图案*/
for(i=0;i<5;i++)
{
label[i] =new QLabel(this);
label[i]->setMaximumSize(40, 40);
label[i]->setMaximumSize(40, 40);
}
/*按键布局*/
pushButton[0]->setGeometry(680,35,40,40);
pushButton[1]->setGeometry(680,125,40,40);
pushButton[2]->setGeometry(680,216,40,40);
pushButton[3]->setGeometry(680,310,40,40);
switchButton->setGeometry(660,410,30,30);
/*图案布局*/
label[0]->setStyleSheet("QLabel{border-image: url(:/set/images/iphone.png);}");
label[0]->setGeometry(50,30,40,40);
label[1]->setStyleSheet("QLabel{border-image: url(:/set/images/wifi1.png);}");
label[1]->setGeometry(50,125,40,40);
label[2]->setStyleSheet("QLabel{border-image: url(:/set/images/Bluetooth.png);}");
label[2]->setGeometry(50,216,40,40);
label[3]->setStyleSheet("QLabel{border-image: url(:/set/images/hot3.png);}");
label[3]->setGeometry(50,310,40,40);
label[4]->setStyleSheet("QLabel{border-image: url(:/set/images/monitoring.png);}");
label[4]->setGeometry(50,408,40,40);
/* 连接信号槽 */
connect(switchButton,
SIGNAL(toggled(bool)),
this,
SLOT(switchButtonClicked(bool)));
}
//设置按钮图标,按钮的默认大小是 30*30可以自己指定
void set::setButtonImage(QPushButton *button, QString image)
{
button->setText("");
QPixmap pixmap(image);
QPixmap fitpixmap = pixmap.scaled(30, 30, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
button->setIcon(QIcon(fitpixmap));
button->setIconSize(QSize(30, 30));
button->setFlat(true);
button->setStyleSheet("border: 0px"); //消除边框
}
/*我的设备*/
void set::on_pushButton_2_clicked()
{
device = new mydevice();
device->setGeometry(0,0,800,480);
device->show();
}
/*wifi*/
void set::on_pushButton_3_clicked()
{
if(m_windowShow){
return;
}
if(m_realLoad){
qDebug()<<"开启";
return;
}
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qmlRegisterType<wirelessListModel>("wirelessModel", 1, 0, "WirelessListModel");
qmlRegisterType<Comnet>("an.qml.comnet", 1, 0, "Comnet");
m_engine->rootContext()->setContextProperty("WINenv", false);
m_engine->load(QUrl(QStringLiteral("qrc:/main.qml")));
if (m_engine->rootObjects().isEmpty())
{
qDebug()<<"load errpr";
}
}
/* 当点开关时,开启视频监控*/
void set::switchButtonClicked(bool checked)
{
if(checked==true)
{
qDebug()<<"监控已打开"<<endl;
cmd->start("bash"); //启动终端(Windows下改为cmd)
cmd->waitForStarted(); //等待启动完成
cmd->write("ffmpeg -f v4l2 -video_size 320x240 -framerate 15 -i /dev/video1 -q 10 -f flv -an rtmp://120.79.100.106:1935/live/romm\n"); //向终端写入“ls”命令注意尾部的“\n”不可省略
}
else
{
cmd_stop->start("bash");
cmd_stop->waitForStarted(); //等待启动完成
cmd_stop->write("killall ffmpeg\n");
cmd->close();
cmd->waitForFinished();
qDebug()<<"监控已关闭"<<endl;
}
}
void set::readoutput()
{
qDebug()<<cmd->readAllStandardOutput().data()<<endl;
}
void set::readerror()
{
qDebug()<<cmd->readAllStandardError().data()<<endl;
}