first commit

This commit is contained in:
2026-01-02 19:20:35 +09:00
commit a10cb30c4a
94 changed files with 28609 additions and 0 deletions

View File

@@ -0,0 +1,224 @@
#include "procedurelistwidget.h"
#include "overlaydialogswidget.h"
#include "../procedure/proceduremanager.h"
#include <QFrame>
#include <QScrollBar>
#include <QCoreApplication>
#include <QDir>
#include <QDebug>
ProcedureListWidget::ProcedureListWidget(ProcedureManager *manager, QWidget *parent)
: QWidget(parent), m_manager(manager)
{
setupUI();
refreshList();
}
ProcedureListWidget::~ProcedureListWidget() {}
void ProcedureListWidget::setupUI()
{
auto *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
// 顶部工具栏 - Material Design 深色
auto *toolbar = new QWidget(this);
toolbar->setFixedHeight(56);
toolbar->setStyleSheet("background: #263238;");
auto *toolbarLayout = new QHBoxLayout(toolbar);
toolbarLayout->setContentsMargins(8, 0, 16, 0);
toolbarLayout->setSpacing(8);
m_backBtn = new QPushButton("返回", this);
m_backBtn->setFixedHeight(40);
m_backBtn->setStyleSheet(
"QPushButton { background: #455A64; color: white; border: none; border-radius: 4px; padding: 0 16px; font-size: 14px; }"
"QPushButton:hover { background: #546E7A; }"
"QPushButton:pressed { background: #37474F; }");
connect(m_backBtn, &QPushButton::clicked, this, &ProcedureListWidget::backRequested);
toolbarLayout->addWidget(m_backBtn);
auto *titleLabel = new QLabel("规程列表", this);
titleLabel->setStyleSheet("color: white; font-size: 18px; font-weight: bold;");
toolbarLayout->addWidget(titleLabel);
toolbarLayout->addStretch();
mainLayout->addWidget(toolbar);
// 内容区域
auto *contentWidget = new QWidget(this);
contentWidget->setStyleSheet("background: #FAFAFA;");
auto *contentLayout = new QVBoxLayout(contentWidget);
contentLayout->setContentsMargins(20, 20, 20, 20);
contentLayout->setSpacing(16);
// 搜索卡片
auto *searchCard = new QWidget(this);
searchCard->setStyleSheet(
"QWidget#searchCard { background: white; border-radius: 8px; border: 1px solid #E0E0E0; }");
searchCard->setObjectName("searchCard");
auto *searchCardLayout = new QVBoxLayout(searchCard);
searchCardLayout->setContentsMargins(20, 16, 20, 16);
searchCardLayout->setSpacing(16);
auto *searchRow = new QHBoxLayout();
searchRow->setSpacing(12);
m_searchEdit = new QLineEdit(this);
m_searchEdit->setPlaceholderText("输入规程ID或名称搜索...");
m_searchEdit->setFixedHeight(44);
m_searchEdit->setStyleSheet(
"QLineEdit { border: 2px solid #E0E0E0; border-radius: 6px; padding: 0 16px; font-size: 15px; background: #FAFAFA; }"
"QLineEdit:focus { border-color: #1976D2; background: white; }");
searchRow->addWidget(m_searchEdit, 1);
m_scanProcedureBtn = new QPushButton("扫描条码", this);
m_scanProcedureBtn->setFixedHeight(44);
m_scanProcedureBtn->setStyleSheet(
"QPushButton { background: #1976D2; color: white; border: none; border-radius: 6px; padding: 0 20px; font-size: 14px; font-weight: bold; }"
"QPushButton:hover { background: #1565C0; }"
"QPushButton:pressed { background: #0D47A1; }");
searchRow->addWidget(m_scanProcedureBtn);
searchCardLayout->addLayout(searchRow);
auto *workOrderRow = new QHBoxLayout();
workOrderRow->setSpacing(12);
auto *workOrderLabel = new QLabel("工单号:", this);
workOrderLabel->setStyleSheet("color: #424242; font-size: 15px; font-weight: bold;");
workOrderLabel->setFixedWidth(70);
workOrderRow->addWidget(workOrderLabel);
m_workOrderEdit = new QLineEdit(this);
m_workOrderEdit->setPlaceholderText("输入或扫描工单号");
m_workOrderEdit->setFixedHeight(44);
m_workOrderEdit->setStyleSheet(
"QLineEdit { border: 2px solid #E0E0E0; border-radius: 6px; padding: 0 16px; font-size: 15px; background: #FAFAFA; }"
"QLineEdit:focus { border-color: #1976D2; background: white; }");
workOrderRow->addWidget(m_workOrderEdit, 1);
m_scanWorkOrderBtn = new QPushButton("扫描", this);
m_scanWorkOrderBtn->setFixedHeight(44);
m_scanWorkOrderBtn->setStyleSheet(
"QPushButton { background: #455A64; color: white; border: none; border-radius: 6px; padding: 0 20px; font-size: 14px; }"
"QPushButton:hover { background: #546E7A; }"
"QPushButton:pressed { background: #37474F; }");
workOrderRow->addWidget(m_scanWorkOrderBtn);
searchCardLayout->addLayout(workOrderRow);
contentLayout->addWidget(searchCard);
// 规程列表
m_procedureList = new QListWidget(this);
m_procedureList->setStyleSheet(
"QListWidget { border: 1px solid #E0E0E0; border-radius: 8px; background: white; padding: 8px; }"
"QListWidget::item { background: #FAFAFA; border-radius: 6px; padding: 16px; margin: 4px 0; border: 1px solid #EEEEEE; }"
"QListWidget::item:selected { background: #E3F2FD; border: 2px solid #1976D2; }"
"QListWidget::item:hover { background: #F5F5F5; }");
contentLayout->addWidget(m_procedureList, 1);
// 底部按钮
auto *bottomLayout = new QHBoxLayout();
bottomLayout->addStretch();
m_startBtn = new QPushButton("进入规程", this);
m_startBtn->setEnabled(false);
m_startBtn->setFixedSize(200, 52);
m_startBtn->setStyleSheet(
"QPushButton { background: #43A047; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; }"
"QPushButton:hover { background: #388E3C; }"
"QPushButton:pressed { background: #2E7D32; }"
"QPushButton:disabled { background: #BDBDBD; color: #757575; }");
bottomLayout->addWidget(m_startBtn);
bottomLayout->addStretch();
contentLayout->addLayout(bottomLayout);
mainLayout->addWidget(contentWidget, 1);
connect(m_searchEdit, &QLineEdit::textChanged, this, &ProcedureListWidget::onSearchTextChanged);
connect(m_scanProcedureBtn, &QPushButton::clicked, this, &ProcedureListWidget::onScanProcedureBarcode);
connect(m_scanWorkOrderBtn, &QPushButton::clicked, this, &ProcedureListWidget::onScanWorkOrderBarcode);
connect(m_procedureList, &QListWidget::itemClicked, this, &ProcedureListWidget::onProcedureItemClicked);
connect(m_procedureList, &QListWidget::itemDoubleClicked, this, &ProcedureListWidget::onStartProcedure);
connect(m_startBtn, &QPushButton::clicked, this, &ProcedureListWidget::onStartProcedure);
}
void ProcedureListWidget::refreshList()
{
// 尝试多个可能的 procedures 目录位置
QStringList possiblePaths;
possiblePaths << QCoreApplication::applicationDirPath() + "/procedures";
possiblePaths << QCoreApplication::applicationDirPath() + "/../../procedures";
possiblePaths << QCoreApplication::applicationDirPath() + "/../../../procedures";
possiblePaths << QCoreApplication::applicationDirPath() + "/../../../../procedures";
QString proceduresDir;
for (const QString &path : possiblePaths)
{
QString absPath = QDir(path).absolutePath();
qDebug() << "Checking procedures path:" << absPath << "exists:" << QDir(absPath).exists();
if (QDir(absPath).exists())
{
proceduresDir = absPath;
break;
}
}
if (proceduresDir.isEmpty())
{
qWarning() << "Could not find procedures directory! Tried paths:" << possiblePaths;
proceduresDir = QCoreApplication::applicationDirPath() + "/procedures"; // 使用默认路径
}
qDebug() << "Loading procedures from:" << proceduresDir;
auto procedures = m_manager->loadProcedureList(proceduresDir);
updateProcedureList(procedures);
}
void ProcedureListWidget::updateProcedureList(const QVector<ProcedureSummary> &procedures)
{
m_procedureList->clear();
for (const auto &proc : procedures)
{
auto *item = new QListWidgetItem();
item->setData(Qt::UserRole, proc.id);
item->setText(QString("%1\n%2\n版本: %3").arg(proc.id).arg(proc.name).arg(proc.version));
item->setSizeHint(QSize(0, 80));
m_procedureList->addItem(item);
}
}
void ProcedureListWidget::onSearchTextChanged(const QString &text)
{
updateProcedureList(m_manager->searchProcedures(text));
}
void ProcedureListWidget::onScanProcedureBarcode()
{
OverlayDialog::information(this, "扫码", "请将条码对准扫描窗口...");
}
void ProcedureListWidget::onScanWorkOrderBarcode()
{
OverlayDialog::information(this, "扫码", "请将工单条码对准扫描窗口...");
}
void ProcedureListWidget::onProcedureItemClicked(QListWidgetItem *item)
{
m_selectedProcedureId = item->data(Qt::UserRole).toString();
m_startBtn->setEnabled(!m_selectedProcedureId.isEmpty());
}
void ProcedureListWidget::onStartProcedure()
{
if (m_selectedProcedureId.isEmpty())
{
OverlayDialog::warning(this, "提示", "请先选择一个规程");
return;
}
QString workOrder = m_workOrderEdit->text().trimmed();
if (!workOrder.isEmpty())
{
m_manager->setWorkOrderId(workOrder);
}
emit procedureSelected(m_selectedProcedureId);
}