diff --git a/soft/thermostat/inc/edit_dlg.h b/soft/thermostat/inc/edit_dlg.h index b0a142b..343a001 100644 --- a/soft/thermostat/inc/edit_dlg.h +++ b/soft/thermostat/inc/edit_dlg.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "settings.h" @@ -33,6 +34,7 @@ private: void set_font(QWidget *widget); QHBoxLayout *add_prog_layout(int idx); + QPushButton *m_add_btn; QDoubleSpinBox m_default_temperature; QVBoxLayout *m_progsLayout; QVector m_progs; diff --git a/soft/thermostat/src/edit_dlg.cpp b/soft/thermostat/src/edit_dlg.cpp index bf9330e..3a1f3a0 100644 --- a/soft/thermostat/src/edit_dlg.cpp +++ b/soft/thermostat/src/edit_dlg.cpp @@ -26,6 +26,9 @@ #define SPIN_ARROW_H 50 #define SPIN_FONT_SZ 20 +// otherwise, the Rpi screen is too small +#define MAX_PROGRAMS 4 + EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { Settings *s = Settings::getInstance(); @@ -63,8 +66,8 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, upperLayout->addWidget(room_name); upperLayout->addWidget(&m_default_temperature); + m_add_btn = new QPushButton(tr("Add"), this); QPushButton *ok_btn = new QPushButton(tr("Ok"), this); - QPushButton *add_btn = new QPushButton(tr("Add"), this); QPushButton *cancel_btn = new QPushButton(tr("Cancel"), this); @@ -73,21 +76,23 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, QSizePolicy::PushButton); set_font(ok_btn); - set_font(add_btn); + set_font(m_add_btn); set_font(cancel_btn); ok_btn->setSizePolicy(*szPolicy); - add_btn->setSizePolicy(*szPolicy); + m_add_btn->setSizePolicy(*szPolicy); cancel_btn->setSizePolicy(*szPolicy); + m_add_btn->setEnabled(m_progs.count() < MAX_PROGRAMS); + connect(ok_btn, SIGNAL(clicked(void)), this, SLOT(save(void))); - connect(add_btn, SIGNAL(clicked(void)), this, SLOT(add(void))); + connect(m_add_btn, SIGNAL(clicked(void)), this, SLOT(add(void))); connect(cancel_btn, SIGNAL(clicked(void)), this, SLOT(reject(void))); QHBoxLayout *btnLayout = new QHBoxLayout; btnLayout->addWidget(cancel_btn); - btnLayout->addWidget(add_btn); + btnLayout->addWidget(m_add_btn); btnLayout->addWidget(ok_btn); QVBoxLayout *topLayout = new QVBoxLayout; @@ -284,6 +289,8 @@ void EditDlg::add(void) layout = add_prog_layout(idx); m_progsLayout->addLayout(layout); + + m_add_btn->setEnabled(m_progs.count() < MAX_PROGRAMS); } void EditDlg::delete_prog_clicked(void) @@ -357,6 +364,8 @@ void EditDlg::delete_prog_clicked(void) } } } + + m_add_btn->setEnabled(m_progs.count() < MAX_PROGRAMS); } void EditDlg::edit_prog_clicked(void)