#include "roomwidget.h" #include "room.h" #include #include #include RoomWidget::RoomWidget(const room& r, QWidget *parent) : QWidget(parent) { setMaximumHeight(120); nameLabel = new QLabel(r.getName()); nameLabel->setStyleSheet("font-size: 24px; font-weight: bold;"); nameLabel->setAlignment(Qt::AlignCenter); co2Label = new QLabel; tempLabel = new QLabel; noiseLabel = new QLabel; fanBar = new QProgressBar; fanBar->setMinimum(0); fanBar->setMaximum(100); fanBar->setTextVisible(false); fanPercentLabel = new QLabel; fanPercentLabel->setAlignment(Qt::AlignRight); modButton = new QPushButton("Modificar"); connect(modButton, &QPushButton::clicked, this, &RoomWidget::modifyRequested); QVBoxLayout *infoLayout = new QVBoxLayout; infoLayout->addWidget(co2Label); infoLayout->addWidget(tempLabel); infoLayout->addWidget(noiseLabel); QHBoxLayout *fanLayout = new QHBoxLayout; fanLayout->addWidget(new QLabel("Velocidad del Ventilador")); fanLayout->addWidget(fanBar); fanLayout->addWidget(fanPercentLabel); infoLayout->addLayout(fanLayout); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(nameLabel); mainLayout->addLayout(infoLayout); QFont monoFont; QStringList monospaceFonts = QFontDatabase::systemFont(QFontDatabase::FixedFont).families(); if (!monospaceFonts.isEmpty()) { monoFont = QFont(monospaceFonts.first()); } else { monoFont = QFont("Courier New"); } monoFont.setFixedPitch(true); co2Label->setFont(monoFont); tempLabel->setFont(monoFont); noiseLabel->setFont(monoFont); setLayout(mainLayout); updateDisplay(r); } void RoomWidget::updateDisplay(const room& r) { co2Label->setText(QString("CO2 [ppm]: %1").arg(r.getCO2())); tempLabel->setText(QString("t [°C]: %1").arg(r.getTemp())); noiseLabel->setText(QString("Ruido [dB]: %1").arg(r.getNoise())); fanBar->setValue(r.getFanPercent()); fanPercentLabel->setText(QString("%1%").arg(r.getFanPercent())); }