Files
VX5_KRO_GearPump/CounterVarSet.cpp
T
2026-07-22 11:47:13 +08:00

375 lines
11 KiB
C++

#include "CounterVarSet.h"
#include "ui_countervarset.h"
#include <QDateTime>
#include <QDebug>
#include "scene/PicCounterItem.h"
CounterVarSet::CounterVarSet(QWidget *parent) :
QWidget(parent),
ui(new Ui::CounterVarSet)
{
ui->setupUi(this);
ui->label_35->hide();
ui->spinBoxdecimalpointnum->hide();
ui->pushButtonVAR->hide();
ui->checkVARLEN->hide();
init();
}
CounterVarSet::~CounterVarSet()
{
delete ui;
}
void CounterVarSet::init()
{
applyStyleSheet();
// 连接信号槽
connect(ui->checkBtn, &QPushButton::clicked, this, &CounterVarSet::buttonClickedSlot);
connect(ui->closeBtn, &QPushButton::clicked, this, &CounterVarSet::buttonClickedSlot);
}
void CounterVarSet::buttonClickedSlot()
{
// 编辑
// if (editFlag) {
// m_textEdit->clear();
// on_buttonInsertVari_pressed();
// applyUIPara();
// emit sig_updateSelectedCounter();
// editFlag = false;
// return;
// }
// 添加
QPushButton* btn = qobject_cast<QPushButton*>(sender());
if (btn == ui->checkBtn)
{
// on_buttonInsertVari_pressed();
emit sendButtonClickedSignal(1);
}else if(btn == ui->closeBtn){
emit sendButtonClickedSignal(2);
}
}
CounterViewModel CounterVarSet::getCounterConfig()
{
CounterViewModel& viewModel = m_vm;
unsigned char splitMode = 0;
getValue(&viewModel.counterType, &viewModel.digitalNum, &splitMode);
viewModel.letterSpace = ui->letterSpaceSpinBox->value();
viewModel.charWidth = ui->charWidthSpinBox->value();
viewModel.enbCustomCharWidth = ui->enbCharWidthSpinBox->isChecked();
applyUIPara();
return viewModel;
}
void CounterVarSet::setCounterConfig(CounterViewModel viewModel)
{
m_vm = viewModel;
ui->cb_digits->setCurrentText(QString::number(viewModel.digitalNum));
ui->radioButtonVar1->setChecked(viewModel.counterType == COUNTER_TYPE_1 ? true : false);
ui->radioButtonVar2->setChecked(viewModel.counterType == COUNTER_TYPE_2 ? true : false);
ui->tabWidget->setCurrentIndex(viewModel.counterType == COUNTER_TYPE_1 ? 1 : 2);
ui->letterSpaceSpinBox->setValue(viewModel.letterSpace);
ui->charWidthSpinBox->setValue(viewModel.charWidth);
ui->enbCharWidthSpinBox->setChecked(viewModel.enbCustomCharWidth);
updateSysParaToUI();
}
void CounterVarSet::getValue(int *varType,int *digitalWidth,unsigned char *splitMode){
int type = 0,width = 0;
// 20260403
if(ui->radioButtonVar1->isChecked())
type = 7;
else if(ui->radioButtonVar2->isChecked())
type = 8;
width = ui->cb_digits->currentText().toInt();
if(varType && digitalWidth){
*varType = type;
*digitalWidth = width;
}
return;
}
void CounterVarSet::applyUIPara()
{
m_vm.cnt1Settings.endValue = ui->spinBoxCnt1EndValue->value();
m_vm.cnt1Settings.repeatValue = ui->spinBoxCnt1RepeateCnt->value();
m_vm.cnt1Settings.startValue = ui->spinBoxCnt1StartValue->value();
m_vm.cnt1Settings.stepValue = ui->spinBoxCnt1StepValue->value();
m_vm.cnt1Settings.currValue = ui->spinBoxCnt1CurrValue->value();
m_vm.cnt1Settings.editCurrValue = ui->checkBoxResetCnt1CurrValue->isChecked();
m_vm.cnt2Settings.endValue = ui->spinBoxCnt2EndValue->value();
m_vm.cnt2Settings.repeatValue = ui->spinBoxCnt2RepeateCnt->value();
m_vm.cnt2Settings.startValue = ui->spinBoxCnt2StartValue->value();
m_vm.cnt2Settings.stepValue = ui->spinBoxCnt2StepValue->value();
m_vm.cnt2Settings.currValue = ui->spinBoxCnt2CurrValue->value();
m_vm.cnt2Settings.editCurrValue = ui->checkBoxResetCnt2CurrValue->isChecked();
ui->checkBoxResetCnt1CurrValue->setChecked(false);
ui->checkBoxResetCnt2CurrValue->setChecked(false);
}
void CounterVarSet::updateSysParaToUI()
{
ui->spinBoxCnt1EndValue->setValue(m_vm.cnt1Settings.endValue);
ui->spinBoxCnt1RepeateCnt->setValue(m_vm.cnt1Settings.repeatValue);
ui->spinBoxCnt1StartValue->setValue(m_vm.cnt1Settings.startValue);
ui->spinBoxCnt1StepValue->setValue(m_vm.cnt1Settings.stepValue);
ui->spinBoxCnt1CurrValue->setValue(m_vm.cnt1Settings.currValue);
ui->spinBoxCnt2EndValue->setValue(m_vm.cnt2Settings.endValue);
ui->spinBoxCnt2RepeateCnt->setValue(m_vm.cnt2Settings.repeatValue);
ui->spinBoxCnt2StartValue->setValue(m_vm.cnt2Settings.startValue);
ui->spinBoxCnt2StepValue->setValue(m_vm.cnt2Settings.stepValue);
ui->spinBoxCnt2CurrValue->setValue(m_vm.cnt2Settings.currValue);
// 电眼触发计数器动作 选择
// ui->eleCNT1IncEn->setChecked( (sysPara->para.eleEyeClearCntInSynMode & 0x10)?1:0);
// ui->radCNT1ResetEn->setChecked( (sysPara->para.eleEyeClearCntInSynMode & 0x10)?0:1);
// ui->eleCNT2IncEn->setChecked( (sysPara->para.eleEyeClearCntInSynMode & 0x20)?1:0);
// ui->radCNT2ResetEn->setChecked( (sysPara->para.eleEyeClearCntInSynMode & 0x20)?0:1);
ui->checkBoxResetCnt1CurrValue->setChecked(false);
ui->checkBoxResetCnt2CurrValue->setChecked(false);
}
void CounterVarSet::applyStyleSheet()
{
QString styleSheet =
R"(
QPushButton#closeBtn, QPushButton#checkBtn{
background-color: #E6F7FF;
border: 1px solid #87CEEB;
border-radius: 4px;
font-size: 24px;
color: #228B22;
}
QPushButton#closeBtn:hover,QPushButton#checkBtn:hover{
background-color: #D1E9FF;
}
QPushButton#closeBtn:pressed,QPushButton#checkBtn:pressed{
background-color: #BAE7FF;
}
QPushButton {
background-color: #5396C1;
color: #ffffff;
border: 1px solid #000000;
border-radius: 3px;
font-size: 18px;
font-weight:500;
width: 180px;
height: 90px;
}
QPushButton:hover {
background-color: #5396C1;
}
QPushButton:disabled {
background-color: #7C828E;
color: #606060;
border-color: #808080;
}
QComboBox {
border: 1px solid #000000;
border-radius: 3px;
font-size: 14px;
width: 180px;
height: 90px;
padding-left: 10px; /* 文字左边距,避免紧贴边缘 */
}
/* 下拉箭头区域 */
QComboBox::drop-down {
border: 1px solid #333333;
border-radius: 3px;
width: 30px; /* 箭头区域宽度 */
background-color: #5396C1;
}
/* 下拉箭头图标 */
QComboBox::down-arrow {
image: url(:/image/down_white.png);
width: 16px; /* 图标显示宽度 */
height: 16px; /* 图标显示高度 */
}
/* 悬停状态 */
QComboBox:hover {
background-color: #efefef;
}
QComboBox QAbstractItemView {
border: 1px solid #000000;
border-radius: 3px;
font-size: 14px;
selection-background-color: #5396C1; /* 选中项背景色(稍深) */
selection-color: #ffffff;
}
QSpinBox::down-button {
width: 23px; /* 图标显示宽度 */
height: 23px; /* 图标显示高度 */
border: 1px solid #333333;
border-radius: 3px;
background-color: #5396C1;
}
QSpinBox::down-arrow {
image: url(:/image/down_white.png);
height: 18px;
width: 18px;
}
QSpinBox::up-button {
width: 23px; /* 图标显示宽度 */
height: 23px; /* 图标显示高度 */
border: 1px solid #333333;
border-radius: 3px;
background-color: #5396C1;
}
QSpinBox::up-arrow {
image: url(:/image/up_white.png);
height: 18px;
width: 18px;
}
QSpinBox {
border: 1px solid #333333;
}
QTabWidget {
border: none;
background-color: #7B838E;
}
QTabBar::tab {
margin-top: -3px;
min-width: 90px;
min-height: 45px;
padding: 4px 10px;
margin-right: 4px;
border: 1px solid #dddddd;
border-bottom: none;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
background-color: #5396C1;
color: #ffffff;
}
QTabWidget::tab-bar {
top: -3px;
left: 10px;
}
QTabBar::tab:focus {
outline: none;
}
QTabBar::tab:selected {
background-color: #6bb1e0;
color: #ffffff;
box-shadow: 0 -3px 8px rgba(44, 125, 232, 0.25);
}
QRadioButton::indicator {
width: 25px;
height: 25px;
}
QSpinBox::down-button {
width: 23px; /* 图标显示宽度 */
height: 23px; /* 图标显示高度 */
border: 1px solid #333333;
border-radius: 3px;
background-color: #5396C1;
}
QSpinBox::down-arrow {
image: url(:/image/down_white.png);
height: 15px;
width: 15px;
}
QSpinBox::up-button {
width: 23px; /* 图标显示宽度 */
height: 23px; /* 图标显示高度 */
border: 1px solid #333333;
border-radius: 3px;
background-color: #5396C1;
}
QSpinBox::up-arrow {
image: url(:/image/up_white.png);
height: 15px;
width: 15px;
}
QSpinBox {
border: 1px solid #333333;
}
QCheckBox {
color: #000000;
}
QCheckBox::indicator {
width: 15px;
height: 15px;
border: 1px solid #96A0A9;
border-radius: 8px;
background-color: #ffffff;
}
QCheckBox::indicator:checked {
background-color: #95B2D4;
border-color: #95B2D4;
}
)";
this->setStyleSheet(styleSheet);
}
void CounterVarSet::on_checkBoxResetCnt1CurrValue_released()
{
bool checked = ui->checkBoxResetCnt1CurrValue->isChecked();
ui->spinBoxCnt1CurrValue->setEnabled(checked);
}
void CounterVarSet::on_checkBoxResetCnt2CurrValue_released()
{
bool checked = ui->checkBoxResetCnt2CurrValue->isChecked();
ui->spinBoxCnt2CurrValue->setEnabled(checked);
}
void CounterVarSet::on_pushOnlyCNT1Clear_pressed()
{
// 转由主界面实现清零 byons@2026年4月25日
// sysPara->devOp->clearProductCnt(1<<2); // 计数器1单独清零
}
void CounterVarSet::on_pushOnlyCNT2Clear_pressed()
{
// sysPara->devOp->clearProductCnt(1<<3);// 计数器2单独清零
}