#include "gasdetector.h" #include "titlebar.h" #include "statusstrip.h" #include "datacard.h" #include "udpcommunication.h" #include "confirmdialog.h" #include #include #include #include #include "global.h" GasDetectorPage::GasDetectorPage(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); // 中央卡片区(2×2) QWidget* center = new QWidget(this); QGridLayout* grid = new QGridLayout(center); grid->setSpacing(16); grid->setContentsMargins(0, 0, 0, 0); m_chassisCard = new DataCard("底盘", center); m_chassisCard->addField("电量", "85%"); m_chassisCard->addField("电压", "360V"); m_chassisCard->addField("故障", "无"); m_washCard = new DataCard("洗消", center); m_washCard->addField("A液位", "100L"); m_washCard->addField("泡沫液位", "30L"); m_armCard = new DataCard("机械臂", center); m_armCard->addField("末端位置", "XYZ"); m_armCard->addField("姿态", "RX/RY/RZ"); m_gasCard = new DataCard("气体检测仪", center); m_gasCard->addField("主机状态", "待机"); m_gasCard->addField("有毒物种类", "--"); m_gasCard->addField("有毒物等级", "--"); m_gasConcField = m_gasCard->addField("浓度", "0 ppb", true); m_gasCard->setHighlight(true); // 主色描边突出 grid->addWidget(m_chassisCard, 0, 0); grid->addWidget(m_washCard, 0, 1); grid->addWidget(m_gasCard, 1, 0); grid->addWidget(m_armCard, 1, 1); main->addWidget(center, 1); // 右侧按钮列(垂直居中 + 平均分布) QWidget* right = new QWidget(this); QVBoxLayout* rightLay = new QVBoxLayout(right); rightLay->setContentsMargins(0, 0, 0, 0); rightLay->setSpacing(8); m_start = button("启动", "primary", right); m_start->setFixedHeight(180); connect(m_start, &QPushButton::clicked, this, [this]() { this->ctx()->comm()->sendGasStart(); this->ctx()->gasRunning = true; updateGating(); }); m_stop = button("停机", "", right); m_stop->setFixedHeight(180); connect(m_stop, &QPushButton::clicked, this, [this]() { this->ctx()->comm()->sendGasStop(); this->ctx()->gasRunning = false; updateGating(); }); rightLay->addStretch(1); rightLay->addWidget(m_start); rightLay->addStretch(1); rightLay->addWidget(m_stop); rightLay->addStretch(1); right->setFixedWidth(360); main->addWidget(right); root->addLayout(main, 1); m_statusStrip = new StatusStrip(ctx, this); connect(m_statusStrip, &StatusStrip::backClicked, this, [this]() { if (this->ctx()->gasRunning) { // 【设计建议】检测中返回弹提示 if (ConfirmDialog::confirm(this, "提示", "检测仍在进行,是否退出?")) emit navigate(PageJob); } else { emit navigate(PageJob); } }); root->addWidget(m_statusStrip); connect(ctx->comm(), &UdpCommunication::telemetryUpdated, this, &GasDetectorPage::refresh); updateGating(); refresh(); } void GasDetectorPage::updateGating() { bool running = ctx()->gasRunning; m_start->setEnabled(!running); m_stop->setEnabled(running); } void GasDetectorPage::refresh() { const Telemetry& t = ctx()->telemetry; // 同步运行状态(以遥测为准) if (t.gasHost == "detecting") ctx()->gasRunning = true; else if (t.gasHost == "standby") ctx()->gasRunning = false; updateGating(); m_chassisCard->setField(0, QString("%1%").arg(t.soc)); m_chassisCard->setField(1, QString("%1V").arg(t.volt, 0, 'f', 0)); m_chassisCard->setField(2, t.chassisFaults.isEmpty() ? "无" : t.chassisFaults.join(";")); m_washCard->setField(0, QString("%1L").arg(t.levelA, 0, 'f', 0)); m_washCard->setField(1, QString("%1L").arg(t.levelFoam, 0, 'f', 0)); m_armCard->setField(0, t.pos); m_armCard->setField(1, t.pose); m_gasCard->setField(0, t.gasHost == "detecting" ? "检测中" : (t.gasHost == "fault" ? "故障" : "待机")); m_gasCard->setField(1, t.gasType); m_gasCard->setField(2, t.gasLevel); m_gasCard->setField(m_gasConcField, QString("%1 ppb").arg(t.gasConc, 0, 'f', 0)); // 超阈值红闪 m_gasCard->setAlarm(m_gasConcField, t.gasConc > 500.0); }