FemaLocalSoftware/logwidget.cpp
lopata29435_NSK 3af06d02ec finish
2025-01-08 05:13:48 +07:00

72 lines
2.1 KiB
C++

#include "logwidget.h"
#include <QHBoxLayout>
LogWidget::LogWidget(QMap<QString, QMap<QString, QPair<QString, QString>>> &translate,
const QString &time,
const QString &log,
const QString &sensorId,
const QString &group,
const int status,
QWidget *parent)
: QWidget(parent)
, _translate(translate)
{
setAttribute(Qt::WA_StyledBackground);
setStyleSheet(R"(
QWidget {
border: 1px solid #E5E7EB;
background-color: transparent;
}
)");
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setSpacing(70);
mainLayout->setContentsMargins(25, 5, 25, 5);
setLayout(mainLayout);
timeLabel = createLabel(time, 100, 230);
logLabel = createLabel(log, 100, 250);
sensorIdLabel = createLabel(translate[group][sensorId].second, 150, 220);
groupLabel = createLabel(translate[group][sensorId].first, 150, 100);
QString msg;
if (status == 0) {
msg = "Отладка";
} else if (status == 1) {
msg = "Информация";
} else if (status == 2) {
msg = "Предупреждение";
} else if (status == 3) {
msg = "Ошибка";
} else {
msg = "Экстренно";
}
statusLabel = createLabel(msg, 100, 120);
mainLayout->addWidget(timeLabel);
mainLayout->addWidget(logLabel);
mainLayout->addWidget(sensorIdLabel);
mainLayout->addWidget(groupLabel);
mainLayout->addWidget(statusLabel);
}
QLabel *LogWidget::createLabel(const QString &text, int minSize, int maxSize)
{
QLabel *label = new QLabel(text);
label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
label->setWordWrap(true);
label->setMinimumWidth(minSize);
label->setMaximumWidth(maxSize);
label->setFixedHeight(200);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
label->setStyleSheet(R"(
background: transparent;
font-family: Inter;
font-size: 20px;
font-weight: 400;
color: #13385F;
border: none;
)");
return label;
}