#include "ctrlbrightpanel.h" #include "base/waitingdlg.h" #include "globaldefine.h" #include "deviceitem.h" #include "tools.h" #include "LoUIClass/x_timeeditdelegate.h" #include "xlsxdocument.h" #include #include #include #include #include #include #include #include CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) { auto vBox = new QVBoxLayout(this); vBox->setContentsMargins(0,0,0,0); vBox->addSpacing(8); lbBrightCfg = new QLabel; lbBrightCfg->setAlignment(Qt::AlignCenter); vBox->addWidget(lbBrightCfg); auto hBox = new QHBoxLayout(); hBox->addStretch(); radioAuto = new QRadioButton(); radioAuto->setChecked(true); hBox->addWidget(radioAuto); hBox->addSpacing(40); radioManual = new QRadioButton(); hBox->addWidget(radioManual); hBox->addSpacing(40); radioSchedule = new QRadioButton(); hBox->addWidget(radioSchedule); hBox->addStretch(); vBox->addLayout(hBox); auto line = new QFrame; line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); vBox->addWidget(line); auto autoPanel = new QWidget(); { auto vBox = new QVBoxLayout(autoPanel); fdBrightTip = new QLabel; fdBrightTip->setAlignment(Qt::AlignCenter); fdBrightTip->setWordWrap(true); vBox->addWidget(fdBrightTip); auto hBox = new QHBoxLayout; hBox->addStretch(); lbSensi = new QLabel; lbSensi->setMinimumWidth(120); lbSensi->setAlignment(Qt::AlignRight | Qt::AlignVCenter); hBox->addWidget(lbSensi); fdSensi = new QSlider(Qt::Horizontal); fdSensi->setRange(1, 100); hBox->addWidget(fdSensi); auto lbSensiValue = new QLabel(QString::number(fdSensi->value())+"%"); lbSensiValue->setMinimumWidth(40); lbSensiValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); connect(fdSensi, &QSlider::valueChanged, lbSensiValue, [lbSensiValue](int value) { lbSensiValue->setText(QString::number(value)+"%"); }); hBox->addWidget(lbSensiValue); btnSensiSet = new QPushButton; btnSensiSet->setMinimumSize(60, 30); btnSensiSet->setProperty("ssType", "progManageTool"); connect(btnSensiSet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "SetBrightnessSensitivity"); json.insert("_type", "SetBrightnessSensitivity"); json.insert("sensitivity", fdSensi->value()); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("SetBrightnessSensitivity")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { Def_CtrlSetReqAfter }); } else { foreach(auto card, *gSelCards) { Def_CtrlSetMulti(tr("SetBrightnessSensitivity")) } } }); hBox->addWidget(btnSensiSet); btnSensiGet = new QPushButton; btnSensiGet->setMinimumSize(60, 30); btnSensiGet->setProperty("ssType", "progManageTool"); connect(btnSensiGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "GetBrightnessSensitivity"); json.insert("_type", "GetBrightnessSensitivity"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetBrightnessSensitivity")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { Def_CtrlSingleGetReply waitingDlg->success(); fdSensi->setValue(json["sensitivity"].toInt()); }); } else { foreach(auto card, *gSelCards) { auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); if(err.isEmpty()) err = QString::number(json["sensitivity"].toInt()); gFdResInfo->append(card->m_strCardId+" "+tr("GetBrightnessSensitivity")+" "+err); }); } } }); hBox->addWidget(btnSensiGet); hBox->addStretch(); vBox->addLayout(hBox); hBox = new QHBoxLayout; hBox->addStretch(); lbMinBright = new QLabel; lbMinBright->setMinimumWidth(120); lbMinBright->setAlignment(Qt::AlignRight | Qt::AlignVCenter); hBox->addWidget(lbMinBright); fdMinBright = new QSlider(Qt::Horizontal); fdMinBright->setRange(1, 100); hBox->addWidget(fdMinBright); auto lbMinBrightValue = new QLabel(QString::number(fdMinBright->value())+"%"); lbMinBrightValue->setMinimumWidth(40); lbMinBrightValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); connect(fdMinBright, &QSlider::valueChanged, lbSensiValue, [lbMinBrightValue](int value) { lbMinBrightValue->setText(QString::number(value)+"%"); }); hBox->addWidget(lbMinBrightValue); btnMinBrightSet = new QPushButton; btnMinBrightSet->setMinimumSize(60, 30); btnMinBrightSet->setProperty("ssType", "progManageTool"); connect(btnMinBrightSet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "SetMinBrightness"); json.insert("_type", "SetMinBrightness"); auto brightPercent = fdMinBright->value(); if(gSelCards->count() == 1) { json.insert("brightness", (brightPercent * gSelCards->at(0)->BrightnessLevel + 50) / 100); auto waitingDlg = new WaitingDlg(this, tr("SetMinBrightness")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { Def_CtrlSetReqAfter }); } else { foreach(auto card, *gSelCards) { json.insert("brightness", (brightPercent * card->BrightnessLevel + 50) / 100); Def_CtrlSetMulti(tr("SetMinBrightness")); } } }); hBox->addWidget(btnMinBrightSet); btnMinBrightGet = new QPushButton; btnMinBrightGet->setMinimumSize(60, 30); btnMinBrightGet->setProperty("ssType", "progManageTool"); connect(btnMinBrightGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "GetMinBrightness"); json.insert("_type", "GetMinBrightness"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetMinBrightness")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { Def_CtrlSingleGetReply waitingDlg->success(); fdMinBright->setValue(qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel)); }); } else { foreach(auto card, *gSelCards) { auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); gFdResInfo->append(card->m_strCardId+" "+tr("GetMinBrightness")+" "+(err.isEmpty()?QString::number(qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel))+"%":err)); }); } } }); hBox->addWidget(btnMinBrightGet); hBox->addStretch(); vBox->addLayout(hBox); line = new QFrame; line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); vBox->addWidget(line); fdSensiTypeTip = new QLabel; fdSensiTypeTip->setAlignment(Qt::AlignCenter); fdSensiTypeTip->setWordWrap(true); vBox->addWidget(fdSensiTypeTip); hBox = new QHBoxLayout; hBox->addStretch(); radioButton_2 = new QRadioButton("R68/RL3"); hBox->addWidget(radioButton_2); radioButton = new QRadioButton("RL2"); hBox->addWidget(radioButton); hBox->addSpacing(20); btnUpload = new QPushButton; btnUpload->setMinimumSize(60, 30); btnUpload->setProperty("ssType", "progManageTool"); connect(btnUpload, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QString strSensorType; if(radioButton->isChecked()) strSensorType = radioButton->text(); else if(radioButton_2->isChecked()) strSensorType = radioButton_2->text(); else { QMessageBox::information(gMainWin, tr("Tip"), tr("NeedSelectSensorTypeTip")); return; } QString xlsxFile = QFileDialog::getOpenFileName(this, "open file dialog", "/", "brightness files(*.xlsx)"); if(xlsxFile.isEmpty() || ! QFileInfo::exists(xlsxFile)) return; QXlsx::Document xlsx(xlsxFile); xlsx.selectSheet(strSensorType); QJsonArray values; for(int j=0; j<255; j++) values.append(xlsx.read(3,j+3).toString()); QJsonObject json; json.insert("_id", "SensorBrightnessTable"); json.insert("_type", "SensorBrightnessTable"); json.insert("values", values); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("SensorBrightnessTable")); Def_CtrlReqPre; connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { Def_CtrlSetReqAfter; }); } else { foreach(auto card, *gSelCards) { Def_CtrlSetMulti(tr("SensorBrightnessTable")); } } }); hBox->addWidget(btnUpload); btnTableGet = new QPushButton(); btnTableGet->setMinimumSize(60, 30); btnTableGet->setProperty("ssType", "progManageTool"); connect(btnTableGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QString strSensorType; if(radioButton->isChecked()) strSensorType = radioButton->text(); else if(radioButton_2->isChecked()) strSensorType = radioButton_2->text(); else { QMessageBox::information(gMainWin, tr("Tip"), tr("NeedSelectSensorTypeTip")); return; } QJsonObject json; json.insert("_id", "GetSensorBrightnessTable"); json.insert("_type", "GetSensorBrightnessTable"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetSensorBrightnessTable")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card, strSensorType] { Def_CtrlSingleGetReply waitingDlg->close(); QStringList values = json["values"].toVariant().value(); if(values.isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("no sensorBrightnessTable")); return; } QString btbFile = QCoreApplication::applicationDirPath()+"/Btb"; QFile btbQFile(btbFile); if(! btbQFile.exists()) { QMessageBox::information(gMainWin, tr("Tip"), btbFile+" is not exist"); return; } QString selectFilter = "*.xlsx"; QString savingFile = QFileDialog::getSaveFileName(this, tr("Save file"), card->m_strCardId + "BrightnessTable.xlsx", "brightness(*.xlsx );", &selectFilter, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if(savingFile.isEmpty()) return; btbQFile.copy(savingFile); QXlsx::Document xlsx(savingFile); xlsx.selectSheet(strSensorType); for(int m=0; maddWidget(btnTableGet); hBox->addStretch(); vBox->addLayout(hBox); hBox = new QHBoxLayout; hBox->addStretch(); lbCurBright = new QLabel; hBox->addWidget(lbCurBright); fdCurBright = new QLabel; hBox->addWidget(fdCurBright); btnCurBrightGet = new QPushButton; btnCurBrightGet->setMinimumSize(60, 30); btnCurBrightGet->setProperty("ssType", "progManageTool"); connect(btnCurBrightGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "GetCurrentSensorBrightness"); json.insert("_type", "GetCurrentSensorBrightness"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetCurrentSensorBrightness")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { Def_CtrlSingleGetReply waitingDlg->success(); if(json["is485"].toBool()) radioButton_2->setChecked(true); else radioButton->setChecked(true); fdCurBright->setText(QString::number(qRound(json["value"].toInt() * 100.0 / card->BrightnessLevel))+"%"); }); } else { foreach(auto card, *gSelCards) { auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); gFdResInfo->append(card->m_strCardId+" "+tr("GetCurrentSensorBrightness")+" "+QString::number(qRound(json["value"].toInt() * 100.0 / card->BrightnessLevel))+"%"); }); } } }); hBox->addWidget(btnCurBrightGet); hBox->addStretch(); vBox->addLayout(hBox); vBox->addStretch(); } auto manualPanel = new QWidget; { auto vBox = new QVBoxLayout(manualPanel); auto hBox = new QHBoxLayout; hBox->addStretch(); lbFixedBright = new QLabel; hBox->addWidget(lbFixedBright); fdFixedBright = new QSlider(Qt::Horizontal); fdFixedBright->setRange(1, 100); hBox->addWidget(fdFixedBright); auto lbBrightValue = new QLabel(QString::number(fdFixedBright->value())+"%"); lbBrightValue->setMinimumWidth(40); lbBrightValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); connect(fdFixedBright, &QSlider::valueChanged, lbBrightValue, [lbBrightValue](int value) { lbBrightValue->setText(QString::number(value)+"%"); }); hBox->addWidget(lbBrightValue); hBox->addStretch(); vBox->addLayout(hBox); vBox->addSpacing(20); hBox = new QHBoxLayout; hBox->addStretch(); btnFixedSet = new QPushButton; btnFixedSet->setMinimumSize(60, 30); btnFixedSet->setProperty("ssType", "progManageTool"); connect(btnFixedSet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "SetBrightness"); json.insert("_type", "SetBrightness"); auto percent = fdFixedBright->value(); if(gSelCards->count() == 1) { json.insert("brightness", (percent * gSelCards->at(0)->BrightnessLevel + 50) / 100); auto waitingDlg = new WaitingDlg(this, tr("SetBrightness")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { Def_CtrlSetReqAfter }); } else { foreach(auto card, *gSelCards) { json.insert("brightness", (percent * card->BrightnessLevel + 50) / 100); Def_CtrlSetMulti(tr("SetBrightness")) } } }); hBox->addWidget(btnFixedSet); btnFixedGet = new QPushButton; btnFixedGet->setMinimumSize(60, 30); btnFixedGet->setProperty("ssType", "progManageTool"); connect(btnFixedGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "GetBrightness"); json.insert("_type", "GetBrightness"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetBrightness")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { Def_CtrlSingleGetReply waitingDlg->success(); card->brightness = json["brightness"].toInt(); fdFixedBright->setValue(qRound(card->brightness * 100.0 / card->BrightnessLevel)); }); } else { foreach(auto card, *gSelCards) { auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); gFdResInfo->append(card->m_strCardId+" "+tr("Brightness")+" "+(err.isEmpty()?QString::number(qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel))+"%":err)); }); } } }); hBox->addWidget(btnFixedGet); hBox->addStretch(); vBox->addLayout(hBox); vBox->addStretch(); } auto schedulePanel = new QWidget; { auto hBox = new QHBoxLayout(schedulePanel); hBox->addStretch(); auto vBox = new QVBoxLayout; hBox->addLayout(vBox); hBox->addStretch(); hBox = new QHBoxLayout(); fdScheTip = new QLabel; fdScheTip->setWordWrap(true); hBox->addWidget(fdScheTip); vBox->addLayout(hBox); hBox = new QHBoxLayout(); btnScheAdd = new QPushButton; btnScheAdd->setMinimumSize(60, 30); btnScheAdd->setProperty("ssType", "progManageTool"); connect(btnScheAdd, &QPushButton::clicked, this, [this] { int row = tableSche->rowCount(); tableSche->insertRow(row); auto cellWgt = new QWidget; auto hBox = new QHBoxLayout(cellWgt); auto slider = new QSlider(Qt::Horizontal); slider->setRange(1, 100); hBox->addWidget(slider); auto lb = new QLabel(QString::number(slider->value())+"%"); connect(slider, &QSlider::valueChanged, lb, [lb](int value) { lb->setText(QString::number(value)+"%"); }); hBox->addWidget(lb); tableSche->setCellWidget(row, "bright", cellWgt); auto timeEdit = new QTimeEdit(QTime(0, 0)); timeEdit->setDisplayFormat("HH:mm"); timeEdit->setAlignment(Qt::AlignCenter); tableSche->setCellWidget(row, "start", timeEdit); timeEdit = new QTimeEdit(QTime(1, 0)); timeEdit->setDisplayFormat("HH:mm"); timeEdit->setAlignment(Qt::AlignCenter); tableSche->setCellWidget(row, "end", timeEdit); }); hBox->addWidget(btnScheAdd); btnScheDel = new QPushButton; btnScheDel->setMinimumSize(60, 30); btnScheDel->setProperty("ssType", "progManageTool"); connect(btnScheDel, &QPushButton::clicked, this, [this] { auto selected = tableSche->selectedRanges(); if(! selected.isEmpty()) tableSche->model()->removeRows(selected[0].topRow(), selected[0].rowCount()); }); hBox->addWidget(btnScheDel); btnScheClear = new QPushButton; btnScheClear->setMinimumSize(60, 30); btnScheClear->setProperty("ssType", "progManageTool"); connect(btnScheClear, &QPushButton::clicked, this, [this] {tableSche->setRowCount(0);}); hBox->addWidget(btnScheClear); hBox->addStretch(); lbDefBright = new QLabel; lbDefBright->setAlignment(Qt::AlignRight | Qt::AlignVCenter); lbDefBright->setMinimumWidth(120); hBox->addWidget(lbDefBright); fdDefBright = new QSlider(Qt::Horizontal); fdDefBright->setRange(0, 100); fdDefBright->setValue(100); fdDefBright->setMinimumWidth(120); hBox->addWidget(fdDefBright); auto lbDefBrightValue = new QLabel(QString::number(fdDefBright->value())+"%"); lbDefBrightValue->setMinimumWidth(40); lbDefBrightValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); connect(fdDefBright, &QSlider::valueChanged, lbDefBrightValue, [lbDefBrightValue](int value) { lbDefBrightValue->setText(QString::number(value)+"%"); }); hBox->addWidget(lbDefBrightValue); hBox->addStretch(); btnScheImport = new QPushButton; btnScheImport->setMinimumSize(QSize(60, 30)); btnScheImport->setProperty("ssType", "progManageTool"); connect(btnScheImport, &QPushButton::clicked, this, [this] { auto dir = QSettings().value("CtrlScheduleDir").toString(); if(dir.isEmpty()) dir = "/"; QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("BrightnessSchedule (*.bjs)")); if(scheFile.isEmpty()) return; QFile scheQFile(scheFile); if(! scheQFile.open(QIODevice::ReadOnly)) return; auto data = scheQFile.readAll(); scheQFile.close(); restoreScheduleJson(QJsonDocument::fromJson(data).object()); }); hBox->addWidget(btnScheImport); btnScheExport = new QPushButton; btnScheExport->setMinimumSize(QSize(60, 30)); btnScheExport->setProperty("ssType", "progManageTool"); connect(btnScheExport, &QPushButton::clicked, this, [this] { QSettings settings; auto dir = settings.value("CtrlScheduleDir").toString(); if(dir.isEmpty()) dir = "/"; QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("BrightnessSchedule (*.bjs)")); if(scheFile.isEmpty()) return; settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath()); QFile scheQFile(scheFile); if(! scheQFile.open(QIODevice::WriteOnly)) return; scheQFile.write(QJsonDocument(getScheduleJson()).toJson()); scheQFile.close(); }); hBox->addWidget(btnScheExport); vBox->addLayout(hBox); tableSche = new Table({ {"bright", tr("BrightnessValue"), 300}, {"start", tr("Start Time"), 100}, {"end", tr("End Time"), 100} }); tableSche->setDefs(); tableSche->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); vBox->addWidget(tableSche); hBox = new QHBoxLayout(); hBox->addStretch(); btnScheSet = new QPushButton; btnScheSet->setMinimumSize(QSize(60, 30)); btnScheSet->setProperty("ssType", "progManageTool"); connect(btnScheSet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "SetAutoBrightnessTask"); json.insert("_type", "SetAutoBrightnessTask"); if(gSelCards->count() == 1) { json.insert("taskBrightness", getScheduleJson(gSelCards->at(0)->BrightnessLevel)); auto waitingDlg = new WaitingDlg(this, tr("SetAutoBrightnessTask")); Def_CtrlReqPre; connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { Def_CtrlSetReqAfter }); } else { foreach(auto card, *gSelCards) { json.insert("taskBrightness", getScheduleJson(card->BrightnessLevel)); Def_CtrlSetMulti(tr("SetAutoBrightnessTask")) } } }); hBox->addWidget(btnScheSet); hBox->addStretch(); btnScheGet = new QPushButton; btnScheGet->setMinimumSize(QSize(60, 30)); btnScheGet->setProperty("ssType", "progManageTool"); connect(btnScheGet, &QPushButton::clicked, this, [this] { if(gSelCards->isEmpty()) { QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "GetAutoBrightnessTask"); json.insert("_type", "GetAutoBrightnessTask"); if(gSelCards->count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("GetAutoBrightnessTask")); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { Def_CtrlSingleGetReply waitingDlg->success(); restoreScheduleJson(json["taskBrightness"].toObject(), card->BrightnessLevel); }); } }); hBox->addWidget(btnScheGet); hBox->addStretch(); vBox->addLayout(hBox); } auto stackBox = new QStackedLayout(vBox); stackBox->addWidget(autoPanel); stackBox->addWidget(manualPanel); stackBox->addWidget(schedulePanel); stackBox->setCurrentIndex(0); auto group = new QButtonGroup; group->addButton(radioAuto, 0); group->addButton(radioManual, 1); group->addButton(radioSchedule, 2); connect(group, &QButtonGroup::idToggled, stackBox, [stackBox](int idx, bool checked) { if(checked) stackBox->setCurrentIndex(idx); }); connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] { if(isVisible()) init(); }); transUi(); } void CtrlBrightPanel::showEvent(QShowEvent *event) { QWidget::showEvent(event); init(); } void CtrlBrightPanel::init() { bool isSingle = gSelCards->count()==1; btnTableGet->setEnabled(isSingle); btnScheGet->setEnabled(isSingle); if(! isSingle) return; auto card = gSelCards->at(0); mSensi = -1; mTask = -1; QJsonObject json; json.insert("_id", "GetAutoBrightnessTask"); json.insert("_type", "GetAutoBrightnessTask"); auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [this, reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); if(! err.isEmpty()) { QMessageBox::critical(gMainWin, tr("Error"), err); return; } mTask = restoreScheduleJson(json["taskBrightness"].toObject(), card->BrightnessLevel); if(mTask) radioSchedule->setChecked(true); else if(mSensi > 0) radioAuto->setChecked(true); else if(mSensi == 0) radioManual->setChecked(true); }); json = QJsonObject(); json.insert("_id", "GetBrightnessSensitivity"); json.insert("_type", "GetBrightnessSensitivity"); reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [this, reply] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); if(! err.isEmpty()) { QMessageBox::critical(gMainWin, tr("Error"), err); return; } mSensi = json["sensitivity"].toInt(); fdSensi->setValue(mSensi); if(mTask != 0) return; if(mSensi > 0) radioAuto->setChecked(true); else radioManual->setChecked(true); }); json = QJsonObject(); json.insert("_id", "GetMinBrightness"); json.insert("_type", "GetMinBrightness"); reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [this, reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); if(! err.isEmpty()) { QMessageBox::critical(gMainWin, tr("Error"), err); return; } fdMinBright->setValue(qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel)); }); json = QJsonObject(); json.insert("_id", "GetBrightness"); json.insert("_type", "GetBrightness"); reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [this, reply, card] { QJsonDocument json; QString err = checkReplyForJson(reply, &json); if(! err.isEmpty()) { QMessageBox::critical(gMainWin, tr("Error"), err); return; } card->brightness = json["brightness"].toInt(); fdFixedBright->setValue(qRound(card->brightness * 100.0 / card->BrightnessLevel)); }); } void CtrlBrightPanel::changeEvent(QEvent *event) { QWidget::changeEvent(event); if(event->type() == QEvent::LanguageChange) transUi(); } void CtrlBrightPanel::transUi() { lbBrightCfg->setText(tr("Brightness Configuration")); radioAuto->setText(tr("Auto")); radioManual->setText(tr("Manual")); radioSchedule->setText(tr("Schedule")); fdBrightTip->setText(tr("BrightTip1")); fdSensiTypeTip->setText(tr("BrightTip2")); lbSensi->setText(tr("Sensitivity")); lbMinBright->setText(tr("Minbrightness")); btnMinBrightSet->setText(tr("Set")); btnSensiSet->setText(tr("Set")); btnUpload->setText(tr("Upload")); btnMinBrightGet->setText(tr("Readback")); btnSensiGet->setText(tr("Readback")); btnTableGet->setText(tr("ReadbackTable")); btnCurBrightGet->setText(tr("Refresh")); lbCurBright->setText(tr("Cur Brigntness")+": "); lbFixedBright->setText(tr("Brightness value")); btnFixedSet->setText(tr("Set")); btnFixedGet->setText(tr("Readback")); lbDefBright->setText(tr("Default brightness")); btnScheAdd->setText(tr("Add")); btnScheClear->setText(tr("Clear")); btnScheDel->setText(tr("Delete")); btnScheImport->setText(tr("Import")); btnScheExport->setText(tr("Export")); btnScheSet->setText(tr("Apply")); btnScheGet->setText(tr("Readback")); fdScheTip->setText(tr("Default brightness tip")); } bool CtrlBrightPanel::restoreScheduleJson(QJsonObject obj, int max) { tableSche->setRowCount(0); fdDefBright->setValue(qRound(obj["defaultBrightness"].toInt() * 100.0 / max)); auto jsitems = obj["items"].toArray(); foreach(auto jsitem, jsitems) { auto schedule = jsitem["schedules"][0]; int row = tableSche->rowCount(); tableSche->insertRow(row); auto cellWgt = new QWidget; auto hBox = new QHBoxLayout(cellWgt); auto slider = new QSlider(Qt::Horizontal); slider->setRange(1, 100); slider->setValue(qRound(jsitem["brightness"].toInt() * 100.0 / max)); hBox->addWidget(slider); auto lb = new QLabel(QString::number(slider->value())+"%"); connect(slider, &QSlider::valueChanged, lb, [lb](int value) { lb->setText(QString::number(value)+"%"); }); hBox->addWidget(lb); tableSche->setCellWidget(row, "bright", cellWgt); auto timeEdit = new QTimeEdit(QTime::fromString(schedule["startTime"].toString(), "HH:mm")); timeEdit->setDisplayFormat("HH:mm"); timeEdit->setAlignment(Qt::AlignCenter); tableSche->setCellWidget(row, "start", timeEdit); timeEdit = new QTimeEdit(QTime::fromString(schedule["endTime"].toString(), "HH:mm")); timeEdit->setDisplayFormat("HH:mm"); timeEdit->setAlignment(Qt::AlignCenter); tableSche->setCellWidget(row, "end", timeEdit); } return jsitems.count() > 0; } QJsonObject CtrlBrightPanel::getScheduleJson(int max) { QJsonObject obj; obj["createDate"] = QJsonValue::Null; obj["createBy"] = "alahover"; obj["name"] = "TimingBrightness"; auto def = (fdDefBright->value() * max + 50) / 100; obj["defaultBrightness"] = def; obj["brightness"] = def; QJsonArray jsItems; for(int i=0; irowCount(); i++) { QJsonObject item; item["brightness"] = (static_cast(tableSche->cellWidget(i, "bright")->layout()->itemAt(0)->widget())->value() * max + 50) / 100; QJsonObject schedule; schedule["timeType"] = "Range"; schedule["startTime"] = static_cast(tableSche->cellWidget(i, "start"))->text(); schedule["endTime"] = static_cast(tableSche->cellWidget(i, "end"))->text(); schedule["dateType"] = "All"; schedule["startDate"] = QJsonValue::Null; schedule["endDate"] = QJsonValue::Null; schedule["monthFilter"] = QJsonArray(); schedule["filterType"] = "None"; schedule["weekFilter"] = QJsonArray(); item["schedules"] = QJsonArray{schedule}; jsItems.append(item); } obj["items"] = jsItems; return obj; }