#include "expertsmartpointsetwin.h" #include "gqt.h" #include #include #include #include #include #include #include #include #include #include #include #include #include ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent} { setWindowModality(Qt::WindowModal); setAttribute(Qt::WA_DeleteOnClose); setWindowTitle("智能走点参数配置"); resize(900, 600); auto vBox = new QVBoxLayout(center); vBox->setContentsMargins(0,0,0,0); vBox->setSpacing(3); vBox->addLayout(addBtns(new QHBoxLayout())); auto stack = new QStackedLayout; vBox->addLayout(stack); auto page = new QWidget; stack->addWidget(page); QPalette bkBlue; { auto vBox = new QVBoxLayout(page); vBox->setContentsMargins(50, 50, 6, 6); auto lb = new QLabel("基本参数"); bkBlue = lb->palette(); bkBlue.setColor(QPalette::WindowText, QColor(0x5599ff)); lb->setPalette(bkBlue); vBox->addWidget(lb); vBox->addSpacing(50); auto hBox = new QHBoxLayout; hBox->addStretch(); { auto vvv = new QVBoxLayout; auto hhhh = new QHBoxLayout; lb = new QLabel("模组宽度: "); hhhh->addWidget(lb); fdModuleWidth = new QSpinBox; fdModuleWidth->setRange(0, 9999); fdModuleWidth->setValue(ModuleWidth); hhhh->addWidget(fdModuleWidth); vvv->addLayout(hhhh); vvv->addSpacing(30); hhhh = new QHBoxLayout; lb = new QLabel("模组高度: "); hhhh->addWidget(lb); fdModuleHeight = new QSpinBox; fdModuleHeight->setRange(0, 9999); fdModuleHeight->setValue(ModuleHeight); hhhh->addWidget(fdModuleHeight); vvv->addLayout(hhhh); vvv->addSpacing(30); hhhh = new QHBoxLayout; lb = new QLabel("数据组数: "); hhhh->addWidget(lb); fdGroupNum = new QSpinBox; fdGroupNum->setRange(0, 9999); fdGroupNum->setValue(GroupNum); hhhh->addWidget(fdGroupNum); vvv->addLayout(hhhh); vvv->addStretch(); hBox->addLayout(vvv); } hBox->addStretch(); { auto vvv = new QVBoxLayout; auto hhhh = new QHBoxLayout; lb = new QLabel("驱动芯片: "); hhhh->addWidget(lb); fdChipType = new QComboBox; fdChipType->addItem("ICND2153"); hhhh->addWidget(fdChipType); vvv->addLayout(hhhh); vvv->addSpacing(30); hhhh = new QHBoxLayout; lb = new QLabel("译码方式: "); hhhh->addWidget(lb); fdDecodeMode = new QComboBox; fdDecodeMode->addItem("138译码"); hhhh->addWidget(fdDecodeMode); vvv->addLayout(hhhh); vvv->addSpacing(30); hhhh = new QHBoxLayout; lb = new QLabel("分组方式: "); hhhh->addWidget(lb); fdGroupMode = new QComboBox; fdGroupMode->addItem("三线并行"); fdGroupMode->addItem("三色1点串"); fdGroupMode->addItem("三色8点串"); fdGroupMode->addItem("三色16点串"); hhhh->addWidget(fdGroupMode); vvv->addLayout(hhhh); vvv->addStretch(); hBox->addLayout(vvv); } hBox->addStretch(); vBox->addLayout(hBox); } page = new QWidget; stack->addWidget(page); { auto vBox = new QVBoxLayout(page); vBox->setContentsMargins(50, 50, 6, 6); auto lb = new QLabel("扫描行数"); lb->setPalette(bkBlue); vBox->addWidget(lb); vBox->addSpacing(50); auto hBox = new QHBoxLayout; vBox->addLayout(hBox); hBox->addStretch(); auto vvv = new QVBoxLayout; hBox->addLayout(vvv); lb = new QLabel("根据亮线的行/列数确定扫描行/列数: "); vvv->addWidget(lb); vvv->addSpacing(30); auto hhhh = new QHBoxLayout; hhhh->addStretch(); auto fdRow = new QRadioButton("行"); hhhh->addWidget(fdRow); hhhh->addStretch(); auto fdCol = new QRadioButton("列"); hhhh->addWidget(fdCol); hhhh->addStretch(); vvv->addLayout(hhhh); vvv->addSpacing(20); hhhh = new QHBoxLayout; hhhh->addStretch(); lb = new QLabel("亮线的行/列数: "); hhhh->addWidget(lb); auto fdNum = new QSpinBox; fdNum->setRange(0, 9999); fdNum->setValue(1); hhhh->addWidget(fdNum); hhhh->addStretch(); vvv->addLayout(hhhh); vvv->addStretch(); hBox->addStretch(); vvv = new QVBoxLayout; hBox->addLayout(vvv); lb = new QLabel("芯片245版本: "); vvv->addWidget(lb); vvv->addSpacing(30); hhhh = new QHBoxLayout; hhhh->addStretch(); auto fdA = new QRadioButton("A"); hhhh->addWidget(fdA); hhhh->addStretch(); auto fdD = new QRadioButton("D"); hhhh->addWidget(fdD); hhhh->addStretch(); vvv->addLayout(hhhh); vvv->addStretch(); hBox->addStretch(); } page = new QWidget; stack->addWidget(page); { auto vBox = new QVBoxLayout(page); vBox->setContentsMargins(50, 50, 6, 6); auto lb = new QLabel("数据线颜色"); lb->setPalette(bkBlue); vBox->addWidget(lb); vBox->addSpacing(50); lb = new QLabel("依次点击以下状态, 根据模组颜色选择对应颜色"); vBox->addWidget(lb, 0, Qt::AlignCenter); vBox->addSpacing(30); auto hhhh = new QHBoxLayout; hhhh->addStretch(); auto fdSta1 = new QRadioButton("状态1"); fdSta1->setChecked(true); hhhh->addWidget(fdSta1); hhhh->addStretch(); auto fdR1 = new QRadioButton("红"); fdR1->setChecked(true); hhhh->addWidget(fdR1); hhhh->addSpacing(20); auto fdG1 = new QRadioButton("绿"); hhhh->addWidget(fdG1); hhhh->addSpacing(20); auto fdB1 = new QRadioButton("蓝"); hhhh->addWidget(fdB1); hhhh->addSpacing(20); auto fdNo1 = new QRadioButton("黑"); hhhh->addWidget(fdNo1); hhhh->addStretch(); vBox->addLayout(hhhh); vBox->addSpacing(20); hhhh = new QHBoxLayout; hhhh->addStretch(); auto fdSta2 = new QRadioButton("状态2"); hhhh->addWidget(fdSta2); hhhh->addStretch(); auto fdR2 = new QRadioButton("红"); hhhh->addWidget(fdR2); hhhh->addSpacing(20); auto fdG2 = new QRadioButton("绿"); fdG2->setChecked(true); hhhh->addWidget(fdG2); hhhh->addSpacing(20); auto fdB2 = new QRadioButton("蓝"); hhhh->addWidget(fdB2); hhhh->addSpacing(20); auto fdNo2 = new QRadioButton("黑"); hhhh->addWidget(fdNo2); hhhh->addStretch(); vBox->addLayout(hhhh); vBox->addSpacing(20); hhhh = new QHBoxLayout; hhhh->addStretch(); auto fdSta3 = new QRadioButton("状态3"); hhhh->addWidget(fdSta3); hhhh->addStretch(); auto fdR3 = new QRadioButton("红"); hhhh->addWidget(fdR3); hhhh->addSpacing(20); auto fdG3 = new QRadioButton("绿"); hhhh->addWidget(fdG3); hhhh->addSpacing(20); auto fdB3 = new QRadioButton("蓝"); fdB3->setChecked(true); hhhh->addWidget(fdB3); hhhh->addSpacing(20); auto fdNo3 = new QRadioButton("黑"); hhhh->addWidget(fdNo3); hhhh->addStretch(); vBox->addLayout(hhhh); vBox->addStretch(); auto btnGrp = new QButtonGroup(page); btnGrp->addButton(fdR1); btnGrp->addButton(fdG1); btnGrp->addButton(fdB1); btnGrp->addButton(fdNo1); btnGrp = new QButtonGroup(page); btnGrp->addButton(fdR2); btnGrp->addButton(fdG2); btnGrp->addButton(fdB2); btnGrp->addButton(fdNo2); btnGrp = new QButtonGroup(page); btnGrp->addButton(fdR3); btnGrp->addButton(fdG3); btnGrp->addButton(fdB3); btnGrp->addButton(fdNo3); } page = new QWidget; stack->addWidget(page); { auto vBox = new QVBoxLayout(page); vBox->setContentsMargins(0,0,0,0); auto hhh = new QHBoxLayout; auto btnUndo = new QPushButton("回撤"); btnUndo->setMinimumSize(90, 30); connect(btnUndo, &QPushButton::clicked, this, [this] { auto lastIdx = tableRow->columnCount()-1; if(lastIdx==-1) return; auto last = tableRow->item(1, lastIdx); if(last->text()=="×") { virtualCnt--; } else { auto point = last->data(Qt::UserRole).toPoint(); table->setItem(point.y(), point.x(), 0); if(lastIdx==virtualCnt) table->selectionModel()->clearCurrentIndex(); else { for(int i=lastIdx-1; i>-1; i--) { auto item = tableRow->item(1, i); if(item->text()=="×") continue; auto point = item->data(Qt::UserRole).toPoint(); table->setCurrentCell(point.y(), point.x()); break; } } } tableRow->setColumnCount(lastIdx); }); hhh->addWidget(btnUndo); auto btnAddVoid = new QPushButton("插入虚点"); btnAddVoid->setMinimumSize(90, 30); connect(btnAddVoid, &QPushButton::clicked, this, [this] { virtualCnt++; auto cnt = tableRow->columnCount(); tableRow->setColumnCount(cnt+1); tableRow->setItem(0, cnt, new QTableWidgetItem(QString::number(cnt+1))); auto item = new QTableWidgetItem("×"); tableRow->setItem(1, cnt, item); }); hhh->addWidget(btnAddVoid); auto btnReset = new QPushButton("重新走点"); btnReset->setMinimumSize(90, 30); connect(btnReset, &QPushButton::clicked, this, [this] { table->clearContents(); tableRow->setColumnCount(0); virtualCnt = 0; }); hhh->addWidget(btnReset); auto btnOK = new QPushButton("完成"); btnOK->setMinimumSize(90, 30); connect(btnOK, &QPushButton::clicked, this, &ExpertSmartPointSetWin::save); hhh->addWidget(btnOK); hhh->addStretch(); vBox->addLayout(hhh); table = new PointTable; table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setSelectionMode(QTableWidget::SingleSelection); table->horizontalHeader()->setDefaultSectionSize(40); table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); table->verticalHeader()->setMinimumWidth(40); table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter); connect(table, &QTableWidget::currentCellChanged, this, [this](int row, int col) { if(row < 0) return; auto item = table->item(row, col); if(item) return; if(scans.isEmpty()) { auto cnt = tableRow->columnCount() + 1; tableRow->setColumnCount(cnt); tableRow->setItem(0, cnt-1, new QTableWidgetItem(QString::number(cnt))); item = new QTableWidgetItem("√"); item->setData(Qt::UserRole, QPoint{col, row}); tableRow->setItem(1, cnt-1, item); auto realCnt = cnt - virtualCnt; item = new QTableWidgetItem(QString::number(realCnt)); table->setItem(row, col, item); if(realCnt==ModuleWidth) { scans.append({col, row}); QMessageBox::information(this, "提示", "列走完"); } } else if(scans.size() < ScanNum) { scans.append({col, row}); auto size = scans.size(); item = new QTableWidgetItem("S"+QString::number(size)); table->setItem(row, col, item); if(size==ScanNum) { QMessageBox::information(this, "提示", "行走完"); save(); } } }); vBox->addWidget(table); tableRow = new PointTable(2, 0); tableRow->setEditTriggers(QAbstractItemView::NoEditTriggers); tableRow->setSelectionMode(QTableWidget::NoSelection); tableRow->horizontalHeader()->setDefaultSectionSize(40); tableRow->horizontalHeader()->setVisible(false); tableRow->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); tableRow->verticalHeader()->setMinimumWidth(120); tableRow->setMaximumHeight(80); auto item = tableRow->verticalHeaderItem(0); if(item==0) tableRow->setVerticalHeaderItem(0, item = new QTableWidgetItem()); item->setText("第一扫灯数:"); item = tableRow->verticalHeaderItem(1); if(item==0) tableRow->setVerticalHeaderItem(1, item = new QTableWidgetItem()); item->setText("实: 虚:"); vBox->addWidget(tableRow); } auto hBox = new QHBoxLayout; vBox->addLayout(hBox); hBox->addStretch(); auto btnPrev = new QPushButton("上一步"); btnPrev->setMinimumSize(90, 30); hBox->addWidget(btnPrev); auto btnNext = new QPushButton("下一步"); btnNext->setMinimumSize(90, 30); hBox->addWidget(btnNext); connect(btnPrev, &QPushButton::clicked, this, [stack, btnPrev, btnNext] { auto idx = stack->currentIndex(); stack->setCurrentIndex(--idx); btnPrev->setEnabled(idx > 0); btnNext->setEnabled(idx < stack->count()-1); }); connect(btnNext, &QPushButton::clicked, this, [this, stack, btnPrev, btnNext] { auto idx = stack->currentIndex(); if(idx==0) { ModuleWidth = fdModuleWidth->value(); ModuleHeight = fdModuleHeight->value(); GroupNum = fdGroupNum->value(); ScanNum = (ModuleHeight + 1) / GroupNum; ChipType = fdChipType->currentText(); DecodeMode = fdDecodeMode->currentText(); GroupMode = fdGroupMode->currentText(); } else if(idx==2) { table->setColumnCount(ModuleWidth); table->setRowCount(ModuleHeight); } stack->setCurrentIndex(++idx); btnPrev->setEnabled(idx > 0); btnNext->setEnabled(idx < stack->count()-1); }); auto btnCcl = new QPushButton("取消"); btnCcl->setMinimumSize(90, 30); hBox->addWidget(btnCcl); hBox->addSpacing(30); } void ExpertSmartPointSetWin::save() { auto file = QFileDialog::getSaveFileName(this, "保存文件", QApplication::applicationDirPath()+QString("/ModuleFiles/1X2_3扫.module").arg(ModuleWidth).arg(ModuleHeight).arg(ScanNum)); if(file.isEmpty()) return; QFile qFile(file); if(! qFile.open(QFile::WriteOnly)) return; QJsonObject obj; obj.insert("ModuleWidth", ModuleWidth); obj.insert("ModuleHeight", ModuleHeight); obj.insert("GroupNum", GroupNum); obj.insert("ScanNum", ScanNum); obj.insert("ChipType", ChipType); obj.insert("DecodeMode", DecodeMode); obj.insert("GroupMode", GroupMode); QJsonArray Points; for(int i=0; icolumnCount(); i++) { auto data = tableRow->item(1, i)->data(Qt::UserRole); if(! data.isValid()) Points.append(-1); Points.append(data.toPoint().x()); } obj.insert("Points", Points); QJsonArray Scans; foreach(QPoint scan, scans) Scans.append(scan.y()); obj.insert("Scans", Scans); qFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented)); qFile.close(); QMessageBox::information(this, "保存成功", "保存成功"); } void ExpertSmartPointSetWin::save2() { auto dlg = new BaseDlg(this); dlg->setWindowTitle("保存设置"); auto vBox = new VBox(dlg->center); vBox->setContentsMargins(0,0,0,0); auto hBox = new HBox(vBox); dlg->addBtns(hBox); vBox->addSpacing(20); hBox = new HBox(vBox); hBox->addWidget(new QLabel("文件名称: ")); hBox->addWidget(new QLineEdit(QString("1X2_3扫").arg(ModuleWidth).arg(ModuleHeight).arg(ScanNum))); vBox->addSpacing(20); hBox = new HBox(vBox); hBox->addWidget(new QLabel("保存路径: ")); auto dir = QApplication::applicationDirPath()+"/ModuleFiles"; QDir(dir).mkpath("."); auto fdDir = new QLineEdit(dir); fdDir->setMinimumWidth(400); hBox->addWidget(fdDir); auto btnChoose = new QPushButton("选择路径"); connect(btnChoose, &QPushButton::clicked, this, [this, fdDir] { QFileInfo info(fdDir->text()); QFileDialog dlg(this, "选择存储文件的目录", info.path()); auto font = dlg.font(); font.setPixelSize(12); dlg.setFont(font); dlg.setFileMode(QFileDialog::Directory); dlg.setOptions(QFileDialog::ShowDirsOnly); dlg.selectFile(info.fileName()); dlg.exec(); auto dir = dlg.selectedFiles(); if(! dir.isEmpty()) fdDir->setText(dir[0]); //auto dir = QFileDialog::getExistingDirectory(this, "选择存储文件的目录", fdDir->text()); //if(! dir.isEmpty()) fdDir->setText(dir); }); hBox->addWidget(btnChoose); vBox->addSpacing(20); hBox = new HBox(vBox); hBox->addStretch(); auto btnOK = new QPushButton("完成"); btnOK->setMinimumSize(90, 30); connect(btnOK, &QPushButton::clicked, dlg, &BaseDlg::accept); hBox->addWidget(btnOK); auto btnBack = new QPushButton("返回"); btnBack->setMinimumSize(90, 30); connect(btnBack, &QPushButton::clicked, dlg, &BaseDlg::reject); hBox->addWidget(btnBack); dlg->exec(); }