qt/ledset/expertsmartpointsetwin.cpp

567 lines
18 KiB
C++
Raw Normal View History

2022-08-25 18:43:03 +08:00
#include "expertsmartpointsetwin.h"
2022-09-08 23:22:59 +08:00
#include "gqt.h"
2022-08-25 18:43:03 +08:00
#include <QStackedLayout>
#include <QLabel>
#include <QRadioButton>
#include <QPushButton>
#include <QButtonGroup>
2022-08-25 22:52:52 +08:00
#include <QHeaderView>
2022-09-08 23:22:59 +08:00
#include <QMessageBox>
#include <QLineEdit>
#include <QApplication>
#include <QFileDialog>
2022-09-09 23:25:49 +08:00
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
2022-09-08 23:22:59 +08:00
2022-08-25 18:43:03 +08:00
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);
2022-08-25 22:52:52 +08:00
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);
2022-09-09 23:25:49 +08:00
fdModuleWidth->setValue(ModuleWidth);
2022-08-25 22:52:52 +08:00
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);
2022-09-09 23:25:49 +08:00
fdModuleHeight->setValue(ModuleHeight);
2022-08-25 22:52:52 +08:00
hhhh->addWidget(fdModuleHeight);
vvv->addLayout(hhhh);
vvv->addSpacing(30);
hhhh = new QHBoxLayout;
lb = new QLabel("数据组数: ");
hhhh->addWidget(lb);
2022-09-09 23:25:49 +08:00
fdGroupNum = new QSpinBox;
fdGroupNum->setRange(0, 9999);
fdGroupNum->setValue(GroupNum);
hhhh->addWidget(fdGroupNum);
2022-08-25 22:52:52 +08:00
vvv->addLayout(hhhh);
vvv->addStretch();
hBox->addLayout(vvv);
}
hBox->addStretch();
{
auto vvv = new QVBoxLayout;
auto hhhh = new QHBoxLayout;
lb = new QLabel("驱动芯片: ");
hhhh->addWidget(lb);
2022-09-09 23:25:49 +08:00
fdChipType = new QComboBox;
fdChipType->addItem("ICND2153");
hhhh->addWidget(fdChipType);
2022-08-25 22:52:52 +08:00
vvv->addLayout(hhhh);
vvv->addSpacing(30);
hhhh = new QHBoxLayout;
lb = new QLabel("译码方式: ");
hhhh->addWidget(lb);
2022-09-09 23:25:49 +08:00
fdDecodeMode = new QComboBox;
2022-08-25 22:52:52 +08:00
fdDecodeMode->addItem("138译码");
hhhh->addWidget(fdDecodeMode);
vvv->addLayout(hhhh);
vvv->addSpacing(30);
hhhh = new QHBoxLayout;
lb = new QLabel("分组方式: ");
hhhh->addWidget(lb);
2022-09-09 23:25:49 +08:00
fdGroupMode = new QComboBox;
fdGroupMode->addItem("三线并行");
fdGroupMode->addItem("三色1点串");
fdGroupMode->addItem("三色8点串");
fdGroupMode->addItem("三色16点串");
hhhh->addWidget(fdGroupMode);
2022-08-25 22:52:52 +08:00
vvv->addLayout(hhhh);
vvv->addStretch();
hBox->addLayout(vvv);
}
hBox->addStretch();
vBox->addLayout(hBox);
}
page = new QWidget;
stack->addWidget(page);
2022-08-25 18:43:03 +08:00
{
auto vBox = new QVBoxLayout(page);
2022-08-25 22:52:52 +08:00
vBox->setContentsMargins(50, 50, 6, 6);
2022-08-25 18:43:03 +08:00
auto lb = new QLabel("扫描行数");
2022-08-25 22:52:52 +08:00
lb->setPalette(bkBlue);
2022-08-25 18:43:03 +08:00
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);
2022-08-25 22:52:52 +08:00
vBox->setContentsMargins(50, 50, 6, 6);
2022-08-25 18:43:03 +08:00
auto lb = new QLabel("数据线颜色");
2022-08-25 22:52:52 +08:00
lb->setPalette(bkBlue);
2022-08-25 18:43:03 +08:00
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");
2022-09-07 23:10:35 +08:00
fdSta1->setChecked(true);
2022-08-25 18:43:03 +08:00
hhhh->addWidget(fdSta1);
hhhh->addStretch();
auto fdR1 = new QRadioButton("");
2022-09-07 23:10:35 +08:00
fdR1->setChecked(true);
2022-08-25 18:43:03 +08:00
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("绿");
2022-09-07 23:10:35 +08:00
fdG2->setChecked(true);
2022-08-25 18:43:03 +08:00
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("");
2022-09-07 23:10:35 +08:00
fdB3->setChecked(true);
2022-08-25 18:43:03 +08:00
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);
}
2022-08-25 22:52:52 +08:00
page = new QWidget;
stack->addWidget(page);
{
auto vBox = new QVBoxLayout(page);
vBox->setContentsMargins(0,0,0,0);
auto hhh = new QHBoxLayout;
2022-09-06 23:40:02 +08:00
auto btnUndo = new QPushButton("回撤");
btnUndo->setMinimumSize(90, 30);
connect(btnUndo, &QPushButton::clicked, this, [this] {
2022-09-07 23:10:35 +08:00
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;
}
}
2022-09-06 23:40:02 +08:00
}
2022-09-07 23:10:35 +08:00
tableRow->setColumnCount(lastIdx);
2022-09-06 23:40:02 +08:00
});
hhh->addWidget(btnUndo);
2022-08-25 22:52:52 +08:00
2022-09-07 23:10:35 +08:00
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);
2022-09-08 23:22:59 +08:00
auto btnOK = new QPushButton("完成");
btnOK->setMinimumSize(90, 30);
connect(btnOK, &QPushButton::clicked, this, &ExpertSmartPointSetWin::save);
hhh->addWidget(btnOK);
2022-08-25 22:52:52 +08:00
hhh->addStretch();
vBox->addLayout(hhh);
table = new PointTable;
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
2022-09-07 23:10:35 +08:00
table->setSelectionMode(QTableWidget::SingleSelection);
2022-08-25 22:52:52 +08:00
table->horizontalHeader()->setDefaultSectionSize(40);
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
table->verticalHeader()->setMinimumWidth(40);
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
2022-09-06 23:40:02 +08:00
connect(table, &QTableWidget::currentCellChanged, this, [this](int row, int col) {
if(row < 0) return;
auto item = table->item(row, col);
if(item) return;
2022-09-09 23:25:49 +08:00
if(scans.isEmpty()) {
2022-09-08 23:22:59 +08:00
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);
2022-09-09 23:25:49 +08:00
if(realCnt==ModuleWidth) {
scans.append({col, row});
2022-09-08 23:22:59 +08:00
QMessageBox::information(this, "提示", "列走完");
}
2022-09-09 23:25:49 +08:00
} else if(scans.size() < ScanNum) {
scans.append({col, row});
auto size = scans.size();
2022-09-08 23:22:59 +08:00
item = new QTableWidgetItem("S"+QString::number(size));
table->setItem(row, col, item);
2022-09-09 23:25:49 +08:00
if(size==ScanNum) {
2022-09-08 23:22:59 +08:00
QMessageBox::information(this, "提示", "行走完");
save();
}
}
2022-08-25 22:52:52 +08:00
});
vBox->addWidget(table);
2022-09-07 23:10:35 +08:00
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);
2022-08-25 22:52:52 +08:00
}
2022-08-25 18:43:03 +08:00
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] {
2022-08-25 22:52:52 +08:00
auto idx = stack->currentIndex();
stack->setCurrentIndex(--idx);
2022-09-08 23:22:59 +08:00
btnPrev->setEnabled(idx > 0);
btnNext->setEnabled(idx < stack->count()-1);
2022-08-25 18:43:03 +08:00
});
2022-08-25 22:52:52 +08:00
connect(btnNext, &QPushButton::clicked, this, [this, stack, btnPrev, btnNext] {
auto idx = stack->currentIndex();
if(idx==0) {
2022-09-09 23:25:49 +08:00
ModuleWidth = fdModuleWidth->value();
ModuleHeight = fdModuleHeight->value();
GroupNum = fdGroupNum->value();
ScanNum = (ModuleHeight + 1) / GroupNum;
ChipType = fdChipType->currentText();
DecodeMode = fdDecodeMode->currentText();
GroupMode = fdGroupMode->currentText();
2022-08-25 22:52:52 +08:00
} else if(idx==2) {
2022-09-09 23:25:49 +08:00
table->setColumnCount(ModuleWidth);
table->setRowCount(ModuleHeight);
2022-08-25 22:52:52 +08:00
}
stack->setCurrentIndex(++idx);
2022-09-08 23:22:59 +08:00
btnPrev->setEnabled(idx > 0);
btnNext->setEnabled(idx < stack->count()-1);
2022-08-25 18:43:03 +08:00
});
auto btnCcl = new QPushButton("取消");
btnCcl->setMinimumSize(90, 30);
hBox->addWidget(btnCcl);
hBox->addSpacing(30);
}
2022-09-08 23:22:59 +08:00
void ExpertSmartPointSetWin::save() {
2022-09-09 23:25:49 +08:00
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; i<tableRow->columnCount(); 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() {
2022-09-08 23:22:59 +08:00
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("文件名称: "));
2022-09-09 23:25:49 +08:00
hBox->addWidget(new QLineEdit(QString("1X2_3扫").arg(ModuleWidth).arg(ModuleHeight).arg(ScanNum)));
2022-09-08 23:22:59 +08:00
vBox->addSpacing(20);
hBox = new HBox(vBox);
hBox->addWidget(new QLabel("保存路径: "));
2022-09-09 23:25:49 +08:00
auto dir = QApplication::applicationDirPath()+"/ModuleFiles";
QDir(dir).mkpath(".");
auto fdDir = new QLineEdit(dir);
fdDir->setMinimumWidth(400);
hBox->addWidget(fdDir);
2022-09-08 23:22:59 +08:00
auto btnChoose = new QPushButton("选择路径");
2022-09-09 23:25:49 +08:00
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);
2022-09-08 23:22:59 +08:00
});
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();
}