first commit
This commit is contained in:
+153
@@ -0,0 +1,153 @@
|
||||
#include "widget.h"
|
||||
#include "ui_widget.h"
|
||||
|
||||
#include "pages/dashboardpage.h"
|
||||
#include "pages/devicepage.h"
|
||||
#include "pages/logpage.h"
|
||||
#include "pages/orderpage.h"
|
||||
#include "pages/rackpage.h"
|
||||
#include "pages/uihelpers.h"
|
||||
#include "services/logservice.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
Widget::Widget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::Widget)
|
||||
, navList(nullptr)
|
||||
, pageStack(nullptr)
|
||||
, dashboardPage(nullptr)
|
||||
, logPage(nullptr)
|
||||
, systemStateLabel(nullptr)
|
||||
, currentOrderLabel(nullptr)
|
||||
, currentWorkpieceLabel(nullptr)
|
||||
, currentStepLabel(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle("小轴多参数上下料单元管控系统");
|
||||
resize(1280, 820);
|
||||
setupStyle();
|
||||
|
||||
QVBoxLayout *rootLayout = new QVBoxLayout(this);
|
||||
rootLayout->setContentsMargins(0, 0, 0, 0);
|
||||
rootLayout->setSpacing(0);
|
||||
|
||||
setupTopBar(rootLayout);
|
||||
setupMainArea(rootLayout);
|
||||
|
||||
appendLog("生产日志", "系统", "启动", "页面原型已启动,当前为模拟模式", "成功");
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Widget::setupStyle()
|
||||
{
|
||||
setStyleSheet(
|
||||
"QWidget { font-family: 'Microsoft YaHei'; font-size: 13px; color: #1f2933; }"
|
||||
"QListWidget { background: #263238; color: #e8eef2; border: none; padding: 8px; }"
|
||||
"QListWidget::item { height: 42px; padding-left: 12px; border-radius: 4px; }"
|
||||
"QListWidget::item:selected { background: #00897b; color: white; }"
|
||||
"QPushButton { min-height: 28px; padding: 5px 12px; border: 1px solid #cfd8dc; border-radius: 4px; background: #ffffff; }"
|
||||
"QPushButton:hover { background: #eef7f5; }"
|
||||
"QPushButton#primaryButton { background: #00897b; color: white; border-color: #00897b; }"
|
||||
"QPushButton#dangerButton { background: #d32f2f; color: white; border-color: #d32f2f; }"
|
||||
"QFrame#card { background: #ffffff; border: 1px solid #d8dee4; border-radius: 6px; }"
|
||||
"QLabel#cardTitle { font-size: 15px; font-weight: bold; color: #263238; }"
|
||||
"QGroupBox { font-weight: bold; border: 1px solid #d8dee4; border-radius: 6px; margin-top: 10px; padding-top: 12px; }"
|
||||
"QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 4px; }"
|
||||
"QTableWidget { background: white; border: 1px solid #d8dee4; gridline-color: #e5e9ef; }"
|
||||
"QHeaderView::section { background: #eef3f5; padding: 6px; border: none; border-right: 1px solid #d8dee4; }"
|
||||
);
|
||||
}
|
||||
|
||||
void Widget::setupTopBar(QVBoxLayout *rootLayout)
|
||||
{
|
||||
QFrame *topBar = new QFrame;
|
||||
topBar->setStyleSheet("QFrame { background: #f5f7f8; border-bottom: 1px solid #d8dee4; }");
|
||||
|
||||
QHBoxLayout *topLayout = new QHBoxLayout(topBar);
|
||||
topLayout->setContentsMargins(14, 8, 14, 8);
|
||||
topLayout->setSpacing(10);
|
||||
topLayout->addWidget(new QLabel("小轴单元"));
|
||||
|
||||
systemStateLabel = UiHelpers::makeBadge("系统:待机", "#607d8b");
|
||||
currentOrderLabel = UiHelpers::makeBadge("订单:ORD-20260808-001", "#455a64");
|
||||
currentWorkpieceLabel = UiHelpers::makeBadge("工件:WP-0001", "#455a64");
|
||||
currentStepLabel = UiHelpers::makeBadge("工序:待取料", "#00897b");
|
||||
|
||||
topLayout->addWidget(systemStateLabel);
|
||||
topLayout->addWidget(currentOrderLabel);
|
||||
topLayout->addWidget(currentWorkpieceLabel);
|
||||
topLayout->addWidget(currentStepLabel);
|
||||
topLayout->addStretch();
|
||||
topLayout->addWidget(UiHelpers::makeBadge("PLC:模拟", "#795548"));
|
||||
topLayout->addWidget(UiHelpers::makeBadge("机器人:模拟", "#795548"));
|
||||
topLayout->addWidget(UiHelpers::makeBadge("安全门:关闭", "#2e7d32"));
|
||||
|
||||
rootLayout->addWidget(topBar);
|
||||
}
|
||||
|
||||
void Widget::setupMainArea(QVBoxLayout *rootLayout)
|
||||
{
|
||||
QHBoxLayout *bodyLayout = new QHBoxLayout;
|
||||
bodyLayout->setContentsMargins(0, 0, 0, 0);
|
||||
bodyLayout->setSpacing(0);
|
||||
|
||||
navList = new QListWidget;
|
||||
navList->setFixedWidth(170);
|
||||
navList->addItems(QStringList() << "控制面板" << "订单管理" << "料架/托盘" << "设备状态" << "日志");
|
||||
navList->setCurrentRow(0);
|
||||
bodyLayout->addWidget(navList);
|
||||
|
||||
dashboardPage = new DashboardPage(this);
|
||||
OrderPage *orderPage = new OrderPage(this);
|
||||
RackPage *rackPage = new RackPage(this);
|
||||
DevicePage *devicePage = new DevicePage(this);
|
||||
logPage = new LogPage(this);
|
||||
|
||||
pageStack = new QStackedWidget;
|
||||
pageStack->addWidget(dashboardPage);
|
||||
pageStack->addWidget(orderPage);
|
||||
pageStack->addWidget(rackPage);
|
||||
pageStack->addWidget(devicePage);
|
||||
pageStack->addWidget(logPage);
|
||||
bodyLayout->addWidget(pageStack, 1);
|
||||
|
||||
rootLayout->addLayout(bodyLayout, 1);
|
||||
|
||||
connect(navList, &QListWidget::currentRowChanged, pageStack, &QStackedWidget::setCurrentIndex);
|
||||
connect(dashboardPage, &DashboardPage::systemStateChanged, this, [this](const QString &state) {
|
||||
systemStateLabel->setText("系统:" + state);
|
||||
});
|
||||
connect(dashboardPage, &DashboardPage::currentStepChanged, this, [this](const QString &step) {
|
||||
currentStepLabel->setText("工序:" + step);
|
||||
});
|
||||
connect(dashboardPage, &DashboardPage::logRequested, this, &Widget::appendLog);
|
||||
connect(orderPage, &OrderPage::logRequested, this, &Widget::appendLog);
|
||||
connect(rackPage, &RackPage::logRequested, this, &Widget::appendLog);
|
||||
}
|
||||
|
||||
void Widget::appendLog(const QString &type, const QString &module, const QString &action,
|
||||
const QString &content, const QString &status)
|
||||
{
|
||||
if (dashboardPage) {
|
||||
dashboardPage->addLog(type, module, content, status);
|
||||
}
|
||||
if (logPage) {
|
||||
logPage->addLog(type, module, action, content, status);
|
||||
}
|
||||
|
||||
QString error;
|
||||
if (!LogService::instance().record(type, module, action, content, status, &error)) {
|
||||
qWarning() << "Failed to persist operation log:" << error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user