简短文件名
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
#include "selfcheck.h"
|
||||
#include "titlebar.h"
|
||||
#include "ledindicator.h"
|
||||
#include "udpcommunication.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QProgressBar>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include "global.h"
|
||||
|
||||
SelfCheckPage::SelfCheckPage(AppContext* ctx, QWidget* parent)
|
||||
: BasePage(ctx, parent)
|
||||
{
|
||||
QVBoxLayout* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(0, 0, 0, 0);
|
||||
root->setSpacing(0);
|
||||
|
||||
m_titleBar = new TitleBar(ctx, this);
|
||||
m_titleBar->setTitle("自检界面");
|
||||
root->addWidget(m_titleBar);
|
||||
|
||||
// 主区
|
||||
QHBoxLayout* main = new QHBoxLayout();
|
||||
main->setContentsMargins(36, 16, 36, 16);
|
||||
main->setSpacing(32);
|
||||
|
||||
// 左按钮列(垂直居中 + 平均分布)
|
||||
QWidget* left = new QWidget(this);
|
||||
QVBoxLayout* leftLay = new QVBoxLayout(left);
|
||||
leftLay->setContentsMargins(0, 0, 0, 0);
|
||||
leftLay->setSpacing(8);
|
||||
QPushButton* faultQuery = button("故障查询", "", left);
|
||||
faultQuery->setFixedHeight(120);
|
||||
connect(faultQuery, &QPushButton::clicked, this, [this]() { emit navigate(PageFault); });
|
||||
m_ignore = button("忽略故障", "", left);
|
||||
m_ignore->setFixedHeight(120);
|
||||
connect(m_ignore, &QPushButton::clicked, this, &SelfCheckPage::onIgnoreFault);
|
||||
m_ignore->setEnabled(false);
|
||||
leftLay->addStretch(1);
|
||||
leftLay->addWidget(faultQuery);
|
||||
leftLay->addStretch(1);
|
||||
leftLay->addWidget(m_ignore);
|
||||
leftLay->addStretch(1);
|
||||
left->setFixedWidth(270);
|
||||
main->addWidget(left);
|
||||
|
||||
// 中央区
|
||||
QWidget* center = new QWidget(this);
|
||||
QVBoxLayout* centerLay = new QVBoxLayout(center);
|
||||
centerLay->setContentsMargins(0, 0, 0, 0);
|
||||
centerLay->setSpacing(12);
|
||||
|
||||
m_status = label("自检中", 36, C::WARNING, true, center);
|
||||
m_status->setAlignment(Qt::AlignCenter);
|
||||
centerLay->addWidget(m_status);
|
||||
|
||||
// 10 个自检项,两列
|
||||
QGridLayout* grid = new QGridLayout();
|
||||
grid->setSpacing(12);
|
||||
const QString names[10] = {
|
||||
"通信系统", "底盘通信", "机械臂通信", "洗消通信", "传感器信号",
|
||||
"清水液位", "球阀D1开启", "球阀D1关闭", "球阀D2开启", "球阀D2关闭"
|
||||
};
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
LedIndicator* led = new LedIndicator(names[i], center);
|
||||
led->setState(LedIndicator::Off);
|
||||
QLabel* res = label("待检测", 20, C::TEXT_SUB, false, center);
|
||||
res->setFixedWidth(120);
|
||||
QWidget* row = new QWidget(center);
|
||||
QHBoxLayout* rowLay = new QHBoxLayout(row);
|
||||
rowLay->setContentsMargins(0, 0, 0, 0);
|
||||
rowLay->addWidget(led, 1);
|
||||
rowLay->addWidget(res);
|
||||
grid->addWidget(row, i % 5, i / 5);
|
||||
m_leds.append(led);
|
||||
m_results.append(res);
|
||||
}
|
||||
centerLay->addLayout(grid, 1);
|
||||
|
||||
// 进度条
|
||||
m_progress = new QProgressBar(center);
|
||||
m_progress->setRange(0, 100);
|
||||
m_progress->setValue(0);
|
||||
m_progress->setFixedHeight(54);
|
||||
m_progress->setFormat("%p%(0/10)");
|
||||
centerLay->addWidget(m_progress);
|
||||
|
||||
main->addWidget(center, 1);
|
||||
|
||||
// 右按钮列(垂直居中 + 平均分布)
|
||||
QWidget* right = new QWidget(this);
|
||||
QVBoxLayout* rightLay = new QVBoxLayout(right);
|
||||
rightLay->setContentsMargins(0, 0, 0, 0);
|
||||
rightLay->setSpacing(8);
|
||||
QPushButton* help = button("操作说明", "", right);
|
||||
help->setFixedHeight(120);
|
||||
connect(help, &QPushButton::clicked, this, &SelfCheckPage::onHelp);
|
||||
QPushButton* start = button("启动自检", "primary", right);
|
||||
start->setFixedHeight(120);
|
||||
connect(start, &QPushButton::clicked, this, &SelfCheckPage::startSelfCheck);
|
||||
m_job = button("作业选择", "", right);
|
||||
m_job->setFixedHeight(120);
|
||||
connect(m_job, &QPushButton::clicked, this, &SelfCheckPage::onJobSelect);
|
||||
m_job->setEnabled(false);
|
||||
rightLay->addStretch(1);
|
||||
rightLay->addWidget(help);
|
||||
rightLay->addStretch(1);
|
||||
rightLay->addWidget(start);
|
||||
rightLay->addStretch(1);
|
||||
rightLay->addWidget(m_job);
|
||||
rightLay->addStretch(1);
|
||||
right->setFixedWidth(270);
|
||||
main->addWidget(right);
|
||||
|
||||
root->addLayout(main, 1);
|
||||
|
||||
// 连接通信信号
|
||||
connect(ctx->comm(), &UdpCommunication::selfCheckItem, this, &SelfCheckPage::onSelfCheckItem);
|
||||
connect(ctx->comm(), &UdpCommunication::selfCheckDone, this, &SelfCheckPage::onSelfCheckDone);
|
||||
}
|
||||
|
||||
void SelfCheckPage::showEvent(QShowEvent* ev)
|
||||
{
|
||||
BasePage::showEvent(ev);
|
||||
if (!m_autoStarted) {
|
||||
m_autoStarted = true;
|
||||
startSelfCheck();
|
||||
}
|
||||
}
|
||||
|
||||
void SelfCheckPage::startSelfCheck()
|
||||
{
|
||||
m_done = false;
|
||||
m_job->setEnabled(false);
|
||||
m_ignore->setEnabled(false);
|
||||
m_progress->setValue(0);
|
||||
m_progress->setFormat("%p%(0/10)");
|
||||
m_status->setText("自检中");
|
||||
m_status->setStyleSheet(QString("color:%1;font-size:36px;font-weight:700;").arg(C::WARNING));
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
m_leds[i]->setState(LedIndicator::Off);
|
||||
m_results[i]->setText("待检测");
|
||||
m_results[i]->setStyleSheet(QString("color:%1;font-size:22px;").arg(C::TEXT_SUB));
|
||||
}
|
||||
ctx()->comm()->sendSelfCheckStart();
|
||||
}
|
||||
|
||||
void SelfCheckPage::resetAll()
|
||||
{
|
||||
m_autoStarted = false;
|
||||
}
|
||||
|
||||
void SelfCheckPage::onSelfCheckItem(int index, bool ok)
|
||||
{
|
||||
if (index < 0 || index >= 10)
|
||||
return;
|
||||
m_leds[index]->setState(LedIndicator::Yellow); // 检测中黄闪 → 结果
|
||||
// 结果态
|
||||
if (ok) {
|
||||
m_leds[index]->setState(LedIndicator::Green);
|
||||
m_results[index]->setText("正常");
|
||||
m_results[index]->setStyleSheet(QString("color:%1;font-size:22px;").arg(C::SUCCESS));
|
||||
} else {
|
||||
m_leds[index]->setState(LedIndicator::RedBlink);
|
||||
m_results[index]->setText("异常");
|
||||
m_results[index]->setStyleSheet(QString("color:%1;font-size:22px;font-weight:700;").arg(C::DANGER));
|
||||
}
|
||||
int pct = (index + 1) * 10;
|
||||
m_progress->setValue(pct);
|
||||
m_progress->setFormat(QString("%p%(%1/10)").arg(index + 1));
|
||||
}
|
||||
|
||||
void SelfCheckPage::onSelfCheckDone(bool allOk)
|
||||
{
|
||||
m_done = true;
|
||||
if (allOk) {
|
||||
m_status->setText("自检完成");
|
||||
m_status->setStyleSheet(QString("color:%1;font-size:36px;font-weight:700;").arg(C::SUCCESS));
|
||||
m_job->setEnabled(true);
|
||||
// 【设计建议】自检完成 2s 后自动进入作业选择
|
||||
QTimer::singleShot(2000, this, [this]() {
|
||||
if (m_done && isVisible())
|
||||
emit navigate(PageJob);
|
||||
});
|
||||
} else {
|
||||
m_status->setText("无法完成自检 请检查设备");
|
||||
m_status->setStyleSheet(QString("color:%1;font-size:36px;font-weight:700;").arg(C::DANGER));
|
||||
startBlink(m_status, "blink");
|
||||
m_ignore->setEnabled(true);
|
||||
m_job->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SelfCheckPage::onIgnoreFault()
|
||||
{
|
||||
emit navigate(PageJob);
|
||||
}
|
||||
|
||||
void SelfCheckPage::onJobSelect()
|
||||
{
|
||||
emit navigate(PageJob);
|
||||
}
|
||||
|
||||
void SelfCheckPage::onHelp()
|
||||
{
|
||||
QMessageBox::information(this, "操作说明",
|
||||
"系统自检将依次检测:通信系统、底盘通信、机械臂通信、洗消通信、"
|
||||
"传感器信号、清水液位及电动球阀 D1/D2 的开启与关闭。\n"
|
||||
"全部正常后方可进入作业选择界面。");
|
||||
}
|
||||
Reference in New Issue
Block a user