#include "ctrltestpanel.h" #include "tools.h" #include "gutil/qgui.h" #include "gutil/qnetwork.h" #include "gutil/qwaitingdlg.h" #include #include #include #include #include "main.h" #include #include #include CtrlTestPanel::CtrlTestPanel() { auto vBox = new VBox(this); labelTestScreen = new QLabel; labelTestScreen->setAlignment(Qt::AlignCenter); vBox->addWidget(labelTestScreen); auto hBox = new HBox(vBox); auto vv = new VBox(hBox); groupBox = new QGroupBox; auto vvv = new VBox(groupBox); auto hhh = new HBox(vvv); hhh->addStretch(); radioButtonRed = new QRadioButton; hhh->addWidget(radioButtonRed); radioButtonGreen = new QRadioButton; hhh->addWidget(radioButtonGreen); radioButtonBlue = new QRadioButton; hhh->addWidget(radioButtonBlue); radioButtonWhite = new QRadioButton; hhh->addWidget(radioButtonWhite); hhh->addStretch(); hhh = new HBox(vvv); hhh->addStretch(); checkBoxVertical = new QCheckBox; hhh->addWidget(checkBoxVertical); checkBoxSlash = new QCheckBox; hhh->addWidget(checkBoxSlash); checkBoxHorizontal = new QCheckBox; hhh->addWidget(checkBoxHorizontal); hhh->addStretch(); hhh = new HBox(vvv); hhh->addStretch(); label = new QLabel; hhh->addWidget(label); spinBoxLineSpeed = new QSpinBox; spinBoxLineSpeed->setMaximum(99999); hhh->addWidget(spinBoxLineSpeed); label_5 = new QLabel; hhh->addWidget(label_5); hhh->addSpacing(20); label_2 = new QLabel; hhh->addWidget(label_2); spinBoxLineDistance = new QSpinBox; spinBoxLineDistance->setMaximum(128); hhh->addWidget(spinBoxLineDistance); label_6 = new QLabel; hhh->addWidget(label_6); hhh->addStretch(); pushButtonStartLine = new QPushButton; pushButtonStartLine->setMinimumSize(QSize(60, 30)); pushButtonStartLine->setMaximumSize(QSize(80, 16777215)); vvv->addWidget(pushButtonStartLine, 0, Qt::AlignHCenter); vv->addWidget(groupBox); groupBox_2 = new QGroupBox; vvv = new VBox(groupBox_2); checkBoxShowInfo = new QCheckBox; vvv->addWidget(checkBoxShowInfo, 0, Qt::AlignLeft); hhh = new HBox(vvv); hhh->addStretch(); checkBox_red = new QCheckBox; hhh->addWidget(checkBox_red); checkBox_green = new QCheckBox; hhh->addWidget(checkBox_green); checkBox_blue = new QCheckBox; hhh->addWidget(checkBox_blue); checkBox_white = new QCheckBox; hhh->addWidget(checkBox_white); hhh->addStretch(); hhh = new HBox(vvv); hhh->addStretch(); label_3 = new QLabel; hhh->addWidget(label_3); spinBoxGraySpeed = new QSpinBox; spinBoxGraySpeed->setMinimumSize(QSize(60, 0)); spinBoxGraySpeed->setMinimum(10); spinBoxGraySpeed->setMaximum(99999); hhh->addWidget(spinBoxGraySpeed); label_8 = new QLabel; hhh->addWidget(label_8); label_4 = new QLabel; hhh->addWidget(label_4); spinBoxGrayValue = new QSpinBox; spinBoxGrayValue->setMaximum(255); hhh->addWidget(spinBoxGrayValue); label_7 = new QLabel; hhh->addWidget(label_7); hhh->addStretch(); pushButtonStartGray = new QPushButton; pushButtonStartGray->setMinimumSize(QSize(60, 30)); pushButtonStartGray->setMaximumSize(QSize(80, 16777215)); vvv->addWidget(pushButtonStartGray, 0, Qt::AlignHCenter); vv->addWidget(groupBox_2); groupBox_3 = new QGroupBox; vvv = new VBox(groupBox_3); checkBoxGradient = new QCheckBox; vvv->addWidget(checkBoxGradient); hhh = new HBox(vvv); hhh->addStretch(); radioButton_red = new QRadioButton; hhh->addWidget(radioButton_red); radioButton_Green = new QRadioButton; hhh->addWidget(radioButton_Green); radioButton_Blue = new QRadioButton; hhh->addWidget(radioButton_Blue); radioButton_White = new QRadioButton; hhh->addWidget(radioButton_White); hhh->addStretch(); pushButtonStartColor = new QPushButton; pushButtonStartColor->setMinimumSize(QSize(60, 30)); pushButtonStartColor->setMaximumSize(QSize(80, 16777215)); vvv->addWidget(pushButtonStartColor, 0, Qt::AlignHCenter); vv->addWidget(groupBox_3); hhh = new HBox(vv); hhh->addStretch(); btnStopTest = new QPushButton; btnStopTest->setMinimumSize(QSize(60, 30)); hhh->addWidget(btnStopTest); hhh->addStretch(); vv->addStretch(); auto line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); hBox->addWidget(line); hBox->addStretch(); vv = new VBox(hBox); fdAnycast = new QLineEdit; fdAnycast->setValidator(new QIntValidator(0, 100, this)); fdAnycast->setMinimumHeight(36); fdAnycast->setStyleSheet("color: #0f0; background: #000;"); fdAnycast->setAlignment(Qt::AlignCenter); vv->addWidget(fdAnycast); auto gridLayout = new Grid(vv); auto btngrp = new QButtonGroup(this); for(int i=0; i<10; ++i) { auto btn = new QPushButton(QString::number(i)); btn->setFixedSize(60, 30); btn->setProperty("ssType", "progManageTool"); btngrp->addButton(btn, i); } gridLayout->addWidget(btngrp->button(1), 0, 0); gridLayout->addWidget(btngrp->button(2), 0, 1); gridLayout->addWidget(btngrp->button(3), 0, 2); gridLayout->addWidget(btngrp->button(4), 1, 0); gridLayout->addWidget(btngrp->button(5), 1, 1); gridLayout->addWidget(btngrp->button(6), 1, 2); gridLayout->addWidget(btngrp->button(7), 2, 0); gridLayout->addWidget(btngrp->button(8), 2, 1); gridLayout->addWidget(btngrp->button(9), 2, 2); gridLayout->addWidget(btngrp->button(0), 3, 0); connect(btngrp, &QButtonGroup::idClicked, this, [=](int id) { if(fdAnycast->text().contains("-")) fdAnycast->clear(); fdAnycast->setText(fdAnycast->text() + QString::number(id)); btnAnycast->setEnabled(true); }); btnAnycastClear = new QPushButton; btnAnycastClear->setFixedSize(60, 30); btnAnycastClear->setProperty("ssType", "progManageTool"); connect(btnAnycastClear, &QPushButton::clicked, this, [=] { fdAnycast->clear(); btnAnycast->setEnabled(false); }); gridLayout->addWidget(btnAnycastClear, 3, 1, 1, 1); btnAnycastReset = new QPushButton; btnAnycastReset->setFixedSize(60, 30); btnAnycastReset->setProperty("ssType", "progManageTool"); connect(btnAnycastReset, &QPushButton::clicked, this, [=] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } SendAnycastCmd(0); fdAnycast->setText("- "+tr("Loop Mode")+" -"); btnAnycast->setEnabled(false); }); gridLayout->addWidget(btnAnycastReset, 3, 2, 1, 1); btnAnycast = new QPushButton; btnAnycast->setEnabled(false); btnAnycast->setMinimumHeight(36); btnAnycast->setProperty("ssType", "progManageTool"); connect(btnAnycast, &QPushButton::clicked, this, [=] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } SendAnycastCmd(fdAnycast->text().toInt()); fdAnycast->setText(tr("Anycast")+" - "+fdAnycast->text()); btnAnycast->setEnabled(false); }); vv->addWidget(btnAnycast); vv->addStretch(); hBox->addStretch(); vBox->addStretch(); pushButtonStartLine->setProperty("ssType", "progManageTool"); pushButtonStartGray->setProperty("ssType", "progManageTool"); pushButtonStartColor->setProperty("ssType", "progManageTool"); btnStopTest->setProperty("ssType", "progManageTool"); spinBoxLineSpeed->setValue(10); spinBoxLineDistance->setValue(15); spinBoxGraySpeed->setValue(10); spinBoxGrayValue->setValue(0); radioButtonWhite->setChecked(true); radioButton_White->setChecked(true); checkBoxHorizontal->setChecked(true); checkBoxVertical->setChecked(true); checkBoxSlash->setChecked(true); checkBox_red->setChecked(true); checkBox_green->setChecked(true); checkBox_blue->setChecked(true); checkBox_white->setChecked(true); connect(pushButtonStartLine, &QPushButton::clicked, this, [this] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "TestScreen"); json.insert("_type", "TestScreen"); json.insert("mode", 1);// 0:停止; 1:斜线; 2:灰度; 3:颜色;4:渐变 json.insert("speed", spinBoxLineSpeed->value()); if(radioButtonRed->isChecked()) json.insert("color", "#FFFF0000"); else if(radioButtonGreen->isChecked()) json.insert("color", "#FF00FF00"); else if(radioButtonBlue->isChecked()) json.insert("color", "#FF0000FF"); else json.insert("color", "#FFFFFFFF"); json.insert("interval", spinBoxLineDistance->value()); json.insert("horizonalLine", checkBoxHorizontal->isChecked()); json.insert("verticalLine", checkBoxVertical->isChecked()); json.insert("slantLine", checkBoxSlash->isChecked()); json.insert("runLimit", spinBoxGrayValue->value()); json.insert("showInfo", !checkBoxShowInfo->isChecked()); json.insert("red", checkBox_red->isChecked()); json.insert("green", checkBox_green->isChecked()); json.insert("blue", checkBox_blue->isChecked()); json.insert("white", checkBox_white->isChecked()); if(gSelCards.count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ..."); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [=] { Def_CtrlSetReqAfter }); } else { foreach(auto card, gSelCards) { Def_CtrlSetMulti(tr("StartTest")) } } }); connect(pushButtonStartGray, &QPushButton::clicked, this, [this] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "TestScreen"); json.insert("_type", "TestScreen"); json.insert("mode", 2);// 0:停止; 1:斜线; 2:灰度; 3:颜色;4:渐变 json.insert("speed", spinBoxGraySpeed->value()); if(radioButtonRed->isChecked()) json.insert("color", "#FFFF0000"); else if(radioButtonGreen->isChecked()) json.insert("color", "#FF00FF00"); else if(radioButtonBlue->isChecked()) json.insert("color", "#FF0000FF"); else json.insert("color", "#FFFFFFFF"); json.insert("interval", spinBoxLineDistance->value()); json.insert("horizonalLine", checkBoxHorizontal->isChecked()); json.insert("verticalLine", checkBoxVertical->isChecked()); json.insert("slantLine", checkBoxSlash->isChecked()); json.insert("runLimit", spinBoxGrayValue->value()); json.insert("showInfo", !checkBoxShowInfo->isChecked()); json.insert("red", checkBox_red->isChecked()); json.insert("green", checkBox_green->isChecked()); json.insert("blue", checkBox_blue->isChecked()); json.insert("white", checkBox_white->isChecked()); if(gSelCards.count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ..."); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [=] { Def_CtrlSetReqAfter }); } else { foreach(auto card, gSelCards) { Def_CtrlSetMulti(tr("StartTest")) } } }); connect(pushButtonStartColor, &QPushButton::clicked, this, [this] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "TestScreen"); json.insert("_type", "TestScreen"); json.insert("mode", checkBoxGradient->isChecked() ? 4 : 3);// 0:停止; 1:斜线; 2:灰度; 3:颜色;4:渐变 json.insert("speed", spinBoxLineSpeed->value()); if(radioButton_red->isChecked()) json.insert("color", "#FFFF0000"); else if(radioButton_Green->isChecked()) json.insert("color", "#FF00FF00"); else if(radioButton_Blue->isChecked()) json.insert("color", "#FF0000FF"); else json.insert("color", "#FFFFFFFF"); json.insert("interval", spinBoxLineDistance->value()); json.insert("horizonalLine", checkBoxHorizontal->isChecked()); json.insert("verticalLine", checkBoxVertical->isChecked()); json.insert("slantLine", checkBoxSlash->isChecked()); json.insert("runLimit", spinBoxGrayValue->value()); json.insert("showInfo", !checkBoxShowInfo->isChecked()); json.insert("red", checkBox_red->isChecked()); json.insert("green", checkBox_green->isChecked()); json.insert("blue", checkBox_blue->isChecked()); json.insert("white", checkBox_white->isChecked()); if(gSelCards.count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ..."); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [=] { Def_CtrlSetReqAfter }); } else { foreach(auto card, gSelCards) { Def_CtrlSetMulti(tr("StartTest")) } } }); connect(btnStopTest, &QPushButton::clicked, this, [this] { if(gSelCards.isEmpty()) { QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); return; } QJsonObject json; json.insert("_id", "TestScreen"); json.insert("_type", "TestScreen"); json.insert("mode", 0); if(gSelCards.count() == 1) { auto waitingDlg = new WaitingDlg(this, tr("StopTest")+" ..."); Def_CtrlReqPre connect(reply, &QNetworkReply::finished, this, [=] { Def_CtrlSetReqAfter }); } else { foreach(auto card, gSelCards) { Def_CtrlSetMulti(tr("StopTest")) } } }); transUi(); } void CtrlTestPanel::changeEvent(QEvent *event) { QWidget::changeEvent(event); if(event->type() == QEvent::LanguageChange) transUi(); } void CtrlTestPanel::transUi() { labelTestScreen->setText(tr("Test Screen")); groupBox->setTitle(tr("Line test")); radioButtonRed->setText(tr("Red")); radioButtonGreen->setText(tr("Green")); radioButtonBlue->setText(tr("Blue")); radioButtonWhite->setText(tr("White")); radioButton_red->setText(tr("Red")); radioButton_Green->setText(tr("Green")); radioButton_Blue->setText(tr("Blue")); radioButton_White->setText(tr("White")); checkBoxVertical->setText(tr("Vertical")); checkBoxHorizontal->setText(tr("Horizontal")); checkBoxSlash->setText(tr("Slash")); label->setText(tr("Speed")); label_5->setText(tr("ms(>10)")); checkBoxHorizontal->setText(tr("Horizontal")); label_2->setText(tr("Line Distance")); pushButtonStartLine->setText(tr("Test")); groupBox_2->setTitle(tr("Gradation test")); checkBoxShowInfo->setText(tr("Only the gray value is displayed")); checkBox_red->setText(tr("Red")); checkBox_green->setText(tr("Green")); checkBox_blue->setText(tr("Blue")); checkBox_white->setText(tr("White")); label_3->setText(tr("Speed")); label_4->setText(tr("GrayValue")); pushButtonStartGray->setText(tr("Test")); pushButtonStartColor->setText(tr("Test")); groupBox_3->setTitle(tr("Color test")); checkBoxGradient->setText(tr("Gradient")); radioButton_red->setText(tr("Red")); radioButton_Green->setText(tr("Green")); radioButton_Blue->setText(tr("Blue")); radioButton_White->setText(tr("White")); btnStopTest->setText(tr("Stop")); btnAnycastClear->setText(tr("Clear")); btnAnycastReset->setText(tr("Reset")); btnAnycast->setText(tr("Anycast")); } void CtrlTestPanel::SendAnycastCmd(int progIdx) { ST_ANSY_PROGRAM_PACKET tempStreadPakcet; tempStreadPakcet.ucCommType = 0x97; tempStreadPakcet.iBaoLiu = 0; tempStreadPakcet.iLength = 4; unsigned char uctemp[4] = {0}; uctemp[0] = progIdx; memcpy(tempStreadPakcet.pDataBuffer, uctemp, 4); tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength] = GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength)); int iLenPacket = 3*sizeof(unsigned char) + sizeof(char) + sizeof(int) + sizeof(int) + tempStreadPakcet.iLength + sizeof(char); //除正文外的协议结构大小; auto data = QByteArray(reinterpret_cast(&tempStreadPakcet), iLenPacket); auto action = progIdx==0 ? tr("Reset loop mode") : tr("Anycast"); if(gSelCards.count() == 1) { auto waitingDlg = new WaitingDlg(this, action+" ..."); waitingDlg->show(); auto card = gSelCards[0]; auto tcp = new TcpSocket; connect(waitingDlg, &WaitingDlg::rejected, tcp, [=] { tcp->abort(); tcp->deleteLater(); }); connect(tcp, &QTcpSocket::connected, tcp, [=] { tcp->stopTimer(); tcp->write(data); tcp->startTimer(10000); }); connect(tcp, &QTcpSocket::readyRead, tcp, [=] { tcp->stopTimer(); tcp->close(); tcp->deleteLater(); waitingDlg->success(); }); connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) { tcp->close(); tcp->deleteLater(); waitingDlg->close(); QMessageBox::critical(this, tr("Tip"), QString(socketErrKey(err))+" ("+QString::number(err)+") "+tcp->errorString()); }); tcp->connectToHost(card.ip, 31299); tcp->startTimer(10000); } else { for(auto &card : gSelCards) { auto tcp = new TcpSocket; auto cardId = card.id; connect(tcp, &QTcpSocket::connected, tcp, [=] { tcp->stopTimer(); tcp->write(data); tcp->startTimer(10000); }); connect(tcp, &QTcpSocket::readyRead, tcp, [=] { tcp->stopTimer(); tcp->close(); tcp->deleteLater(); gFdResInfo->append(cardId+" "+action+" "+tr("Success")); }); connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) { tcp->close(); tcp->deleteLater(); gFdResInfo->append(cardId+" "+action+" "+socketErrKey(err)+" ("+QString::number(err)+") "+tcp->errorString()); }); tcp->connectToHost(card.ip, 31299); tcp->startTimer(10000); } } }