LCOV - code coverage report
Current view: top level - src - temperature.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.3 % 60 56
Test Date: 2025-07-25 14:54:22 Functions: 100.0 % 10 10

            Line data    Source code
       1              : #include "../include/temperature.h"
       2              : 
       3            7 : Temperature::Temperature(QWidget *parent)
       4            7 :     : QWidget{parent}
       5              : {
       6            7 :     setMinimumSize(parent->width() * 0.2, parent->height() * 0.16); 
       7            7 :     setMaximumSize(parent->width() * 0.2, parent->height() * 0.16);
       8            7 :     main_layout = new QVBoxLayout(this);
       9            7 :     main_layout->setSpacing(height() * 0.05);
      10            7 :     layout = new QHBoxLayout();
      11            7 :     layout->setSpacing(width() * 0.0155); 
      12            7 :     nb_sections = 6;
      13           49 :     for (int i = 0; i < nb_sections; ++i) {
      14           42 :         QWidget *section = new QWidget(this);
      15           42 :         section->setFixedHeight(height() * 0.3);
      16           42 :         section->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
      17           42 :         layout->addWidget(section);
      18           42 :         sections.append(section);
      19              :     }
      20            7 :     main_layout->addLayout(layout);
      21            7 :     label = new QLabel(this);
      22            7 :     set_temperature(50);
      23            7 :     setLayout(main_layout); //setting layout for qwidget (no need to delete them)
      24            7 : }
      25              : 
      26           14 : Temperature::~Temperature()
      27              : {
      28            7 :     std::cout << "Remove Temperature" << std::endl;
      29           14 : }
      30              : 
      31            7 : void Temperature::set_text(int temp)
      32              : {
      33            7 :     label->setTextFormat(Qt::RichText);
      34           14 :     label->setText("<span style='font-family: Noto Sans; font-size: 22px; color: rgb(0, 120, 140);'>🌡️&nbsp;</span>"
      35           28 :         "<span style='font-family: Digital-7; font-size: 25px; color: rgb(0, 120, 140);'>" + 
      36           42 :         QString::number(temp) + "</span>"
      37              :         "<span style='font-family: Calculator; font-size: 25px; color: rgb(0, 120, 140);'> °C</span>");
      38            7 :     label->setContentsMargins(5, 0, 0, 0);
      39            7 :     label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
      40            7 :     main_layout->addWidget(label);
      41            7 : }
      42              : 
      43            7 : void Temperature::set_temperature(int temp)
      44              : {
      45            7 :     int sections_color = static_cast<int>((temp / 80.0) * nb_sections);
      46           49 :     for (int i = 0; i < nb_sections; ++i) {
      47           42 :         if (i < sections_color) {
      48           21 :             QColor sectionColor;
      49           21 :             if (temp < 60) {
      50           21 :                 int green = std::min(255, 60 + (i * (50 / nb_sections))); //from dim cyan to regular cyan
      51           21 :                 int blue = std::min(255, 80 + (i * (50 / nb_sections)));  //dim blueincrease to bright blue
      52           21 :                 sectionColor.setRgb(0, green, blue);
      53              :             } else {
      54            0 :                 int red = (i * (200 / nb_sections));         //increase red component
      55            0 :                 int green = std::min(255, 60 + (i * (20 / nb_sections)));  //decrease green
      56            0 :                 int blue = std::max(0, 80 - (i * (50 / nb_sections)));
      57            0 :                 sectionColor.setRgb(red, green, blue);
      58              :             }
      59           21 :             sections[i]->setStyleSheet(QString("background-color: %1").arg(sectionColor.name()));
      60              :         } else {
      61           21 :             QColor inactive(22, 32, 60); //dim cyan color
      62           21 :             sections[i]->setStyleSheet(QString("background-color: %1").arg(inactive.name()));
      63              :         }
      64              :     }
      65            7 :     set_text(temp);
      66            7 : }
      67              : 
      68            1 : int Temperature::get_nbsections()
      69              : {
      70            1 :     return nb_sections;
      71              : }
      72              : 
      73            1 : QVector<QWidget*> Temperature::get_sections()
      74              : {
      75            1 :     return sections;
      76              : }
      77              : 
      78            1 : QHBoxLayout* Temperature::get_layout()
      79              : {
      80            1 :     return layout;
      81              : }
      82              : 
      83            1 : QVBoxLayout* Temperature::get_mainlayout()
      84              : {
      85            1 :     return main_layout;
      86              : }
      87              : 
      88            1 : QLabel* Temperature::get_label()
      89              : {
      90            1 :     return label;
      91              : }
        

Generated by: LCOV version 2.0-1