feat(layout): 导航菜单自动刷新
-点击导航菜单对应页面自动刷新 -设备布局示意,添加背景图片及显示修改
This commit is contained in:
+183
-83
@@ -16,8 +16,8 @@
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QEvent>
|
||||
#include <QFormLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPushButton>
|
||||
#include <QMetaObject>
|
||||
#include <QPixmap>
|
||||
#include <QResizeEvent>
|
||||
#include <QSizePolicy>
|
||||
#include <QTableWidgetItem>
|
||||
@@ -125,6 +126,13 @@ QString displayOrderStatus(const QString &status)
|
||||
return status.isEmpty() ? "未采集" : status;
|
||||
}
|
||||
|
||||
QString displayInspectionMode(const QString &mode)
|
||||
{
|
||||
if (mode == "BEFORE_PLATING") return "镀金前";
|
||||
if (mode == "AFTER_PLATING") return "镀金后";
|
||||
return mode.isEmpty() ? "未设置" : mode;
|
||||
}
|
||||
|
||||
void updateStatusCell(QLabel *cell, const QString &text, const QString &color,
|
||||
bool highlighted = false)
|
||||
{
|
||||
@@ -132,10 +140,16 @@ void updateStatusCell(QLabel *cell, const QString &text, const QString &color,
|
||||
return;
|
||||
}
|
||||
cell->setText(text);
|
||||
cell->setStyleSheet(QString("QLabel { background: %1; border: %2; "
|
||||
"border-radius: 3px; color: white; font-size: 11px; }")
|
||||
.arg(color)
|
||||
.arg(highlighted ? "3px solid #ffb300" : "1px solid #ffffff"));
|
||||
const QString border = highlighted
|
||||
? "3px solid #ffb300"
|
||||
: QString("1px solid %1").arg(color);
|
||||
const bool compact = cell->property("compactStatus").toBool();
|
||||
cell->setStyleSheet(QString("QLabel { background: rgba(18, 31, 38, 190); "
|
||||
"border: %1; border-radius: 3px; color: white; "
|
||||
"font-size: %2px; padding: %3; }")
|
||||
.arg(border)
|
||||
.arg(compact ? 9 : 11)
|
||||
.arg(compact ? "2px" : "4px 6px"));
|
||||
}
|
||||
|
||||
QString boolStatus(bool valid, bool value, const QString &yes, const QString &no)
|
||||
@@ -148,6 +162,8 @@ QString boolStatus(bool valid, bool value, const QString &yes, const QString &no
|
||||
DashboardPage::DashboardPage(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::DashboardPage)
|
||||
, layoutCanvas(nullptr)
|
||||
, layoutBackground(nullptr)
|
||||
, rackBox(nullptr)
|
||||
, deviceStatusLabel(new QLabel("PLC:未采集 | 机器人:未采集 | 安全回路:未采集", this))
|
||||
, inspectionMachineCell(nullptr)
|
||||
@@ -156,7 +172,6 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
, mainControlCabinetCell(nullptr)
|
||||
, safetyDoor1Cell(nullptr)
|
||||
, safetyDoor2Cell(nullptr)
|
||||
, safetyDoor3Cell(nullptr)
|
||||
, alarmCell(nullptr)
|
||||
, markNgButton(new QPushButton("标记 NG", this))
|
||||
, stopButton(new QPushButton("终止", this))
|
||||
@@ -212,6 +227,7 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
|
||||
QVBoxLayout *processLayout = new QVBoxLayout(processBox);
|
||||
processLayout->addLayout(processSummaryLayout);
|
||||
processBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
processTable->setColumnCount(4);
|
||||
processTable->setHorizontalHeaderLabels(
|
||||
QStringList() << "工序" << "状态" << "次数" << "耗时");
|
||||
@@ -221,8 +237,18 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
processTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
processTable->setAlternatingRowColors(true);
|
||||
processTable->setMinimumHeight(150);
|
||||
processLayout->addWidget(processTable);
|
||||
ui->taskLayout->insertWidget(6, processBox);
|
||||
processTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
processLayout->addWidget(processTable, 1);
|
||||
ui->taskSpacer->changeSize(0, 0, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
ui->taskLayout->insertWidget(6, processBox, 1);
|
||||
|
||||
ui->layoutGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
ui->taskGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
ui->middleLayout->setStretch(0, 1);
|
||||
ui->middleLayout->setStretch(1, 1);
|
||||
ui->mainLayout->setStretch(0, 0);
|
||||
ui->mainLayout->setStretch(1, 4);
|
||||
ui->mainLayout->setStretch(2, 1);
|
||||
|
||||
ui->recentLogTable->setColumnCount(5);
|
||||
ui->recentLogTable->setHorizontalHeaderLabels(QStringList() << "时间" << "类型" << "模块" << "内容" << "状态");
|
||||
@@ -233,51 +259,66 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
ui->recentLogTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->recentLogTable->setAlternatingRowColors(true);
|
||||
|
||||
ui->deviceLayout->setSpacing(10);
|
||||
ui->deviceLayout->setColumnStretch(0, 1);
|
||||
ui->deviceLayout->setColumnStretch(1, 1);
|
||||
ui->deviceLayout->setColumnStretch(2, 2);
|
||||
ui->deviceLayout->setColumnStretch(3, 2);
|
||||
ui->deviceLayout->setColumnStretch(4, 2);
|
||||
ui->deviceLayout->setColumnStretch(5, 1);
|
||||
ui->deviceLayout->setRowStretch(0, 1);
|
||||
ui->deviceLayout->setRowStretch(1, 1);
|
||||
ui->deviceLayout->setRowStretch(2, 1);
|
||||
ui->deviceLayout->setRowStretch(3, 1);
|
||||
ui->deviceLayout->setRowStretch(4, 1);
|
||||
ui->deviceLayout->setRowStretch(5, 1);
|
||||
inspectionMachineCell = UiHelpers::makeStatusCell("检测机\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(inspectionMachineCell, 0, 0, 2, 2);
|
||||
ui->deviceLayout->addWidget(UiHelpers::makeStatusCell("总控电脑", "#43a047"), 0, 3);
|
||||
safetyDoor1Cell = UiHelpers::makeStatusCell("安全门 1\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(safetyDoor1Cell, 0, 4);
|
||||
robotCell = UiHelpers::makeStatusCell("机器人\n未采集", "#607d8b");
|
||||
robotCell->setFixedSize(82, 58);
|
||||
ui->deviceLayout->addWidget(robotCell, 2, 3, 2, 2, Qt::AlignCenter);
|
||||
robotControlCabinetCell = UiHelpers::makeStatusCell("机器人控制柜\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(robotControlCabinetCell, 3, 0);
|
||||
mainControlCabinetCell = UiHelpers::makeStatusCell("总控柜\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(mainControlCabinetCell, 4, 0);
|
||||
safetyDoor2Cell = UiHelpers::makeStatusCell("安全门 2\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(safetyDoor2Cell, 2, 5);
|
||||
safetyDoor3Cell = UiHelpers::makeStatusCell("安全门 3\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(safetyDoor3Cell, 5, 0);
|
||||
alarmCell = UiHelpers::makeStatusCell("PLC 报警\n未采集", "#607d8b");
|
||||
ui->deviceLayout->addWidget(alarmCell, 5, 5);
|
||||
ui->deviceLayout->setContentsMargins(8, 8, 8, 8);
|
||||
ui->deviceLayout->setSpacing(0);
|
||||
ui->layoutGroup->setMinimumSize(480, 500);
|
||||
ui->layoutGroup->installEventFilter(this);
|
||||
|
||||
rackBox = new QGroupBox("料架 2x3");
|
||||
rackBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
QGridLayout *rackLayout = new QGridLayout(rackBox);
|
||||
rackLayout->setContentsMargins(8, 18, 8, 8);
|
||||
rackLayout->setSpacing(4);
|
||||
layoutCanvas = new QWidget(ui->layoutGroup);
|
||||
layoutCanvas->setObjectName("deviceLayoutCanvas");
|
||||
layoutCanvas->setMinimumSize(440, 441);
|
||||
layoutCanvas->setStyleSheet(
|
||||
"QWidget#deviceLayoutCanvas { background: #dfe4e8; }");
|
||||
ui->deviceLayout->addWidget(layoutCanvas, 0, 0, Qt::AlignCenter);
|
||||
|
||||
layoutBackground = new QLabel(layoutCanvas);
|
||||
layoutBackground->setAlignment(Qt::AlignCenter);
|
||||
layoutBackground->setStyleSheet("background: #dfe4e8;");
|
||||
|
||||
inspectionMachineCell = UiHelpers::makeStatusCell("检测机\n未采集", "#607d8b");
|
||||
inspectionMachineCell->setParent(layoutCanvas);
|
||||
safetyDoor1Cell = UiHelpers::makeStatusCell("安全门 1\n未采集", "#607d8b");
|
||||
safetyDoor1Cell->setParent(layoutCanvas);
|
||||
robotCell = UiHelpers::makeStatusCell("机器人\n未采集", "#607d8b");
|
||||
robotCell->setParent(layoutCanvas);
|
||||
robotControlCabinetCell = UiHelpers::makeStatusCell("机器人控制柜\n未采集", "#607d8b");
|
||||
robotControlCabinetCell->setParent(layoutCanvas);
|
||||
mainControlCabinetCell = UiHelpers::makeStatusCell("总控柜\n未采集", "#607d8b");
|
||||
mainControlCabinetCell->setParent(layoutCanvas);
|
||||
safetyDoor2Cell = UiHelpers::makeStatusCell("安全门 2\n未采集", "#607d8b");
|
||||
safetyDoor2Cell->setParent(layoutCanvas);
|
||||
alarmCell = UiHelpers::makeStatusCell("PLC 报警\n未采集", "#607d8b");
|
||||
alarmCell->setParent(layoutCanvas);
|
||||
|
||||
rackBox = new QGroupBox("料架 2x3", layoutCanvas);
|
||||
rackBox->setObjectName("deviceRack");
|
||||
rackBox->setStyleSheet(
|
||||
"QGroupBox#deviceRack { border: 0; background: transparent; color: white; "
|
||||
"font-size: 11px; font-weight: bold; }"
|
||||
"QGroupBox#deviceRack::title { subcontrol-origin: margin; "
|
||||
"background: rgba(18, 31, 38, 190); border: 1px solid #2e7d32; "
|
||||
"border-radius: 3px; padding: 3px 8px; }");
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
QLabel *trayCell = UiHelpers::makeSquareStatusCell(
|
||||
QString("托盘 %1\n未采集").arg(i + 1), "#607d8b");
|
||||
trayCell->setParent(rackBox);
|
||||
trayCell->setMinimumSize(0, 0);
|
||||
trayCell->setProperty("compactStatus", true);
|
||||
rackTrayCells.append(trayCell);
|
||||
rackLayout->addWidget(trayCell, i / 3, i % 3, Qt::AlignCenter);
|
||||
}
|
||||
ui->deviceLayout->addWidget(rackBox, 4, 2, 2, 3);
|
||||
updateRackSize();
|
||||
|
||||
updateStatusCell(inspectionMachineCell, "检测机\n未采集", "#607d8b");
|
||||
updateStatusCell(robotCell, "机器人\n未采集", "#607d8b");
|
||||
updateStatusCell(robotControlCabinetCell, "机器人控制柜\n未采集", "#607d8b");
|
||||
updateStatusCell(mainControlCabinetCell, "总控柜\n未采集", "#607d8b");
|
||||
updateStatusCell(safetyDoor1Cell, "安全门 1\n未采集", "#607d8b");
|
||||
updateStatusCell(safetyDoor2Cell, "安全门 2\n未采集", "#607d8b");
|
||||
updateStatusCell(alarmCell, "PLC 报警\n未采集", "#607d8b");
|
||||
for (int i = 0; i < rackTrayCells.size(); ++i) {
|
||||
updateStatusCell(rackTrayCells.at(i),
|
||||
QString("托盘 %1\n未采集").arg(i + 1), "#607d8b");
|
||||
}
|
||||
QTimer::singleShot(0, this, [this]() { updateDeviceLayout(); });
|
||||
|
||||
connect(ui->startButton, &QPushButton::clicked,
|
||||
this, &DashboardPage::startProduction);
|
||||
@@ -404,34 +445,102 @@ void DashboardPage::addLog(const QString &type, const QString &module, const QSt
|
||||
}
|
||||
}
|
||||
|
||||
bool DashboardPage::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == ui->layoutGroup
|
||||
&& (event->type() == QEvent::Resize
|
||||
|| event->type() == QEvent::Show
|
||||
|| event->type() == QEvent::LayoutRequest)) {
|
||||
QTimer::singleShot(0, this, [this]() { updateDeviceLayout(); });
|
||||
}
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void DashboardPage::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
updateRackSize();
|
||||
QTimer::singleShot(0, this, [this]() { updateDeviceLayout(); });
|
||||
}
|
||||
|
||||
void DashboardPage::updateRackSize()
|
||||
void DashboardPage::updateDeviceLayout()
|
||||
{
|
||||
if (!rackBox || rackTrayCells.isEmpty()) {
|
||||
if (!layoutCanvas || !layoutBackground || !rackBox
|
||||
|| rackTrayCells.size() != 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int spacing = 4;
|
||||
const int leftMargin = 8;
|
||||
const int rightMargin = 8;
|
||||
const int topMargin = 18;
|
||||
const int bottomMargin = 8;
|
||||
const int maxRackHeight = qMax(150, ui->layoutGroup->height() / 3);
|
||||
const int maxCellByHeight = (maxRackHeight - topMargin - bottomMargin - spacing) / 2;
|
||||
const int maxCellByWidth = (ui->layoutGroup->width() - leftMargin - rightMargin - spacing * 2) / 3;
|
||||
const int cellSide = qMax(52, qMin(maxCellByHeight, maxCellByWidth));
|
||||
const int rackWidth = leftMargin + rightMargin + cellSide * 3 + spacing * 2;
|
||||
const int rackHeight = topMargin + bottomMargin + cellSide * 2 + spacing;
|
||||
|
||||
for (QLabel *cell : rackTrayCells) {
|
||||
cell->setFixedSize(cellSide, cellSide);
|
||||
static const QPixmap sourcePixmap(":/layout/Layout.png");
|
||||
if (sourcePixmap.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QSize available = ui->deviceLayout->contentsRect().size();
|
||||
if (available.width() <= 0 || available.height() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const qreal imageRatio = qreal(sourcePixmap.width()) / sourcePixmap.height();
|
||||
int canvasWidth = available.width();
|
||||
int canvasHeight = qRound(canvasWidth / imageRatio);
|
||||
if (canvasHeight > available.height()) {
|
||||
canvasHeight = available.height();
|
||||
canvasWidth = qRound(canvasHeight * imageRatio);
|
||||
}
|
||||
const QSize canvasSize(qMax(1, canvasWidth), qMax(1, canvasHeight));
|
||||
if (layoutCanvas->size() != canvasSize) {
|
||||
layoutCanvas->setFixedSize(canvasSize);
|
||||
}
|
||||
|
||||
layoutBackground->setGeometry(layoutCanvas->rect());
|
||||
layoutBackground->setPixmap(sourcePixmap.scaled(
|
||||
canvasSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
layoutBackground->lower();
|
||||
|
||||
const int width = canvasSize.width();
|
||||
const int height = canvasSize.height();
|
||||
const auto place = [width, height](QWidget *widget, qreal x, qreal y,
|
||||
qreal relativeWidth, int minimumWidth) {
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
const int widgetWidth = qMin(width,
|
||||
qMax(minimumWidth, qRound(width * relativeWidth)));
|
||||
const int widgetHeight = qMin(height,
|
||||
qMax(30, widget->sizeHint().height()));
|
||||
const int left = qBound(0, qRound(width * x), width - widgetWidth);
|
||||
const int top = qBound(0, qRound(height * y), height - widgetHeight);
|
||||
widget->setGeometry(left, top, widgetWidth, widgetHeight);
|
||||
widget->raise();
|
||||
};
|
||||
|
||||
place(inspectionMachineCell, 0.09, 0.09, 0.27, 100);
|
||||
place(safetyDoor1Cell, 0.435, 0.025, 0.13, 72);
|
||||
place(robotCell, 0.67, 0.29, 0.21, 86);
|
||||
place(robotControlCabinetCell, 0.07, 0.57, 0.17, 84);
|
||||
place(mainControlCabinetCell, 0.07, 0.77, 0.15, 76);
|
||||
place(safetyDoor2Cell, 0.38, 0.93, 0.12, 72);
|
||||
place(alarmCell, 0.86, 0.93, 0.125, 82);
|
||||
|
||||
const int rackX = qRound(width * 0.53);
|
||||
const int rackY = qRound(height * 0.615);
|
||||
const int rackWidth = qMin(width - rackX, qRound(width * 0.36));
|
||||
const int rackHeight = qMin(height - rackY, qRound(height * 0.30));
|
||||
rackBox->setGeometry(rackX, rackY, rackWidth, rackHeight);
|
||||
rackBox->raise();
|
||||
|
||||
const int trayWidth = qMin(rackWidth, qMax(1, qRound(rackWidth * 0.30)));
|
||||
const int trayHeight = qMin(rackHeight,
|
||||
qMax(30, qRound(rackHeight * 0.22)));
|
||||
const qreal trayX[] = {0.03, 0.35, 0.67};
|
||||
const qreal trayY[] = {0.28, 0.70};
|
||||
for (int i = 0; i < rackTrayCells.size(); ++i) {
|
||||
const int left = qBound(0, qRound(rackWidth * trayX[i % 3]),
|
||||
rackWidth - trayWidth);
|
||||
const int top = qBound(0, qRound(rackHeight * trayY[i / 3]),
|
||||
rackHeight - trayHeight);
|
||||
rackTrayCells.at(i)->setGeometry(left, top, trayWidth, trayHeight);
|
||||
rackTrayCells.at(i)->raise();
|
||||
}
|
||||
rackBox->setFixedSize(rackWidth, rackHeight);
|
||||
}
|
||||
|
||||
void DashboardPage::startProduction()
|
||||
@@ -1186,17 +1295,13 @@ void DashboardPage::onDeviceStatusChanged(const DeviceStatus &status)
|
||||
: status.robotRunning || status.robotIdle
|
||||
? "#2e7d32" : "#d32f2f");
|
||||
updateStatusCell(robotControlCabinetCell,
|
||||
QString("机器人控制柜\n%1").arg(boolStatus(
|
||||
status.statusValid, status.robotControlCabinetReady,
|
||||
"正常", "未就绪")),
|
||||
!status.statusValid ? "#607d8b"
|
||||
: status.robotControlCabinetReady ? "#2e7d32" : "#d32f2f");
|
||||
QString("机器人控制柜\n%1").arg(
|
||||
offline ? "离线" : "就绪"),
|
||||
offline ? "#607d8b" : "#2e7d32");
|
||||
updateStatusCell(mainControlCabinetCell,
|
||||
QString("总控柜\n%1").arg(boolStatus(
|
||||
status.statusValid, status.mainControlCabinetReady,
|
||||
"正常", "未就绪")),
|
||||
!status.statusValid ? "#607d8b"
|
||||
: status.mainControlCabinetReady ? "#2e7d32" : "#d32f2f");
|
||||
QString("总控柜\n%1").arg(
|
||||
offline ? "离线" : "就绪"),
|
||||
offline ? "#607d8b" : "#2e7d32");
|
||||
updateStatusCell(safetyDoor1Cell,
|
||||
QString("安全门 1\n%1").arg(boolStatus(
|
||||
status.statusValid, status.safetyDoor1Closed,
|
||||
@@ -1209,12 +1314,6 @@ void DashboardPage::onDeviceStatusChanged(const DeviceStatus &status)
|
||||
"关闭", "打开")),
|
||||
!status.statusValid ? "#607d8b"
|
||||
: status.safetyDoor2Closed ? "#2e7d32" : "#d32f2f");
|
||||
updateStatusCell(safetyDoor3Cell,
|
||||
QString("安全门 3\n%1").arg(boolStatus(
|
||||
status.statusValid, status.safetyDoor3Closed,
|
||||
"关闭", "打开")),
|
||||
!status.statusValid ? "#607d8b"
|
||||
: status.safetyDoor3Closed ? "#2e7d32" : "#d32f2f");
|
||||
updateStatusCell(alarmCell,
|
||||
QString("PLC 报警\n%1").arg(boolStatus(
|
||||
status.statusValid, status.activeAlarm,
|
||||
@@ -1331,9 +1430,10 @@ void DashboardPage::loadCurrentOrder()
|
||||
&& !workpieces.isEmpty();
|
||||
}
|
||||
|
||||
ui->orderLabel->setText(QString("当前订单:%1(%2)")
|
||||
ui->orderLabel->setText(QString("当前订单:%1(%2,%3)")
|
||||
.arg(order.no)
|
||||
.arg(displayOrderStatus(order.status)));
|
||||
.arg(displayOrderStatus(order.status))
|
||||
.arg(displayInspectionMode(order.inspectionMode)));
|
||||
emit currentOrderChanged(order.no);
|
||||
updateProductionStats();
|
||||
updateRackSummary();
|
||||
|
||||
Reference in New Issue
Block a user