From a02ba76f32a7a0f8e647342eb2cf78a639aaf6d3 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Mon, 10 Feb 2020 23:04:34 +0100 Subject: [PATCH] thermostat: improve boost dialog --- soft/thermostat/inc/boost_dlg.h | 1 + soft/thermostat/src/boost_dlg.cpp | 54 ++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/soft/thermostat/inc/boost_dlg.h b/soft/thermostat/inc/boost_dlg.h index d3e0c81..d1028fc 100644 --- a/soft/thermostat/inc/boost_dlg.h +++ b/soft/thermostat/inc/boost_dlg.h @@ -39,6 +39,7 @@ private: private slots: void send_result(void); void reject(void); + void updateDuration(int val); signals: void boost_changed(int idx, struct boost_data &data); diff --git a/soft/thermostat/src/boost_dlg.cpp b/soft/thermostat/src/boost_dlg.cpp index f797272..c486877 100644 --- a/soft/thermostat/src/boost_dlg.cpp +++ b/soft/thermostat/src/boost_dlg.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "settings.h" #include "boost_dlg.h" @@ -27,8 +28,19 @@ 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)); + QLabel *room_name = new QLabel(QString(tr("Force %1 temperature: (actual target: %2 °C)") + .arg(zoneName) + .arg(temperature))); + + QFont font = room_name->font(); + font.setPointSize(12); + font.setBold(true); + room_name->setFont(font); + + QSizePolicy *szQPolicy = new QSizePolicy(QSizePolicy::Minimum, + QSizePolicy::MinimumExpanding, + QSizePolicy::PushButton); + room_name->setSizePolicy(*szQPolicy); temperature = qFloor(temperature * 2) / 2.0; m_idx = idx; @@ -37,6 +49,8 @@ BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature, m_boost_temperature.setSingleStep(0.5); m_boost_temperature.setSuffix(" °C"); + m_boost_temperature.setFont(font); + /* * TODO: setting size in pixels sucks * We should set size in mm or ratio of the window size @@ -56,24 +70,52 @@ BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature, sheet = sheet.replace("QDoubleSpinBox", "QSpinBox"); m_boost_duration.setStyleSheet(sheet); + m_boost_duration.setFont(font); + QHBoxLayout *spinLayout = new QHBoxLayout; spinLayout->addWidget(&m_boost_temperature); spinLayout->addWidget(&m_boost_duration); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + 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); + + ok_btn->setFont(font); + cancel_btn->setFont(font); - connect(buttonBox, SIGNAL(accepted(void)), this, SLOT(send_result(void))); - connect(buttonBox, SIGNAL(rejected(void)), this, SLOT(reject(void))); + ok_btn->setSizePolicy(*szPolicy); + cancel_btn->setSizePolicy(*szPolicy); + + connect(ok_btn, SIGNAL(clicked(void)), this, SLOT(send_result(void))); + connect(cancel_btn, SIGNAL(clicked(void)), this, SLOT(reject(void))); + connect(&m_boost_duration, SIGNAL(valueChanged(int)), this, SLOT(updateDuration(int))); + + QHBoxLayout *btnLayout = new QHBoxLayout; + + btnLayout->addWidget(cancel_btn); + btnLayout->addWidget(ok_btn); QVBoxLayout *topLayout = new QVBoxLayout; topLayout->addWidget(room_name); topLayout->addLayout(spinLayout); - topLayout->addWidget(buttonBox); + topLayout->addLayout(btnLayout); this->setLayout(topLayout); } +void BoostDlg::updateDuration(int val) +{ + QTime duration = QTime::currentTime(); + duration = duration.addSecs(val * 3600); + + m_boost_duration.setSuffix(QString(" H (%1)").arg(duration.toString("HH:mm"))); +} + void BoostDlg::send_result(void) { struct boost_data data;