diff --git a/soft/thermostat/inc/zoneitem.h b/soft/thermostat/inc/zoneitem.h index be76d3e..f457fcd 100644 --- a/soft/thermostat/inc/zoneitem.h +++ b/soft/thermostat/inc/zoneitem.h @@ -9,19 +9,18 @@ #ifndef ZONEITEM_H #define ZONEITEM_H -#include #include #include -#include #include "boost_dlg.h" -class ZoneItem : public QWidget +class ZoneItem : public QLabel { Q_OBJECT public: - explicit ZoneItem(const QString &zoneName, QWidget *parent = Q_NULLPTR); + explicit ZoneItem(const QString &zoneName, QWidget *parent = Q_NULLPTR, + Qt::WindowFlags f = Qt::WindowFlags()); ~ZoneItem(); void refresh(void); @@ -33,10 +32,11 @@ public: QString m_name; struct boost_data m_boost; - QPushButton m_zoneNameBtn; - QPushButton m_temperatureBtn; - QPushButton m_hygroBtn; +signals: + void clicked(); +protected: + void mouseReleaseEvent(QMouseEvent* event); }; #endif // ZONEITEM_H diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index 1c8bc9d..3066392 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -37,14 +37,9 @@ MainWindow::MainWindow(QWidget *parent) : for (int i = 0; i < s->nbZones(); i++) { zone = new ZoneItem(s->m_rooms.at(i).name, this); - zone->m_zoneNameBtn.setProperty("idx", i); - zone->m_temperatureBtn.setProperty("idx", i); - zone->m_hygroBtn.setProperty("idx", i); + zone->setProperty("idx", i); zone->m_target_temperature = get_target_temperature(i); - /* TODO: make a big clickable zone instead of 3 tiny buttons */ - connect(&(zone->m_zoneNameBtn), SIGNAL(clicked()), this, SLOT(show_boost())); - connect(&(zone->m_temperatureBtn), SIGNAL(clicked()), this, SLOT(show_boost())); - connect(&(zone->m_hygroBtn), SIGNAL(clicked()), this, SLOT(show_boost())); + connect(zone, SIGNAL(clicked()), this, SLOT(show_boost())); m_zones << zone; } diff --git a/soft/thermostat/src/zoneitem.cpp b/soft/thermostat/src/zoneitem.cpp index cbf01da..50b0d54 100644 --- a/soft/thermostat/src/zoneitem.cpp +++ b/soft/thermostat/src/zoneitem.cpp @@ -6,25 +6,22 @@ * */ -#include -#include -#include #include #include #include +#include #include #include "settings.h" #include "zoneitem.h" -ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent) : - QWidget(parent) +ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent, Qt::WindowFlags f) : + QLabel(parent, f) { m_name = zoneName; - m_zoneNameBtn.setText(zoneName); - m_zoneNameBtn.setFlat(true); - m_temperatureBtn.setFlat(true); - m_hygroBtn.setFlat(true); + m_heating_on = false; + + this->setText(zoneName); m_temperature_value = FORCE_OFF; m_hygro_value = FORCE_OFF; @@ -34,31 +31,44 @@ ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent) : m_boost.temperature = 0; m_boost.end_date = QDateTime(); - /* - * Layout for the left part of the window - */ - QVBoxLayout *topLayout = new QVBoxLayout; - topLayout->addWidget(&m_zoneNameBtn); - topLayout->addWidget(&m_temperatureBtn); - topLayout->addWidget(&m_hygroBtn); + QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum, + QSizePolicy::MinimumExpanding, + QSizePolicy::PushButton); - this->setLayout(topLayout); + this->setSizePolicy(*szPolicy); } ZoneItem::~ZoneItem() { } +void ZoneItem::mouseReleaseEvent(QMouseEvent* event) { + (void)event; + emit clicked(); +} + void ZoneItem::refresh(void) { QString text; + /* Zone name */ + text += QString("
") + m_name + QString("

"); + + /* Temperature */ + text += QString("
"); + if (m_heating_on) { + text += QString(""); + } else { + text += QString(""); + } if ((m_temperature_value == FORCE_OFF) || !m_available) text += QString("-"); else text += QString::number(m_temperature_value); - text += QString("°C / "); + text += QString("°C").toHtmlEscaped(); + text += QString(""); + text += QString(" / ").toHtmlEscaped(); if (m_target_temperature == FORCE_OFF) { text += QString("-"); } else if (m_target_temperature == FORCE_ON) { @@ -66,16 +76,19 @@ void ZoneItem::refresh(void) } else { text += QString::number(m_target_temperature); } - text += QString("°C"); - - m_temperatureBtn.setText(text); + text += QString("°C").toHtmlEscaped(); + text += QString("

"); + /* hygrometry */ + text += QString("
"); if ((m_hygro_value == FORCE_OFF) || !m_available) - text = QString("-"); + text += QString("-"); else - text = QString::number(m_hygro_value); - text += QString("%h"); - m_hygroBtn.setText(text); + text += QString::number(m_hygro_value); + text += QString("%h").toHtmlEscaped(); + text += QString("

"); + + this->setText(text); } /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */