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.

100 lines
2.5 KiB

  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. /*
  3. * Qt mutizone MQTT thermostat
  4. *
  5. * Copyright (C) 2020 Richard Genoud
  6. *
  7. */
  8. #include <QDialogButtonBox>
  9. #include <QSpinBox>
  10. #include <QPushButton>
  11. #include <QVBoxLayout>
  12. #include <QHBoxLayout>
  13. #include <QLocale>
  14. #include <QLabel>
  15. #include <QtMath>
  16. #include <QDateTime>
  17. #include "settings.h"
  18. #include "boost_dlg.h"
  19. #define SPIN_ARROW_W 75
  20. #define SPIN_ARROW_H 50
  21. #define SPIN_FONT_SZ 20
  22. BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature,
  23. QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
  24. {
  25. QString sheet;
  26. QLabel *room_name = new QLabel(QString(tr("Force %1 temperature:").arg(zoneName)));
  27. room_name->setStyleSheet(QString("font-size: %1px;").arg(SPIN_FONT_SZ));
  28. temperature = qFloor(temperature * 2) / 2.0;
  29. m_idx = idx;
  30. m_boost_temperature.setDecimals(1);
  31. m_boost_temperature.setValue(temperature);
  32. m_boost_temperature.setSingleStep(0.5);
  33. m_boost_temperature.setSuffix(" °C");
  34. /*
  35. * TODO: setting size in pixels sucks
  36. * We should set size in mm or ratio of the window size
  37. */
  38. sheet = QString("QDoubleSpinBox { height: %1px; font-size: %4px }"
  39. "QDoubleSpinBox::up-button { width: %2px; height: %3px }"
  40. "QDoubleSpinBox::down-button { width: %2px; height: %3px }")
  41. .arg(2*SPIN_ARROW_H)
  42. .arg(SPIN_ARROW_W)
  43. .arg(SPIN_ARROW_H)
  44. .arg(SPIN_FONT_SZ);
  45. m_boost_temperature.setStyleSheet(sheet);
  46. m_boost_duration.setRange(0, 99);
  47. m_boost_duration.setValue(1);
  48. m_boost_duration.setSuffix(" H");
  49. sheet = sheet.replace("QDoubleSpinBox", "QSpinBox");
  50. m_boost_duration.setStyleSheet(sheet);
  51. QHBoxLayout *spinLayout = new QHBoxLayout;
  52. spinLayout->addWidget(&m_boost_temperature);
  53. spinLayout->addWidget(&m_boost_duration);
  54. QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
  55. connect(buttonBox, SIGNAL(accepted(void)), this, SLOT(send_result(void)));
  56. connect(buttonBox, SIGNAL(rejected(void)), this, SLOT(reject(void)));
  57. QVBoxLayout *topLayout = new QVBoxLayout;
  58. topLayout->addWidget(room_name);
  59. topLayout->addLayout(spinLayout);
  60. topLayout->addWidget(buttonBox);
  61. this->setLayout(topLayout);
  62. }
  63. void BoostDlg::send_result(void)
  64. {
  65. struct boost_data data;
  66. QDateTime now = QDateTime::currentDateTime();
  67. data.temperature = m_boost_temperature.value();
  68. data.end_date = now.addSecs(m_boost_duration.value() * 3600);
  69. emit boost_changed(m_idx, data);
  70. }
  71. void BoostDlg::reject(void)
  72. {
  73. struct boost_data data;
  74. emit boost_changed(-1, data);
  75. }
  76. BoostDlg::~BoostDlg()
  77. {
  78. }
  79. /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */