qt/LedOK/wDevicesManager/controlvolumemanual.cpp
2022-08-25 18:37:24 +08:00

185 lines
5.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "controlvolumemanual.h"
#include "ui_controlvolumemanual.h"
#include <QMessageBox>
#include <QJsonObject>
#include <QJsonDocument>
#include <globaldefine.h>
#include "tools.h"
extern QWidget *gMainWin;
ControlVolumeManual::ControlVolumeManual(QWidget *parent,QList<LedCard *> *list) :
QWidget(parent),
ui(new Ui::ControlVolumeManual)
{
ui->setupUi(this);
refreshLable();
setStyleSheet(Tools::styleSheet());
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()
{
CHECK_CARD_SELECTED
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()
{
CHECK_CARD_SELECTED
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
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
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
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
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)
{
if(index==Setting_Volume)
{
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;
}
}