Thermostat pour piloter jusqu'à 4 radiateurs avec fil pilote
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.7 KiB

  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. /*
  3. * Qt mutizone MQTT thermostat
  4. *
  5. * Copyright (C) 2019 Richard Genoud
  6. *
  7. */
  8. #include <QLocale>
  9. #include <QLabel>
  10. #include <QDateTime>
  11. #include <QSizePolicy>
  12. #include <QTime>
  13. #include "settings.h"
  14. #include "zoneitem.h"
  15. ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent, Qt::WindowFlags f) :
  16. QLabel(parent, f)
  17. {
  18. m_name = zoneName;
  19. m_heating_on = false;
  20. QFont font = this->font();
  21. font.setPointSize(12);
  22. this->setFont(font);
  23. this->setText(zoneName);
  24. m_temperature_value = FORCE_OFF;
  25. m_hygro_value = FORCE_OFF;
  26. m_target_temperature = FORCE_OFF;
  27. m_available = false;
  28. m_boost.temperature = 0;
  29. m_boost.end_date = QDateTime();
  30. QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum,
  31. QSizePolicy::MinimumExpanding,
  32. QSizePolicy::PushButton);
  33. this->setSizePolicy(*szPolicy);
  34. }
  35. ZoneItem::~ZoneItem()
  36. {
  37. }
  38. void ZoneItem::mousePressEvent(QMouseEvent* event)
  39. {
  40. Q_UNUSED(event);
  41. m_click_chrono.start();
  42. }
  43. void ZoneItem::mouseReleaseEvent(QMouseEvent* event)
  44. {
  45. Q_UNUSED(event);
  46. if (m_click_chrono.elapsed() > 1000) {
  47. emit long_clicked();
  48. } else {
  49. emit clicked();
  50. }
  51. }
  52. void ZoneItem::refresh(void)
  53. {
  54. QString text;
  55. Settings *s = Settings::getInstance();
  56. switch (s->getPowerState()) {
  57. case OFF:
  58. m_target_temperature = FORCE_OFF;
  59. break;
  60. case ON:
  61. m_target_temperature = FORCE_ON;
  62. break;
  63. case AUTO:
  64. case MAX_POWER_STATES:
  65. break;
  66. }
  67. if (s->getEndHoliday() > QDateTime::currentDateTime()) {
  68. m_target_temperature = FORCE_OFF;
  69. }
  70. /* Zone name */
  71. text += QString("<center><b>") + m_name + QString("</b></center>");
  72. /* Temperature */
  73. text += QString("<center><b>");
  74. if (((s->getPowerState() == AUTO) && m_heating_on) || (s->getPowerState() == FORCE_ON)) {
  75. text += QString("<font color='red'>");
  76. } else {
  77. text += QString("<font color='black'>");
  78. }
  79. if ((m_temperature_value == FORCE_OFF) || !m_available)
  80. text += QString("-");
  81. else
  82. text += QString::number(m_temperature_value);
  83. text += QString("°C").toHtmlEscaped();
  84. text += QString("</font>");
  85. text += QString(" / ").toHtmlEscaped();
  86. if (m_target_temperature == FORCE_OFF) {
  87. text += QString("-");
  88. } else if (m_target_temperature == FORCE_ON) {
  89. text += QString("+");
  90. } else {
  91. text += QString::number(m_target_temperature);
  92. text += QString("°C").toHtmlEscaped();
  93. }
  94. text += QString("</b></center>");
  95. /* hygrometry */
  96. text += QString("<center><b>");
  97. if ((m_hygro_value == FORCE_OFF) || !m_available)
  98. text += QString("-");
  99. else
  100. text += QString::number(m_hygro_value);
  101. text += QString("%h").toHtmlEscaped();
  102. text += QString("</b></center><br/>");
  103. this->setText(text);
  104. }
  105. /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */