194 lines
7.5 KiB
C++
194 lines
7.5 KiB
C++
#include <qwidget.h>
|
|
#include <qlabel.h>
|
|
#include <qpushbutton.h>
|
|
#include <qobject.h>
|
|
#include <uiModule/components/fancyButton.h>
|
|
#include <qlayout.h>
|
|
#include <qspinbox.h>
|
|
#include <appCore.hpp>
|
|
#include <generalJsonParsing.hpp>
|
|
#include <uiModule/components/enterPasswdWindow.h>
|
|
class _952BiaoDingSwitch : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
QLabel CurrentModeLabel;
|
|
fancyButtonText NormalBtn, BiaoDingBtn;
|
|
fancyButtonText SaveBtn,RestoreBtn;
|
|
QGridLayout mainLayout;
|
|
QLabel OutOffsetLabel, InnerOffsetLabel;
|
|
QDoubleSpinBox* OutDoubleSpinBox,* InnerDoubleSpinBox, *_3dThresholdSpinBox;
|
|
nlohmann::json JsonObj;
|
|
QLabel _3dSignLabel, _2dSignLabel, _3dThresholdLabel;
|
|
enterPasswdWindow _enterPasswdWindow;//密码窗口
|
|
_952BiaoDingSwitch()
|
|
: NormalBtn(180, 30, "一般模式", "一般模式")
|
|
, BiaoDingBtn(180, 30, "标定模式", "标定模式")
|
|
, mainLayout(this)
|
|
, SaveBtn(180, 30, "保存&应用", "保存&应用")
|
|
, RestoreBtn(180, 30, "还原", "还原")
|
|
{
|
|
|
|
QPalette palette;
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
QFont font("微软雅黑", 14, QFont::Bold);
|
|
//
|
|
_3dSignLabel.setText("参数设置");
|
|
_3dSignLabel.setPalette(palette);
|
|
_3dSignLabel.setFont(font);
|
|
mainLayout.addWidget(&_3dSignLabel, 0, 0);
|
|
//
|
|
QHBoxLayout* btnLayout = new QHBoxLayout;
|
|
btnLayout->setContentsMargins(0, 0, 0, 0);
|
|
btnLayout->setAlignment(Qt::AlignLeft);
|
|
btnLayout->addWidget(&NormalBtn);
|
|
btnLayout->addWidget(&BiaoDingBtn);
|
|
mainLayout.addLayout(btnLayout, 1, 0);
|
|
//按钮互斥
|
|
NormalBtn.toGreen();
|
|
QObject::connect(&NormalBtn, &QPushButton::clicked, this, [=]()
|
|
{
|
|
NormalBtn.toGreen();
|
|
BiaoDingBtn.toDefault();
|
|
switchToNormal();
|
|
});
|
|
QObject::connect(&BiaoDingBtn, &QPushButton::clicked, this, [=]()
|
|
{
|
|
BiaoDingBtn.toGreen();
|
|
NormalBtn.toDefault();
|
|
switchToBiaoDing();
|
|
});
|
|
//
|
|
_2dSignLabel.setText("");
|
|
_2dSignLabel.setPalette(palette);
|
|
_2dSignLabel.setFont(font);
|
|
mainLayout.addWidget(&_2dSignLabel, 2, 0);
|
|
//参数输入
|
|
QHBoxLayout* OutOffsetLayout = new QHBoxLayout;
|
|
OutDoubleSpinBox = new QDoubleSpinBox(this);
|
|
OutDoubleSpinBox->setStyleSheet("QDoubleSpinBox::up-button, QDoubleSpinBox::down-button { width: 0; height: 0; border: none; }");
|
|
OutDoubleSpinBox->setRange(0.0, 100.0); // 设置最小值和最大值
|
|
OutDoubleSpinBox->setDecimals(2); // 设置小数点后的位数
|
|
OutDoubleSpinBox->setFont(font);
|
|
//OutDoubleSpinBox->setValue(1.5); // 设置初始值
|
|
OutOffsetLabel.setText("外侧焊印直径(mm)");
|
|
OutOffsetLabel.setPalette(palette);
|
|
OutOffsetLabel.setFont(font);
|
|
OutOffsetLayout->addWidget(&OutOffsetLabel);
|
|
OutOffsetLayout->addWidget(OutDoubleSpinBox);
|
|
mainLayout.addLayout(OutOffsetLayout, 3, 0);
|
|
|
|
QHBoxLayout* InnerOffsetLayout = new QHBoxLayout;
|
|
InnerDoubleSpinBox = new QDoubleSpinBox(this);
|
|
InnerDoubleSpinBox->setStyleSheet("QDoubleSpinBox::up-button, QDoubleSpinBox::down-button { width: 0; height: 0; border: none; }");
|
|
InnerDoubleSpinBox->setRange(0.0, 100.0); // 设置最小值和最大值
|
|
InnerDoubleSpinBox->setDecimals(2); // 设置小数点后的位数
|
|
InnerDoubleSpinBox->setFont(font);
|
|
InnerOffsetLabel.setText("内侧焊印直径(mm)");
|
|
InnerOffsetLabel.setPalette(palette);
|
|
InnerOffsetLabel.setFont(font);
|
|
InnerOffsetLayout->addWidget(&InnerOffsetLabel);
|
|
InnerOffsetLayout->addWidget(InnerDoubleSpinBox);
|
|
mainLayout.addLayout(InnerOffsetLayout, 4, 0);
|
|
|
|
QHBoxLayout* _3dThresholdLayout = new QHBoxLayout;
|
|
_3dThresholdSpinBox = new QDoubleSpinBox(this);
|
|
_3dThresholdSpinBox->setStyleSheet("QDoubleSpinBox::up-button, QDoubleSpinBox::down-button { width: 0; height: 0; border: none; }");
|
|
_3dThresholdSpinBox->setRange(0.0, 100.0); // 设置最小值和最大值
|
|
_3dThresholdSpinBox->setDecimals(2); // 设置小数点后的位数
|
|
_3dThresholdSpinBox->setFont(font);
|
|
_3dThresholdLabel.setText("点胶高度阈值(mm)");
|
|
_3dThresholdLabel.setPalette(palette);
|
|
_3dThresholdLabel.setFont(font);
|
|
_3dThresholdLayout->addWidget(&_3dThresholdLabel);
|
|
_3dThresholdLayout->addWidget(_3dThresholdSpinBox);
|
|
mainLayout.addLayout(_3dThresholdLayout, 5, 0);
|
|
|
|
//参数保存
|
|
QHBoxLayout* btnLayout2 = new QHBoxLayout;
|
|
btnLayout2->setContentsMargins(0, 0, 0, 0);
|
|
btnLayout2->setAlignment(Qt::AlignLeft);
|
|
btnLayout2->addWidget(&SaveBtn);
|
|
QObject::connect(&SaveBtn, &QPushButton::clicked, this, [=]()
|
|
{
|
|
_enterPasswdWindow.show();
|
|
});
|
|
QObject::connect(&_enterPasswdWindow, &enterPasswdWindow::okSignal, this, [=]()
|
|
{
|
|
saveConfig();
|
|
// 设置按钮显示√
|
|
SaveBtn.setText("√");
|
|
SaveBtn.toGreen();
|
|
QTimer::singleShot(1000, [=]() mutable {
|
|
// 一秒后还原文本
|
|
SaveBtn.toDefault();
|
|
SaveBtn.setText("保存&应用");
|
|
});
|
|
});
|
|
|
|
btnLayout2->addWidget(&RestoreBtn);
|
|
QObject::connect(&RestoreBtn, &QPushButton::clicked, this, [=]()
|
|
{
|
|
restore();
|
|
});
|
|
mainLayout.addLayout(btnLayout2, 6, 0);//
|
|
//加载json并设置默认值
|
|
try
|
|
{
|
|
JsonObj = readJsonFromPath("./config/_952BiaoDingSwitchConfig.json");
|
|
int JsonMode = JsonObj["mode"];
|
|
double JsonOutOffset = JsonObj["in_OutOffset"];
|
|
double JsonInnerOffset = JsonObj["in_InnerOffset"];
|
|
double Json3dThreshold = JsonObj["_3d_threshold"];
|
|
if (JsonMode == 1)
|
|
BiaoDingBtn.click();
|
|
OutDoubleSpinBox->setValue(JsonOutOffset);
|
|
InnerDoubleSpinBox->setValue(JsonInnerOffset);
|
|
_3dThresholdSpinBox->setValue(Json3dThreshold);
|
|
//QMutexLocker locker(&_core._appConfig.__952BiaoDingSwitchData.mutex);
|
|
//_core._appConfig.__952BiaoDingSwitchData.modeIn = JsonMode;
|
|
//_core._appConfig.__952BiaoDingSwitchData.in_OutOffset = JsonOutOffset;
|
|
//_core._appConfig.__952BiaoDingSwitchData.in_InnerOffset = JsonInnerOffset;
|
|
//_core._appConfig.__952BiaoDingSwitchData._3d_threshold = Json3dThreshold;
|
|
}
|
|
catch (...)
|
|
{
|
|
std::cout << "err load json@_952BiaoDingSwitchConfig" << std::endl;
|
|
}
|
|
};
|
|
void switchToBiaoDing()
|
|
{
|
|
//QMutexLocker locker(&_core._appConfig.__952BiaoDingSwitchData.mutex);
|
|
//_core._appConfig.__952BiaoDingSwitchData.modeIn = 1;
|
|
//JsonObj["mode"] = 1;
|
|
//saveJsonFromPath("./config/_952BiaoDingSwitchConfig.json", JsonObj);
|
|
}
|
|
void switchToNormal()
|
|
{
|
|
//QMutexLocker locker(&_core._appConfig.__952BiaoDingSwitchData.mutex);
|
|
//_core._appConfig.__952BiaoDingSwitchData.modeIn = 0;
|
|
//JsonObj["mode"] = 0;
|
|
//saveJsonFromPath("./config/_952BiaoDingSwitchConfig.json", JsonObj);
|
|
}
|
|
void saveConfig()
|
|
{
|
|
//QMutexLocker locker(&_core._appConfig.__952BiaoDingSwitchData.mutex);
|
|
//_core._appConfig.__952BiaoDingSwitchData.in_OutOffset = OutDoubleSpinBox->value();
|
|
//_core._appConfig.__952BiaoDingSwitchData.in_InnerOffset = InnerDoubleSpinBox->value();
|
|
//_core._appConfig.__952BiaoDingSwitchData._3d_threshold = _3dThresholdSpinBox->value();
|
|
//JsonObj["in_OutOffset"] = _core._appConfig.__952BiaoDingSwitchData.in_OutOffset;
|
|
//JsonObj["in_InnerOffset"] = _core._appConfig.__952BiaoDingSwitchData.in_InnerOffset;
|
|
//JsonObj["_3d_threshold"] = _core._appConfig.__952BiaoDingSwitchData._3d_threshold;
|
|
//saveJsonFromPath("./config/_952BiaoDingSwitchConfig.json", JsonObj);
|
|
//qDebug() << "_952BiaoDingSwitch-ValueChanged:in_OutOffset->" << _core._appConfig.__952BiaoDingSwitchData.in_OutOffset
|
|
// << " | in_InnerOffset->" << _core._appConfig.__952BiaoDingSwitchData.in_InnerOffset;
|
|
}
|
|
void restore()
|
|
{
|
|
//QMutexLocker locker(&_core._appConfig.__952BiaoDingSwitchData.mutex);
|
|
//OutDoubleSpinBox->setValue(_core._appConfig.__952BiaoDingSwitchData.in_OutOffset);
|
|
//InnerDoubleSpinBox->setValue(_core._appConfig.__952BiaoDingSwitchData.in_InnerOffset);
|
|
}
|
|
private:
|
|
};
|
|
#pragma once |