FemaLocalSoftware/sensorwidget.cpp

131 lines
6.0 KiB
C++
Raw Normal View History

2024-11-28 08:02:59 +00:00
#include "sensorwidget.h"
#include <QSpacerItem>
SensorWidget::SensorWidget(QWidget *parent,
const QString &title,
const QString &value,
const QString &incident)
: QFrame(parent), titleLabel(new QLabel(this)), valueLabel(new QLabel(this)), incidentLabel(new QLabel(this)), layout(new QVBoxLayout(this))
{
setFrameStyle(QFrame::Box);
setLineWidth(1);
setStyleSheet("QFrame { border: 2px solid rgba(229, 231, 235, 0.70);; border-radius: 10px; background: rgba(255, 255, 255, 0.70)}");
setFixedSize(250, 200);
layout->addWidget(titleLabel);
layout->addSpacerItem(new QSpacerItem(1, 55, QSizePolicy::Fixed, QSizePolicy::Fixed));
layout->addWidget(valueLabel);
layout->addWidget(incidentLabel);
// Стиль для нормального состояния
titleLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
valueLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
incidentLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: rgba(19, 56, 95, 0.5);"
"border: 0;"
"background: transparent;");
titleLabel->setText(title);
valueLabel->setText(value);
incidentLabel->setText(incident);
layout->setContentsMargins(10, 10, 10, 10); // Внутренние отступы
layout->setSpacing(5); // Отступы между текстами (кроме спейсеров)
setLayout(layout);
}
void SensorWidget::setErrorState(bool hasError,
const QString &title,
const QString &value,
const QString &incident)
{
// Включение ошибки
if (hasError) {
// Изменение текста и стиля для отображения ошибки
setStyleSheet("QFrame { border: 2px solid #FF453A; border-radius: 10px; background: rgba(255, 69, 58, 0.25);}");
titleLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
valueLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #FF453A;"
"border: 0;"
"background: transparent;");
incidentLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
} else {
// Восстановление нормального состояния
setStyleSheet("QFrame { border: 2px solid rgba(229, 231, 235, 0.70);; border-radius: 10px; background: transparent}");
titleLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
valueLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: #13385F;"
"border: 0;"
"background: transparent;");
incidentLabel->setStyleSheet("font-family: Inter;"
"font-size: 24px;"
"font-weight: 400;"
"line-height: 29.05px;"
"text-align: left;"
"color: rgba(19, 56, 95, 0.5);"
"border: 0;"
"background: transparent;");
}
titleLabel->setText(title);
valueLabel->setText(value);
incidentLabel->setText(incident);
}