feat:初始化wuhan_QT界面代码

This commit is contained in:
xu
2026-09-09 17:00:37 +08:00
commit 40473ad10b
537 changed files with 23934 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
#include "titlebar.h"
#include "ledindicator.h"
#include "appcontext.h"
#include "udpcommunication.h"
#include "confirmdialog.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QTime>
#include "global.h"
#include <QStyle>
TitleBar::TitleBar(AppContext* ctx, QWidget* parent)
: QWidget(parent), m_ctx(ctx)
{
setObjectName("TitleBar");
setFixedHeight(98);
setStyleSheet(QString("QWidget#TitleBar{background-color:%1;border-bottom:1px solid %2;}")
.arg(C::PANEL, C::BORDER));
QHBoxLayout* lay = new QHBoxLayout(this);
lay->setContentsMargins(24, 0, 24, 0);
lay->setSpacing(20);
// 通信状态
m_comm = new LedIndicator("通信正常", this);
m_comm->setState(LedIndicator::Green);
lay->addWidget(m_comm);
// 标题(居中)
m_title = new QLabel("", this);
m_title->setAlignment(Qt::AlignCenter);
m_title->setStyleSheet(QString("color:%1;font-size:40px;font-weight:700;").arg(C::TEXT));
lay->addWidget(m_title, 1);
// 时间
m_time = new QLabel("", this);
m_time->setStyleSheet(QString("color:%1;font-size:26px;").arg(C::TEXT_SUB));
m_time->setAlignment(Qt::AlignCenter);
lay->addWidget(m_time);
// 软急停按钮
m_estop = new QPushButton("急停", this);
m_estop->setProperty("variant", "estop");
m_estop->setFixedSize(130, 64);
connect(m_estop, &QPushButton::clicked, this, [this]() {
if (m_ctx->estopTriggered) {
if (ConfirmDialog::confirm(window(), "急停复位", "确定复位急停并恢复系统?"))
m_ctx->resetEstop();
} else {
m_ctx->triggerEstop();
}
});
lay->addWidget(m_estop);
// 通信状态刷新
connect(m_ctx->comm(), &UdpCommunication::commOkChanged, this, [this](bool ok) {
if (ok) { m_comm->setText("通信正常"); m_comm->setState(LedIndicator::Green); }
else { m_comm->setText("通信异常"); m_comm->setState(LedIndicator::RedBlink); }
});
// 急停状态刷新
connect(m_ctx, &AppContext::estopChanged, this, &TitleBar::updateEstop);
updateEstop();
// 时钟
m_clock = new QTimer(this);
connect(m_clock, &QTimer::timeout, this, &TitleBar::updateTime);
m_clock->start(1000);
updateTime();
}
void TitleBar::setTitle(const QString& title)
{
m_title->setText(title);
}
void TitleBar::setEstopVisible(bool visible)
{
m_estop->setVisible(visible);
}
void TitleBar::updateEstop()
{
if (m_ctx->estopTriggered) {
m_estop->setText("复位");
m_estop->setProperty("variant", "danger");
} else {
m_estop->setText("急停");
m_estop->setProperty("variant", "estop");
}
m_estop->style()->unpolish(m_estop);
m_estop->style()->polish(m_estop);
}
void TitleBar::updateTime()
{
m_time->setText(QTime::currentTime().toString("HH:mm"));
}