Browse Source

thermostat: make zoneitem clickable and colorized

master
Richard Genoud 4 years ago
parent
commit
0a2d1a5795
3 changed files with 47 additions and 39 deletions
  1. +7
    -7
      soft/thermostat/inc/zoneitem.h
  2. +2
    -7
      soft/thermostat/src/mainwindow.cpp
  3. +38
    -25
      soft/thermostat/src/zoneitem.cpp

+ 7
- 7
soft/thermostat/inc/zoneitem.h View File

@ -9,19 +9,18 @@
#ifndef ZONEITEM_H
#define ZONEITEM_H
#include <QWidget>
#include <QObject>
#include <QLabel>
#include <QPushButton>
#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


+ 2
- 7
soft/thermostat/src/mainwindow.cpp View File

@ -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;
}


+ 38
- 25
soft/thermostat/src/zoneitem.cpp View File

@ -6,25 +6,22 @@
*
*/
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QLocale>
#include <QLabel>
#include <QDateTime>
#include <QSizePolicy>
#include <QTime>
#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("<center><b>") + m_name + QString("</b></center><br/>");
/* Temperature */
text += QString("<center><b>");
if (m_heating_on) {
text += QString("<font color='red'>");
} else {
text += QString("<font color='black'>");
}
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("</font>");
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("</b></center><br/>");
/* hygrometry */
text += QString("<center><b>");
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("</b></center><br/>");
this->setText(text);
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

Loading…
Cancel
Save