qt/LedOK/wDevicesManager/controlvolumemanual.cpp

185 lines
5.5 KiB
C++
Raw Normal View History

2022-01-04 18:11:48 +08:00
#include "controlvolumemanual.h"
#include "ui_controlvolumemanual.h"
2022-08-25 18:37:24 +08:00
#include <QMessageBox>
2022-01-04 18:11:48 +08:00
#include <QJsonObject>
#include <QJsonDocument>
#include <globaldefine.h>
2022-08-25 18:37:24 +08:00
#include "tools.h"
extern QWidget *gMainWin;
2022-01-04 18:11:48 +08:00
ControlVolumeManual::ControlVolumeManual(QWidget *parent,QList<LedCard *> *list) :
QWidget(parent),
ui(new Ui::ControlVolumeManual)
{
ui->setupUi(this);
refreshLable();
2022-08-25 18:37:24 +08:00
setStyleSheet(Tools::styleSheet());
2022-01-04 18:11:48 +08:00
onSelectedDeviceList(list);
ui->horizontalSlider->setRange(0,15);
ui->horizontalSlider->setTickPosition(QSlider::TicksAbove);
ui->pushButtonReadback->setProperty("ssType", "progManageTool");
connect(ui->pushButtonReadback,SIGNAL(clicked()),this,SLOT(OnReadback()));
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->labelCurValue, SLOT(setNum(int)));
connect(ui->horizontalSlider, SIGNAL(sliderReleased()), this, SLOT(setVolumeValue()));
MARCO_DEFINE_CONTROL_FUNC2(parent->parent()->parent(),parent->parent())
}
ControlVolumeManual::~ControlVolumeManual()
{
delete ui;
if(pHpptClient != nullptr)
{
qDebug() <<"delete pHpptClient in ~NetComm";
delete pHpptClient;
pHpptClient=nullptr;
}
if(pHpptClientAll != nullptr)
{
qDebug() <<"delete pHpptClientAll in ~NetComm";
delete pHpptClientAll;
pHpptClientAll=nullptr;
}
}
void ControlVolumeManual::setVolumeValue()
{
2022-08-25 18:37:24 +08:00
CHECK_CARD_SELECTED
2022-01-04 18:11:48 +08:00
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "SetVolume");
json.insert("volume", ui->labelCurValue->text().toInt());
MACRO_DEFINE_TIPDLG_FUCN(tr("SetVolume"),tr("Success"),tr("failed"))
}
void ControlVolumeManual::refreshLable()
{
ui->labelVolume->setText(tr("Volume(min:0-max:15)"));
ui->pushButtonReadback->setText(tr("Readback"));
}
void ControlVolumeManual::OnReadback()
{
2022-08-25 18:37:24 +08:00
CHECK_CARD_SELECTED
2022-01-04 18:11:48 +08:00
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetVolume");
MACRO_DEFINE_TIPDLG_FUCN(tr("GetVolume"),tr("Success"),tr("failed"))
}
void ControlVolumeManual::onSelectedDeviceList(QList<LedCard*> *list)
{
m_pLedlist=list;
MACRO_DEFINE_CONTROL_FUNC3
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlVolumeManual::OnProHttpResponse(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
2022-08-25 18:37:24 +08:00
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
2022-01-04 18:11:48 +08:00
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
qDebug()<<m_pLedCard->m_strCardId +"---------"+ strType;
if(strType == "SetVolume")
{
//emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetBrightness")+":"+tr("success"));
}
else if(strType == "GetVolume"){
int itempVolume=jsonObject["volume"].toInt();
ui->horizontalSlider->setValue(itempVolume);
ui->labelCurValue->setNum(itempVolume);
}
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlVolumeManual::OnProHttpResponseAll(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
2022-08-25 18:37:24 +08:00
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
2022-01-04 18:11:48 +08:00
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
qDebug()<<m_pLedCard->m_strCardId +"---------"+ strType;
if(strType == "GetVolume"){
int itempVolume=jsonObject["volume"].toInt();
ui->horizontalSlider->setValue(itempVolume);
ui->labelCurValue->setNum(itempVolume);
}
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
void ControlVolumeManual::OnControlTypeSwitchIndexChanged(int index)
{
2022-08-25 18:37:24 +08:00
if(index==Setting_Volume)
2022-01-04 18:11:48 +08:00
{
m_bSelected=true;
if(m_pLedCard!=nullptr)
onReadbackAllThisPage();
}
else {
m_bSelected=false;
}
}
void ControlVolumeManual::onReadbackAllThisPage()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()!=1)
return;
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetVolume");
HttpPostByTypeJsonObject(pHpptClientAll,m_strUrl,json);
MACRO_DEFINE_TIPDLG_ALL_FUCN(tr("Readback"),tr("Success"),tr("failed"))
}
void ControlVolumeManual::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}