436 lines
13 KiB
C++
436 lines
13 KiB
C++
#include "MainInstruction.h"
|
|
#include "ui_MainInstruction.h"
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
#include <cerrno>
|
|
#include <cstring>
|
|
#include "DlgRFIDConfig.h"
|
|
#include "runtimectrl.h"
|
|
#include "DlgCanvasHeightEditor.h"
|
|
|
|
MainInstruction::MainInstruction(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::MainInstruction)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
m_graphicsEditor = new ZkEdit();
|
|
|
|
// 连接几个特殊按钮,这些按钮将由外部处理
|
|
connect(ui->closeBtn, &QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 1));
|
|
connect(ui->sysMgtBtn, &QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 2));
|
|
connect(ui->sysSetBtn, &QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 3));
|
|
connect(ui->otherSetBtn, &QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 4));
|
|
connect(ui->sysUpdateBtn,&QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 5));
|
|
connect(ui->btn_defPrintSet, &QPushButton::clicked, this, std::bind(&MainInstruction::onSpecialButtonClicked, this, 6));
|
|
|
|
// 其他信号槽连接在ui文件中
|
|
|
|
dlgInputAddr = new DlgInputAddr(parent);
|
|
dialogAuthorization = new DialogAuthorization(parent);
|
|
dlgRfidConfig = new DlgRFIDConfig(this);
|
|
dlgRfidConfig->setWindowTitle(tr("RFID Settings"));
|
|
|
|
connect(dlgRfidConfig, &DlgRFIDConfig::accepted, this, &MainInstruction::onRFIDAutoConfirmTimeoutChanged);
|
|
|
|
dlgInputAddr->GetAddr();
|
|
dlgInputAddr->vpnConnect();
|
|
dlgInputAddr->hide();
|
|
|
|
dialogMaintenanceTimeSettingAuth = new DialogAuthorization;
|
|
connect(dialogMaintenanceTimeSettingAuth,SIGNAL(accepted()),this,SLOT(onDlgAuthMaintenanceTimeAccepted()));
|
|
|
|
connect(dialogAuthorization,SIGNAL(accepted()),this,SLOT(ondialogAuthorizationAccepted()));
|
|
|
|
MTimeSetting = new DialogMaintenanceTimeSetting(this);
|
|
connect(MTimeSetting,SIGNAL(accepted()),this,SLOT(onMTimeSettingAccepted()));
|
|
//30s刷新一次总运行时间
|
|
connect(RunTimeCtrl::instance(), &RunTimeCtrl::sig_saveRunTime
|
|
, this, [=]() {
|
|
if (sysPara){
|
|
RFIDPara_t rfidPara = sysPara->RFIDPara;
|
|
rfidPara.runtimeMs = RunTimeCtrl::instance()->totalRuntimeMs();
|
|
MTimeSetting->updateUI(rfidPara);
|
|
}
|
|
});
|
|
|
|
applyStyleSheet();
|
|
|
|
// 授权
|
|
ui->tabWidget->removeTab(2);
|
|
|
|
timeDia.hide();
|
|
connect(&timeDia,SIGNAL(accepted()),this,SLOT(slt_timeSetting()));
|
|
|
|
ui->btn_network->hide();
|
|
|
|
dlgCanvasHeightEditor = new DlgCanvasHeightEditor(this);
|
|
dlgCanvasHeightEditor->setWindowModality(Qt::WindowModality::WindowModal);
|
|
connect(dlgCanvasHeightEditor, &QDialog::accepted, this, [this](){
|
|
if(!sysPara)
|
|
return;
|
|
|
|
sysPara->para.canvasHeight = dlgCanvasHeightEditor->canvasHeight();
|
|
LogInfo::setRunStatusText(QString("Canvas Height: %1").arg(sysPara->para.canvasHeight));
|
|
sysPara->saveParaToFile();
|
|
});
|
|
}
|
|
|
|
MainInstruction::~MainInstruction()
|
|
{
|
|
delete ui;
|
|
delete m_graphicsEditor;
|
|
}
|
|
|
|
void MainInstruction::bindSysPara(SysPara *sysPara){
|
|
this->sysPara = sysPara;
|
|
}
|
|
|
|
void MainInstruction::onGraphicsEditBtnClicked()
|
|
{
|
|
// 在arm主机上以全屏模式显示,而在x86上无所谓
|
|
#if defined(ARCH_AARCH64_GNU)
|
|
m_graphicsEditor->showFullScreen();
|
|
#else
|
|
m_graphicsEditor->show();
|
|
#endif
|
|
}
|
|
|
|
void MainInstruction::onSpecialButtonClicked(int btnID)
|
|
{
|
|
emit sendButtonClickedSignal(btnID);
|
|
}
|
|
|
|
void MainInstruction::on_createNewFileBtn_clicked()
|
|
{
|
|
emit newFileBtnClick();
|
|
}
|
|
|
|
void MainInstruction::on_maintenanceIntervalBtn_clicked()
|
|
{
|
|
// dialogMaintenanceTimeSettingAuth->clearAuth();
|
|
// dialogMaintenanceTimeSettingAuth->show();
|
|
|
|
onDlgAuthMaintenanceTimeAccepted();
|
|
}
|
|
|
|
|
|
void MainInstruction::onDlgAuthMaintenanceTimeAccepted()
|
|
{
|
|
MTimeSetting->updateUI(sysPara->RFIDPara);
|
|
MTimeSetting->disableMaintenanceTimeSet(false);
|
|
MTimeSetting->show();
|
|
}
|
|
|
|
void MainInstruction::maintenanceDialogShow()
|
|
{
|
|
MTimeSetting->updateUI(sysPara->RFIDPara);
|
|
RunTimeCtrl::instance()->updatePara(&sysPara->RFIDPara);
|
|
MTimeSetting->disableMaintenanceTimeSet(true);
|
|
MTimeSetting->show();
|
|
}
|
|
|
|
void MainInstruction::onMTimeSettingAccepted(){
|
|
MTimeSetting->getInterval(&sysPara->RFIDPara);
|
|
RunTimeCtrl::instance()->updatePara(&sysPara->RFIDPara);
|
|
sysPara->saveRFIDPara();
|
|
}
|
|
|
|
void MainInstruction::ondialogAuthorizationAccepted(){
|
|
|
|
QString authString = dialogAuthorization->getAuth();
|
|
|
|
if((authString.left(4) == "nnyp") && ( dlgInputAddr->checkSupperJm(authString.mid(4))))
|
|
{
|
|
#ifdef __RFID_CARD
|
|
/**********超级密码,除了维护时间的5个参数,其他参数清零*****************/
|
|
sysPara->RFIDPara = RFIDPara_t();
|
|
RunTimeCtrl::instance()->authorizationAccepted(&sysPara->RFIDPara);
|
|
sysPara->saveRFIDPara();
|
|
QMessageBox::warning(0,tr("提示"),tr("RFID卡清零!") );
|
|
|
|
sysPara->para.flagOfInkWarning = false;
|
|
sysPara->para.flagOfSolventWarning = false;
|
|
sysPara->status.needMaintenanceRemind = false;
|
|
|
|
// sysPara->RFIDPara.inkCardTimeOut = false;
|
|
// sysPara->RFIDPara.solventCardTimeOut = false;
|
|
|
|
sysPara->RFIDPara.needMaintenance = false;
|
|
|
|
// sysPara->RFIDPara.needInkCard = false;
|
|
// sysPara->RFIDPara.needSolventCard = false;
|
|
|
|
QDate curDate = QDate::currentDate();
|
|
int curdate = curDate.toString("yyMMdd").toInt();
|
|
sysPara->RFIDPara.maintenanceDate = curdate; // 维护日期
|
|
QDate mtEndDate = curDate.addMonths(sysPara->RFIDPara.maintenanceInterval);
|
|
sysPara->RFIDPara.maintenanceEndDate = mtEndDate.toString("yyMMdd").toInt(); // 维护结束日期
|
|
sysPara->para.inkWarnDate = 0;
|
|
sysPara->para.inkWarnTime = 0;
|
|
sysPara->para.solventWarnDate = 0;
|
|
sysPara->para.solventWarnTime = 0;
|
|
sysPara->saveParaToFile();
|
|
sysPara->saveRFIDPara();
|
|
|
|
emit superJmAccepted();
|
|
#endif
|
|
}
|
|
else if( dlgInputAddr->checkSupperJm(authString))
|
|
{
|
|
sysPara->status.WorkTimeOut=0;
|
|
dlgInputAddr->ReadJm();
|
|
dlgInputAddr->show();
|
|
// ui->labMac->setText(QString("Mac:%1").arg(dlgInputAddr->jd.addr));
|
|
}
|
|
else if(authString == "nnyp") {
|
|
ui->tabWidget->addTab(ui->tabExtra, tr("额外设置"));
|
|
ui->pushButtonAuth->setText(tr("取消授权"));
|
|
} else {
|
|
QMessageBox box(QMessageBox::Warning, tr("警告"),
|
|
tr("密码错误:%1").arg(authString), QMessageBox::Ok,
|
|
this);
|
|
box.exec();
|
|
}
|
|
}
|
|
|
|
void MainInstruction::on_pushButtonAuth_clicked()
|
|
{
|
|
if (ui->pushButtonAuth->text() == tr("取消授权")) {
|
|
ui->pushButtonAuth->setText(tr("系统授权"));
|
|
int index = ui->tabWidget->indexOf(ui->tabExtra);
|
|
ui->tabWidget->removeTab(index);
|
|
return;
|
|
}
|
|
dialogAuthorization->clearAuth();
|
|
dialogAuthorization->show();
|
|
}
|
|
|
|
|
|
void MainInstruction::on_btn_time_clicked()
|
|
{
|
|
QTime tm = QTime::currentTime();
|
|
QDate date = QDate::currentDate();
|
|
timeDia.setYear(date.year());
|
|
timeDia.setMonth(date.month());
|
|
timeDia.setDay(date.day());
|
|
timeDia.setHour(tm.hour());
|
|
timeDia.setMinute(tm.minute());
|
|
timeDia.setSecond(tm.second());
|
|
timeDia.show();
|
|
}
|
|
|
|
#include <time.h>
|
|
void m_adjustdate(int year, int mon, int mday, int hour, int min, int sec) {
|
|
time_t t;
|
|
struct tm nowtime = {};
|
|
nowtime.tm_sec = sec; // Seconds.[0-60] (1 leap second)
|
|
nowtime.tm_min = min; // Minutes.[0-59]
|
|
nowtime.tm_hour = hour; // Hours. [0-23]
|
|
nowtime.tm_mday = mday; // Day.[1-31]
|
|
nowtime.tm_mon = mon - 1; // Month. [0-11]
|
|
nowtime.tm_year = year - 1900; // Year- 1900.
|
|
nowtime.tm_isdst = -1; // DST.[-1/0/1]
|
|
t = mktime(&nowtime);
|
|
|
|
// GLibc 版本 大于等于 2.31时使用新API
|
|
#if (__GLIBC_MINOR__ >= 31 && __GLIBC__ == 2) || (__GLIBC__ > 2)
|
|
if (t == static_cast<time_t>(-1)) {
|
|
qWarning() << "mktime failed, errno:" << errno << QString::fromLocal8Bit(std::strerror(errno));
|
|
return;
|
|
}
|
|
|
|
struct timespec res;
|
|
res.tv_nsec = 0;
|
|
res.tv_sec = t;
|
|
auto r = clock_settime(CLOCK_REALTIME, &res);
|
|
if (r != 0) {
|
|
qWarning() << "clock_settime failed, errno:" << errno << QString::fromLocal8Bit(std::strerror(errno));
|
|
} else {
|
|
qInfo() << "clock_settime success";
|
|
}
|
|
#else
|
|
if (t == static_cast<time_t>(-1)) {
|
|
qWarning() << "mktime failed, errno:" << errno << QString::fromLocal8Bit(std::strerror(errno));
|
|
return;
|
|
}
|
|
|
|
stime(&t);
|
|
#endif
|
|
}
|
|
|
|
uint8_t m_datatime[8] = {};
|
|
void MainInstruction::slt_timeSetting()
|
|
{
|
|
m_adjustdate(timeDia.getYear(), timeDia.getMonth(),
|
|
timeDia.getDay(), timeDia.getHour(),
|
|
timeDia.getMinute(), timeDia.getSecond());
|
|
|
|
QDate date(timeDia.getYear(), timeDia.getMonth(), timeDia.getDay());
|
|
int dayOfWeek = date.dayOfWeek();
|
|
QString YearStr = QString::number(timeDia.getYear());
|
|
int Year1 = YearStr.mid(0,2).toInt();
|
|
int Year2 = YearStr.mid(2,2).toInt();
|
|
uint8_t year1 = Year1;
|
|
m_datatime[0] = year1;
|
|
uint8_t year2 = Year2;
|
|
m_datatime[1] = year2;
|
|
uint8_t month = timeDia.getMonth();
|
|
m_datatime[2] = month;
|
|
uint8_t day = timeDia.getDay();
|
|
m_datatime[3] = day;
|
|
uint8_t week= dayOfWeek;
|
|
m_datatime[4] = week;
|
|
uint8_t hour = timeDia.getHour();
|
|
m_datatime[5] = hour;
|
|
uint8_t minute= timeDia.getMinute();
|
|
m_datatime[6] = minute;
|
|
uint8_t second= timeDia.getSecond();
|
|
m_datatime[7] = second;
|
|
|
|
sysPara->devOp->stm32Wr(0xA1,(unsigned char *)m_datatime,8);
|
|
}
|
|
|
|
void MainInstruction::onRfidCfgBtnClicked()
|
|
{
|
|
dlgRfidConfig->setAutoConfirmTimeout(sysPara->para.rfidCountDown);
|
|
dlgRfidConfig->setWindowModality(Qt::WindowModality::WindowModal);
|
|
dlgRfidConfig->show();
|
|
}
|
|
|
|
void MainInstruction::onRFIDAutoConfirmTimeoutChanged()
|
|
{
|
|
sysPara->para.rfidCountDown = dlgRfidConfig->autoConfirmTimeout();
|
|
qInfo() << "RFID auto confirm timeout: " << sysPara->para.rfidCountDown;
|
|
sysPara->saveRFIDPara();
|
|
}
|
|
|
|
void MainInstruction::onCanvasCfgBtnClicked()
|
|
{
|
|
if(sysPara)
|
|
dlgCanvasHeightEditor->setCanvsHeight(sysPara->para.canvasHeight);
|
|
|
|
dlgCanvasHeightEditor->show();
|
|
}
|
|
|
|
void MainInstruction::applyStyleSheet()
|
|
{
|
|
QString styleSheet =
|
|
R"(
|
|
QWidget#buttonWidget {
|
|
background-color: #95989D;
|
|
}
|
|
|
|
QPushButton#closeBtn {
|
|
background-color: #E6F7FF;
|
|
border: 1px solid #87CEEB;
|
|
border-radius: 4px;
|
|
font-size: 24px;
|
|
color: #228B22;
|
|
}
|
|
|
|
QPushButton#closeBtn:hover {
|
|
background-color: #D1E9FF;
|
|
}
|
|
|
|
QPushButton#closeBtn:pressed {
|
|
background-color: #BAE7FF;
|
|
}
|
|
|
|
QLabel {
|
|
font-size: 18px;
|
|
color: #000000;
|
|
font-weight: 500;
|
|
}
|
|
|
|
QCheckBox {
|
|
font-size: 18px;
|
|
color: #000000;
|
|
font-weight:500;
|
|
}
|
|
|
|
QCheckBox::indicator {
|
|
width: 18px;
|
|
height: 18px;
|
|
border: 1px solid #96A0A9;
|
|
border-radius: 10px;
|
|
background-color: #ffffff;
|
|
}
|
|
|
|
QCheckBox::indicator:checked {
|
|
background-color: #95B2D4;
|
|
border-color: #95B2D4;
|
|
image: url(:/Demo/image/select.png);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
QWidget#fileTab, QWidget#extraTab, QWidget#settingsTab, QWidget#serviceTab {
|
|
background-color: #E3E7EC;
|
|
}
|
|
|
|
QTabWidget::pane {
|
|
border: 1px solid #dddddd;
|
|
background-color: #ffffff;
|
|
}
|
|
|
|
QTabWidget::tab-bar {
|
|
top: -3px;
|
|
left: 10px;
|
|
}
|
|
|
|
QTabBar::tab {
|
|
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;
|
|
}
|
|
|
|
QTabBar::tab:selected {
|
|
background-color: #6bb1e0;
|
|
color: #ffffff;
|
|
box-shadow: 0 -3px 8px rgba(44, 125, 232, 0.25);
|
|
}
|
|
|
|
QTabBar::tab:focus {
|
|
outline: none;
|
|
}
|
|
|
|
)";
|
|
|
|
this->setStyleSheet(styleSheet);
|
|
}
|
|
void MainInstruction::on_visSetBtn_clicked()
|
|
{
|
|
if (dlgVisSetting == nullptr) {
|
|
dlgVisSetting = new DlgViscositySetting(this);
|
|
}
|
|
if (dlgVisSetting)
|
|
dlgVisSetting->show();
|
|
}
|