增加通讯协议

This commit is contained in:
xu
2026-10-14 09:59:42 +08:00
parent 32878a9a80
commit 950e9e6c9e
102 changed files with 5538 additions and 2679 deletions
+15 -8
View File
@@ -9,9 +9,11 @@ QSize LedIndicator::sizeHint() const
QFont f = font();
f.setPixelSize(m_textPx);
const QFontMetrics fm(f);
const int textW = fm.horizontalAdvance(m_text);
if (m_dotAfter)
return QSize(textW + 10 + m_radius * 2 + 10, 52); // 文字 + 间距 + 圆点区 + 右侧 10px
// 宽度 = 文字起点(圆点区 + 左侧 10px) + 文字宽度 + 右侧 10px
const int w = textLeft() + fm.horizontalAdvance(m_text) + 10;
return QSize(w, 52); // 高度与构造函数 setFixedHeight(52) 一致
return QSize(textLeft() + textW + 10, 52); // 高度与构造函数 setFixedHeight(52) 一致
}
LedIndicator::LedIndicator(const QString& text, QWidget* parent)
@@ -55,6 +57,13 @@ void LedIndicator::paintEvent(QPaintEvent*)
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
// 文字度量:圆点位置取决于文字宽度(圆点在文字后时)
QFont f = p.font();
f.setPixelSize(m_textPx);
p.setFont(f);
const QFontMetrics fm(f);
const int textW = fm.horizontalAdvance(m_text);
// 中心圆点颜色
QColor color = QColor(C::DISABLED); // 灰
switch (m_state) {
@@ -70,7 +79,7 @@ void LedIndicator::paintEvent(QPaintEvent*)
if ((m_state == RedBlink || m_state == YellowBlink) && !m_on)
color.setAlpha(102);
const QPointF c(m_radius + 8, height() / 2.0);
const QPointF c(m_dotAfter ? textW + 10 + m_radius : m_radius + 8, height() / 2.0);
// 外发光
if (color.alpha() > 0) {
@@ -93,11 +102,9 @@ void LedIndicator::paintEvent(QPaintEvent*)
p.setPen(QPen(QColor(C::BORDER), 1));
p.drawEllipse(c, m_radius, m_radius);
// 文字
// 文字(圆点在文字后时,文字从控件左边缘开始)
p.setPen(QColor(C::TEXT));
QFont f = p.font();
f.setPixelSize(m_textPx);
p.setFont(f);
const QRectF textRect(textLeft(), 0, width() - textLeft() - 10, height());
const QRectF textRect(m_dotAfter ? 0 : textLeft(), 0,
m_dotAfter ? textW : width() - textLeft() - 10, height());
p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_text);
}