自检页面调试完成
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
#include "ledindicator.h"
|
||||
#include <QPainter>
|
||||
#include <QRadialGradient>
|
||||
#include <QFontMetrics>
|
||||
#include "global.h"
|
||||
|
||||
QSize LedIndicator::sizeHint() const
|
||||
{
|
||||
QFont f = font();
|
||||
f.setPixelSize(m_textPx);
|
||||
const QFontMetrics fm(f);
|
||||
// 宽度 = 文字起点(圆点区 + 左侧 10px) + 文字宽度 + 右侧 10px
|
||||
const int w = textLeft() + fm.horizontalAdvance(m_text) + 10;
|
||||
return QSize(w, 52); // 高度与构造函数 setFixedHeight(52) 一致
|
||||
}
|
||||
|
||||
LedIndicator::LedIndicator(const QString& text, QWidget* parent)
|
||||
: QWidget(parent), m_text(text)
|
||||
{
|
||||
@@ -35,6 +46,7 @@ void LedIndicator::setState(State s)
|
||||
void LedIndicator::setText(const QString& t)
|
||||
{
|
||||
m_text = t;
|
||||
updateGeometry(); // 文字变了,重新按新宽度请求布局
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -84,8 +96,8 @@ void LedIndicator::paintEvent(QPaintEvent*)
|
||||
// 文字
|
||||
p.setPen(QColor(C::TEXT));
|
||||
QFont f = p.font();
|
||||
f.setPixelSize(24);
|
||||
f.setPixelSize(m_textPx);
|
||||
p.setFont(f);
|
||||
const QRectF textRect(m_radius * 2 + 16, 0, width() - m_radius * 2 - 16, height());
|
||||
const QRectF textRect(textLeft(), 0, width() - textLeft() - 10, height());
|
||||
p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_text);
|
||||
}
|
||||
|
||||
@@ -17,19 +17,24 @@ public:
|
||||
|
||||
void setState(State s);
|
||||
void setText(const QString& t);
|
||||
void setTextPixelSize(int px) { m_textPx = px; updateGeometry(); update(); } // 文字字号
|
||||
void setRadius(int r) { m_radius = r; updateGeometry(); update(); } // 圆形指示点半径
|
||||
State state() const { return m_state; }
|
||||
|
||||
QSize sizeHint() const override { return QSize(140, 44); }
|
||||
QSize sizeHint() const override; // 宽度按文字实际宽度计算,避免文字被裁
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
|
||||
private:
|
||||
int textLeft() const { return m_radius * 2 + 18; } // 文字起点:圆点区 + 左侧 10px 留白
|
||||
|
||||
State m_state = Off;
|
||||
QString m_text;
|
||||
QTimer* m_blink = nullptr;
|
||||
bool m_on = true;
|
||||
int m_radius = 16; // 圆形指示点 32×32
|
||||
int m_textPx = 24; // 文字字号
|
||||
};
|
||||
|
||||
#endif // LEDINDICATOR_H
|
||||
|
||||
+36
-19
@@ -18,31 +18,49 @@ TitleBar::TitleBar(AppContext* ctx, QWidget* parent)
|
||||
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);
|
||||
// 左侧区(通信状态)
|
||||
QWidget* leftBox = new QWidget(this);
|
||||
QHBoxLayout* leftLay = new QHBoxLayout(leftBox);
|
||||
leftLay->setContentsMargins(0, 0, 0, 0);
|
||||
leftLay->setSpacing(20);
|
||||
m_comm = new LedIndicator("通信正常", leftBox);
|
||||
m_comm->setState(LedIndicator::Green);
|
||||
lay->addWidget(m_comm);
|
||||
leftLay->addWidget(m_comm);
|
||||
leftLay->addStretch(1);
|
||||
|
||||
// 右侧区(时间 + 软急停)
|
||||
QWidget* rightBox = new QWidget(this);
|
||||
QHBoxLayout* rightLay = new QHBoxLayout(rightBox);
|
||||
rightLay->setContentsMargins(0, 0, 0, 0);
|
||||
rightLay->setSpacing(20);
|
||||
m_time = new QLabel("", rightBox);
|
||||
m_time->setStyleSheet(QString("color:%1;font-size:60px;").arg(C::TEXT_SUB));
|
||||
m_time->setAlignment(Qt::AlignCenter);
|
||||
m_estop = new QPushButton("急停", rightBox);
|
||||
m_estop->setProperty("variant", "estop");
|
||||
m_estop->setStyleSheet("font-size:60px;");
|
||||
m_estop->setFixedSize(180, 80);
|
||||
rightLay->addStretch(1);
|
||||
rightLay->addWidget(m_time);
|
||||
rightLay->addWidget(m_estop);
|
||||
|
||||
// 左右两侧等宽 → 中间标题恰好居中于屏幕
|
||||
const int sideW = 380; // 需 >= 较宽一侧所需宽度(右侧:时间 + 急停)
|
||||
leftBox->setFixedWidth(sideW);
|
||||
rightBox->setFixedWidth(sideW);
|
||||
|
||||
// 标题(居中)
|
||||
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));
|
||||
m_title->setStyleSheet(QString("color:%1;font-size:60px;font-weight:700;").arg(C::TEXT));
|
||||
|
||||
QHBoxLayout* lay = new QHBoxLayout(this);
|
||||
lay->setContentsMargins(24, 6, 24, 6);
|
||||
lay->setSpacing(0);
|
||||
lay->addWidget(leftBox);
|
||||
lay->addWidget(m_title, 1);
|
||||
lay->addWidget(rightBox);
|
||||
|
||||
// 时间
|
||||
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(), "急停复位", "确定复位急停并恢复系统?"))
|
||||
@@ -51,7 +69,6 @@ TitleBar::TitleBar(AppContext* ctx, QWidget* parent)
|
||||
m_ctx->triggerEstop();
|
||||
}
|
||||
});
|
||||
lay->addWidget(m_estop);
|
||||
|
||||
// 通信状态刷新
|
||||
connect(m_ctx->comm(), &UdpCommunication::commOkChanged, this, [this](bool ok) {
|
||||
|
||||
Reference in New Issue
Block a user