#include "WorkflowWidget.h" #include #include #include #include #include WorkflowWidget::WorkflowWidget(QWidget *parent) : QWidget(parent) { setupUI(); } void WorkflowWidget::setupUI() { // 设置背景色 setStyleSheet("background-color: rgb(37, 38, 42);"); // 创建主布局 QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(20, 10, 20, 10); mainLayout->setSpacing(8); // 创建步骤标签 QFont stepFont; stepFont.setPointSize(14); stepFont.setBold(false); // 步骤1-4: 检测阶段 QGroupBox* detectGroup = new QGroupBox("检测阶段"); detectGroup->setStyleSheet( "QGroupBox {" " color: rgb(239, 241, 245);" " font-size: 15pt;" " font-weight: bold;" " border: 2px solid rgb(60, 120, 180);" " border-radius: 6px;" " margin-top: 10px;" " padding-top: 8px;" "}" "QGroupBox::title {" " subcontrol-origin: margin;" " left: 12px;" " padding: 0 6px;" "}" ); QVBoxLayout* detectLayout = new QVBoxLayout(detectGroup); detectLayout->setSpacing(6); // 步骤1-4 for (int i = 0; i < 4; ++i) { m_stepLabels[i] = new QLabel(); m_stepLabels[i]->setFont(stepFont); m_stepLabels[i]->setStyleSheet( "color: rgb(150, 150, 150);" "padding: 6px 8px;" "border-left: 4px solid rgb(60, 60, 60);" "background-color: rgb(45, 46, 50);" "border-radius: 3px;" ); detectLayout->addWidget(m_stepLabels[i]); } m_stepLabels[0]->setText("1. 机械臂运行到准备位置"); m_stepLabels[1]->setText("2. 触发控制器检测"); m_stepLabels[2]->setText("3. 等待检测完成"); m_stepLabels[3]->setText("4. 读取检测结果"); mainLayout->addWidget(detectGroup); // 结果显示区域 m_resultLabel = new QLabel("检测结果: 等待检测..."); m_resultLabel->setFont(stepFont); m_resultLabel->setStyleSheet( "color: rgb(100, 150, 255);" "padding: 8px 10px;" "background-color: rgb(45, 46, 50);" "border: 2px solid rgb(60, 120, 180);" "border-radius: 6px;" "font-size: 13pt;" ); m_resultLabel->setWordWrap(true); m_resultLabel->setMinimumHeight(100); mainLayout->addWidget(m_resultLabel); // 步骤5-8: 执行阶段 QGroupBox* executeGroup = new QGroupBox("执行阶段"); executeGroup->setStyleSheet( "QGroupBox {" " color: rgb(239, 241, 245);" " font-size: 15pt;" " font-weight: bold;" " border: 2px solid rgb(100, 180, 120);" " border-radius: 6px;" " margin-top: 10px;" " padding-top: 8px;" "}" "QGroupBox::title {" " subcontrol-origin: margin;" " left: 12px;" " padding: 0 6px;" "}" ); QVBoxLayout* executeLayout = new QVBoxLayout(executeGroup); executeLayout->setSpacing(6); // 步骤5-8 for (int i = 4; i < 8; ++i) { m_stepLabels[i] = new QLabel(); m_stepLabels[i]->setFont(stepFont); m_stepLabels[i]->setStyleSheet( "color: rgb(150, 150, 150);" "padding: 6px 8px;" "border-left: 4px solid rgb(60, 60, 60);" "background-color: rgb(45, 46, 50);" "border-radius: 3px;" ); executeLayout->addWidget(m_stepLabels[i]); } m_stepLabels[4]->setText("5. 机械臂移动到抓取位置"); m_stepLabels[5]->setText("6. 执行抓取"); m_stepLabels[6]->setText("7. 机械臂移动到放置位置"); m_stepLabels[7]->setText("8. 执行放置"); mainLayout->addWidget(executeGroup); // 添加弹性空间 mainLayout->addStretch(); } void WorkflowWidget::updateStep(WorkflowStep step) { // 重置所有步骤为默认样式(未执行) for (int i = 0; i < 8; ++i) { m_stepLabels[i]->setStyleSheet( "color: rgb(150, 150, 150);" "padding: 6px 8px;" "border-left: 4px solid rgb(60, 60, 60);" "background-color: rgb(45, 46, 50);" "border-radius: 3px;" ); } // 当前正在执行的步骤样式(橙色高亮) QString activeStyle = "color: rgb(255, 255, 255);" "font-weight: bold;" "padding: 6px 8px;" "border-left: 4px solid rgb(255, 165, 0);" "background-color: rgb(80, 60, 30);" "border-radius: 3px;"; // 已完成的步骤样式(绿色) QString completedStyle = "color: rgb(200, 255, 200);" "padding: 6px 8px;" "border-left: 4px solid rgb(100, 200, 100);" "background-color: rgb(40, 60, 45);" "border-radius: 3px;"; // 错误步骤样式(红色) QString errorStyle = "color: rgb(255, 255, 255);" "font-weight: bold;" "padding: 6px 8px;" "border-left: 4px solid rgb(255, 80, 80);" "background-color: rgb(80, 40, 40);" "border-radius: 3px;"; switch (step) { case WorkflowStep::Idle: break; case WorkflowStep::MovingToReady: m_stepLabels[0]->setStyleSheet(activeStyle); break; case WorkflowStep::TriggeringDetection: m_stepLabels[0]->setStyleSheet(completedStyle); m_stepLabels[1]->setStyleSheet(activeStyle); break; case WorkflowStep::WaitingDetectionComplete: m_stepLabels[0]->setStyleSheet(completedStyle); m_stepLabels[1]->setStyleSheet(completedStyle); m_stepLabels[2]->setStyleSheet(activeStyle); break; case WorkflowStep::ReadingResult: m_stepLabels[0]->setStyleSheet(completedStyle); m_stepLabels[1]->setStyleSheet(completedStyle); m_stepLabels[2]->setStyleSheet(completedStyle); m_stepLabels[3]->setStyleSheet(activeStyle); break; case WorkflowStep::MovingToGrasp: for (int i = 0; i < 4; ++i) { m_stepLabels[i]->setStyleSheet(completedStyle); } m_stepLabels[4]->setStyleSheet(activeStyle); break; case WorkflowStep::Grasping: for (int i = 0; i < 5; ++i) { m_stepLabels[i]->setStyleSheet(completedStyle); } m_stepLabels[5]->setStyleSheet(activeStyle); break; case WorkflowStep::MovingToPlace: for (int i = 0; i < 6; ++i) { m_stepLabels[i]->setStyleSheet(completedStyle); } m_stepLabels[6]->setStyleSheet(activeStyle); break; case WorkflowStep::Placing: for (int i = 0; i < 7; ++i) { m_stepLabels[i]->setStyleSheet(completedStyle); } m_stepLabels[7]->setStyleSheet(activeStyle); break; case WorkflowStep::Completed: for (int i = 0; i < 8; ++i) { m_stepLabels[i]->setStyleSheet(completedStyle); } break; case WorkflowStep::Error: // 错误状态,找到当前步骤显示为红色 for (int i = 0; i < 8; ++i) { QString currentStyle = m_stepLabels[i]->styleSheet(); if (currentStyle.contains("bold")) { m_stepLabels[i]->setStyleSheet(errorStyle); break; } } break; default: break; } } void WorkflowWidget::updateDetectionResult(const DetectionResult& result) { if (!result.valid) { m_resultLabel->setText("检测结果: 无效"); m_resultLabel->setStyleSheet( "color: rgb(255, 100, 100);" "padding: 15px;" "background-color: rgb(60, 45, 45);" "border: 2px solid rgb(255, 100, 100);" "border-radius: 8px;" "font-size: 14pt;" ); return; } QString resultText = QString( "检测结果:\n" "X: %1 mm Y: %2 mm Z: %3 mm\n" "Roll: %4° Pitch: %5° Yaw: %6°" ).arg(result.x, 0, 'f', 2) .arg(result.y, 0, 'f', 2) .arg(result.z, 0, 'f', 2) .arg(result.roll, 0, 'f', 2) .arg(result.pitch, 0, 'f', 2) .arg(result.yaw, 0, 'f', 2); m_resultLabel->setText(resultText); m_resultLabel->setStyleSheet( "color: rgb(100, 200, 100);" "padding: 15px;" "background-color: rgb(45, 55, 50);" "border: 2px solid rgb(100, 200, 100);" "border-radius: 8px;" "font-size: 14pt;" ); } void WorkflowWidget::reset() { // 重置所有步骤为默认样式 for (int i = 0; i < 8; ++i) { m_stepLabels[i]->setStyleSheet( "color: rgb(150, 150, 150);" "padding: 6px 8px;" "border-left: 4px solid rgb(60, 60, 60);" "background-color: rgb(45, 46, 50);" "border-radius: 3px;" ); } // 重置结果显示 m_resultLabel->setText("检测结果: 等待检测..."); m_resultLabel->setStyleSheet( "color: rgb(100, 150, 255);" "padding: 8px 10px;" "background-color: rgb(45, 46, 50);" "border: 2px solid rgb(60, 120, 180);" "border-radius: 6px;" "font-size: 13pt;" ); }