464 lines
14 KiB
C++
464 lines
14 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();
|
|
currPage = 0;
|
|
initReplaceValue();
|
|
}
|
|
|
|
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::bindSysPara(SysPara *sysPara){
|
|
this->sysPara = sysPara;
|
|
}
|
|
|
|
void CounterVarSet::bindTxTEdit(QTextEdit* textEdit){
|
|
m_textEdit = textEdit;
|
|
}
|
|
|
|
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();
|
|
applyUIPara();
|
|
emit sendButtonClickedSignal(1);
|
|
}else if(btn == ui->closeBtn){
|
|
emit sendButtonClickedSignal(2);
|
|
}
|
|
|
|
}
|
|
|
|
CounterViewModel CounterVarSet::getCounterConfig()
|
|
{
|
|
CounterViewModel viewModel;
|
|
unsigned char splitMode = sysPara ? sysPara->para.ExpirySplitMode : 0;
|
|
getValue(&viewModel.counterType, &viewModel.digitalNum, &splitMode);
|
|
viewModel.letterSpace = ui->letterSpaceSpinBox->value();
|
|
viewModel.charWidth = ui->charWidthSpinBox->value();
|
|
viewModel.enbCustomCharWidth = ui->enbCharWidthSpinBox->isChecked();
|
|
return viewModel;
|
|
}
|
|
|
|
void CounterVarSet::setCounterConfig(CounterViewModel 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);
|
|
}
|
|
|
|
void CounterVarSet::on_buttonInsertVari_pressed()
|
|
{
|
|
if(!m_textEdit || !sysPara)
|
|
return;
|
|
|
|
QString fontname = "Dinkie9";
|
|
|
|
// 从字体名中提取像素大小(字体名最后的数字)
|
|
int pixelSize = 9;
|
|
QString numStr = "";
|
|
for(int i = fontname.length() - 1; i >= 0; --i) {
|
|
if(fontname[i].isDigit()) {
|
|
numStr.prepend(fontname[i]);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
if(!numStr.isEmpty()) {
|
|
pixelSize = numStr.toInt();
|
|
}
|
|
|
|
QFont font;
|
|
font.setFamily(fontname);
|
|
font.setPixelSize(pixelSize);
|
|
pixelSize = font.pixelSize();
|
|
font.setWeight(false && (pixelSize<=16) ?QFont::Bold:QFont::Normal);
|
|
font.setLetterSpacing(QFont::AbsoluteSpacing, sysPara->para.textEditCharSpace);
|
|
|
|
QFontMetrics fontMetrics(font);
|
|
|
|
int width = (fontMetrics.horizontalAdvance("0123456789")) / 10;
|
|
int height = font.pixelSize();
|
|
|
|
int digitalNum;
|
|
int varType;
|
|
unsigned char splitMode = sysPara->para.ExpirySplitMode;
|
|
getValue(&varType, &digitalNum, &splitMode);
|
|
|
|
fmt = m_textEdit->currentCharFormat();
|
|
|
|
int varType1 = varType;
|
|
|
|
if(fontname.contains("SerifL") || fontname.contains("serifl"))
|
|
varType1 = 20 + varType;
|
|
else if(fontname.contains("SerifR") || fontname.contains("serifr"))
|
|
varType1 = 20 + varType;
|
|
else if(fontname.contains("bangla"))
|
|
varType1 = 30 + varType;
|
|
else if(fontname.contains("biyangF"))
|
|
varType1 = 50 + varType;
|
|
else if(fontname.contains("Roman"))
|
|
varType1 = 60 + varType;
|
|
|
|
m_textEdit->insertHtml(QString("<img src=':/%1/%5/../image/digitalWidth%2.bmp' height='%3' width='%4' style=\"vertical-align: bottom;\" />")
|
|
.arg(varType).arg(false && (pixelSize<=16)?(digitalNum*100 + 75):digitalNum)
|
|
.arg(height+1).arg(width*digitalNum).arg(varType1));
|
|
|
|
m_textEdit->setFocus();
|
|
}
|
|
|
|
|
|
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(){
|
|
if(sysPara){
|
|
|
|
sysPara->para.cnt1EndValue = ui->spinBoxCnt1EndValue->value();
|
|
sysPara->para.cnt1RepeateValue = ui->spinBoxCnt1RepeateCnt->value();
|
|
sysPara->para.cnt1StartValue = ui->spinBoxCnt1StartValue->value();
|
|
sysPara->para.cnt1StepValue = ui->spinBoxCnt1StepValue->value();
|
|
sysPara->para.cnt1CurrValue = ui->spinBoxCnt1CurrValue->value();
|
|
sysPara->status.cnt1CurrentValueInitDoneFlag = !ui->checkBoxResetCnt1CurrValue->isChecked();
|
|
|
|
sysPara->para.cnt2EndValue = ui->spinBoxCnt2EndValue->value();
|
|
sysPara->para.cnt2RepeateValue = ui->spinBoxCnt2RepeateCnt->value();
|
|
sysPara->para.cnt2StartValue = ui->spinBoxCnt2StartValue->value();
|
|
sysPara->para.cnt2StepValue = ui->spinBoxCnt2StepValue->value();
|
|
sysPara->para.cnt2CurrValue = ui->spinBoxCnt2CurrValue->value();
|
|
sysPara->status.cnt2CurrentValueInitDoneFlag = !ui->checkBoxResetCnt2CurrValue->isChecked();
|
|
|
|
if(ui->eleCNT1IncEn->isChecked())
|
|
sysPara->para.eleEyeClearCntInSynMode = (sysPara->para.eleEyeClearCntInSynMode | 0x10); // CNT1 +1
|
|
else
|
|
sysPara->para.eleEyeClearCntInSynMode = (sysPara->para.eleEyeClearCntInSynMode & 0xef); // CNT1 = current
|
|
|
|
if(ui->eleCNT2IncEn->isChecked())
|
|
sysPara->para.eleEyeClearCntInSynMode = (sysPara->para.eleEyeClearCntInSynMode | 0x20); // CNT2 +1
|
|
else
|
|
sysPara->para.eleEyeClearCntInSynMode = (sysPara->para.eleEyeClearCntInSynMode & 0xdf); // CNT2 = current
|
|
|
|
ui->checkBoxResetCnt1CurrValue->setChecked(false);
|
|
ui->checkBoxResetCnt2CurrValue->setChecked(false);
|
|
|
|
sysPara->devOp->writeFpgaCalandar(0);
|
|
|
|
}
|
|
}
|
|
|
|
void CounterVarSet::updateSysParaToUI(){
|
|
|
|
if(sysPara){
|
|
ui->spinBoxCnt1EndValue->setValue(sysPara->para.cnt1EndValue);
|
|
ui->spinBoxCnt1RepeateCnt->setValue(sysPara->para.cnt1RepeateValue);
|
|
ui->spinBoxCnt1StartValue->setValue(sysPara->para.cnt1StartValue);
|
|
ui->spinBoxCnt1StepValue->setValue(sysPara->para.cnt1StepValue);
|
|
ui->spinBoxCnt1CurrValue->setValue(sysPara->para.cnt1CurrValue);
|
|
|
|
ui->spinBoxCnt2EndValue->setValue(sysPara->para.cnt2EndValue);
|
|
ui->spinBoxCnt2RepeateCnt->setValue(sysPara->para.cnt2RepeateValue);
|
|
ui->spinBoxCnt2StartValue->setValue(sysPara->para.cnt2StartValue);
|
|
ui->spinBoxCnt2StepValue->setValue(sysPara->para.cnt2StepValue);
|
|
ui->spinBoxCnt2CurrValue->setValue(sysPara->para.cnt2CurrValue);
|
|
|
|
// 电眼触发计数器动作 选择
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
QString CounterVarSet::getFamilyName(int fontsize){
|
|
return "YaHei"+QString::number(fontsize);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
)";
|
|
|
|
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单独清零
|
|
}
|
|
|
|
void CounterVarSet::initReplaceValue(){
|
|
// dataList.clear();
|
|
// dataList << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7"
|
|
// << "8" << "9" << "A" << "B" << "C" << "D" << "E" << "F";
|
|
|
|
// if(ui->comboBox_2->currentIndex() == 0) //index 0 --- 数据
|
|
// loadDataShow();
|
|
}
|
|
|
|
//void CounterVarSet::loadDataShow(){
|
|
// if(currPage >3) //最大显示4页
|
|
// currPage =3;
|
|
// int objectIndex = 1;
|
|
// for(int i=currPage*4;(i<(currPage+1)*4)&&(i<dataList.size());i++){
|
|
|
|
// QString strObject = QString("lineEditName") + QString::number(objectIndex);
|
|
// QLineEdit *lineEdit = this->findChild<QLineEdit*>(strObject);
|
|
// if(lineEdit)
|
|
// lineEdit->setText(QString::number(i));
|
|
|
|
// QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex);
|
|
// QLineEdit *lineEdit2 = this->findChild<QLineEdit*>(strObject2);
|
|
// if(lineEdit2)
|
|
// lineEdit2->setText(dataList.at(i));
|
|
// objectIndex++;
|
|
// }
|
|
//}
|
|
|
|
void CounterVarSet::editCounter(int index)
|
|
{
|
|
ui->tabWidget->setCurrentIndex(index);
|
|
editFlag = true;
|
|
}
|
|
//void CounterVarSet::on_btnUP_clicked()
|
|
//{
|
|
// if(currPage<1)
|
|
// return;
|
|
// currPage = currPage-1;
|
|
|
|
// if(ui->comboBox_2->currentIndex() == 0){
|
|
// loadDataShow();
|
|
// }
|
|
//}
|
|
|
|
//void CounterVarSet::on_btnDown_clicked()
|
|
//{
|
|
// int currentIndex = ui->comboBox_2->currentIndex();
|
|
// if (currentIndex == 0) { // Data
|
|
// if (currPage < 3) {
|
|
// currPage++;
|
|
// }
|
|
// loadDataShow();
|
|
// return;
|
|
// }
|
|
//}
|