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.
 
 
 
 
 
 

149 lines
3.7 KiB

// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2020 Richard Genoud
*
*/
#include <QLoggingCategory>
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLocale>
#include <QLabel>
#include <QtMath>
#include <QDateTime>
#include <QTime>
#include "settings.h"
#include "edit_prog_dlg.h"
#define SPIN_ARROW_W 75
#define SPIN_ARROW_H 50
#define SPIN_FONT_SZ 20
#define NB_DoW 7
EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
QString sheet;
QString text;
// ************* Temperature ******************
QLabel *temperature_label = new QLabel(QString(tr("target:")));
set_font(temperature_label);
p.temperature = qFloor(p.temperature * 2) / 2.0;
m_temperature.setDecimals(1);
m_temperature.setValue(p.temperature);
m_temperature.setSingleStep(0.5);
m_temperature.setSuffix(" °C");
set_font(&m_temperature);
/*
* 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_temperature.setStyleSheet(sheet);
QHBoxLayout *temperatureLayout = new QHBoxLayout;
temperatureLayout->addWidget(temperature_label);
temperatureLayout->addWidget(&m_temperature);
QPushButton *ok_btn = new QPushButton(tr("Ok"), this);
QPushButton *cancel_btn = new QPushButton(tr("Cancel"), this);
QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
// ************* Day of week buttons ******************
QHBoxLayout *dowLayout = new QHBoxLayout;
QPushButton *dow_btn[NB_DoW];
dow_btn[0] = new QPushButton(tr("Mo"), this);
dow_btn[1] = new QPushButton(tr("Tu"), this);
dow_btn[2] = new QPushButton(tr("We"), this);
dow_btn[3] = new QPushButton(tr("Th"), this);
dow_btn[4] = new QPushButton(tr("Fr"), this);
dow_btn[5] = new QPushButton(tr("Sa"), this);
dow_btn[6] = new QPushButton(tr("Su"), this);
for (int i = 0; i < NB_DoW; i++) {
dow_btn[i]->setProperty("idx", i);
set_font(dow_btn[i]);
dow_btn[i]->setSizePolicy(*szPolicy);
dow_btn[i]->setChecked(true);
if (p.DoW & (1 << i))
dow_btn[i]->setDown(true);
dowLayout->addWidget(dow_btn[i], 0, Qt::AlignHCenter);
}
// ************* OK / CANCEL Buttons ******************
set_font(ok_btn);
set_font(cancel_btn);
ok_btn->setSizePolicy(*szPolicy);
cancel_btn->setSizePolicy(*szPolicy);
connect(ok_btn, SIGNAL(clicked(void)), this, SLOT(save(void)));
connect(cancel_btn, SIGNAL(clicked(void)), this, SLOT(reject(void)));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addWidget(cancel_btn);
btnLayout->addWidget(ok_btn);
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addLayout(temperatureLayout);
topLayout->addLayout(dowLayout);
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
}
void EditProgDlg::set_font(QWidget *widget)
{
QFont font = widget->font();
font.setPointSize(12);
font.setBold(true);
widget->setFont(font);
QSizePolicy *szQPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
widget->setSizePolicy(*szQPolicy);
}
void EditProgDlg::save(void)
{
emit close_edit_prog_dlg();
}
void EditProgDlg::reject(void)
{
emit close_edit_prog_dlg();
}
EditProgDlg::~EditProgDlg()
{
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */