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

// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2020 Richard Genoud
*
*/
#include <QDialogButtonBox>
#include <QSpinBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLocale>
#include <QLabel>
#include <QtMath>
#include <QDateTime>
#include "settings.h"
#include "boost_dlg.h"
#define SPIN_ARROW_W 75
#define SPIN_ARROW_H 50
#define SPIN_FONT_SZ 20
BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature,
QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
QString sheet;
QLabel *room_name = new QLabel(QString(tr("Force %1 temperature:").arg(zoneName)));
room_name->setStyleSheet(QString("font-size: %1px;").arg(SPIN_FONT_SZ));
temperature = qFloor(temperature * 2) / 2.0;
m_idx = idx;
m_boost_temperature.setDecimals(1);
m_boost_temperature.setValue(temperature);
m_boost_temperature.setSingleStep(0.5);
m_boost_temperature.setSuffix(" °C");
/*
* TODO: setting size in pixels sucks
* We should set size in mm or ratio of the window size
*/
sheet = QString("QDoubleSpinBox { height: %1px; font-size: %4px }"
"QDoubleSpinBox::up-button { width: %2px; height: %3px }"
"QDoubleSpinBox::down-button { width: %2px; height: %3px }")
.arg(2*SPIN_ARROW_H)
.arg(SPIN_ARROW_W)
.arg(SPIN_ARROW_H)
.arg(SPIN_FONT_SZ);
m_boost_temperature.setStyleSheet(sheet);
m_boost_duration.setRange(0, 99);
m_boost_duration.setValue(1);
m_boost_duration.setSuffix(" H");
sheet = sheet.replace("QDoubleSpinBox", "QSpinBox");
m_boost_duration.setStyleSheet(sheet);
QHBoxLayout *spinLayout = new QHBoxLayout;
spinLayout->addWidget(&m_boost_temperature);
spinLayout->addWidget(&m_boost_duration);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted(void)), this, SLOT(send_result(void)));
connect(buttonBox, SIGNAL(rejected(void)), this, SLOT(reject(void)));
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(room_name);
topLayout->addLayout(spinLayout);
topLayout->addWidget(buttonBox);
this->setLayout(topLayout);
}
void BoostDlg::send_result(void)
{
struct boost_data data;
QDateTime now = QDateTime::currentDateTime();
data.temperature = m_boost_temperature.value();
data.end_date = now.addSecs(m_boost_duration.value() * 3600);
emit boost_changed(m_idx, data);
}
void BoostDlg::reject(void)
{
struct boost_data data;
emit boost_changed(-1, data);
}
BoostDlg::~BoostDlg()
{
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */