diff --git a/soft/thermostat/inc/boost_dlg.h b/soft/thermostat/inc/boost_dlg.h index 71172d5..d3e0c81 100644 --- a/soft/thermostat/inc/boost_dlg.h +++ b/soft/thermostat/inc/boost_dlg.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -21,7 +21,7 @@ struct boost_data QDateTime end_date; }; -class BoostDlg : public QDialog +class BoostDlg : public QWidget { Q_OBJECT @@ -38,6 +38,7 @@ private: private slots: void send_result(void); + void reject(void); signals: void boost_changed(int idx, struct boost_data &data); diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index 978e1a1..bc3e4c0 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -33,6 +33,7 @@ private: QPushButton m_state_btn; QVector m_zones; QTimer *m_timer; + BoostDlg *m_boost; QStackedWidget m_central_widget; void update_state_btn(enum power_states st); double get_target_temperature(int room_idx); @@ -46,6 +47,7 @@ private slots: void change_state(void); void apply_order_to_heaters(void); void show_boost(void); + void show_main(void); void show_menu(void); void boost_slot(int idx, struct boost_data &data); diff --git a/soft/thermostat/src/boost_dlg.cpp b/soft/thermostat/src/boost_dlg.cpp index 72c9002..f797272 100644 --- a/soft/thermostat/src/boost_dlg.cpp +++ b/soft/thermostat/src/boost_dlg.cpp @@ -23,8 +23,8 @@ #define SPIN_ARROW_H 50 #define SPIN_FONT_SZ 20 -BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature, QWidget *parent, Qt::WindowFlags f) : - QDialog(parent, f) +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))); @@ -62,9 +62,8 @@ BoostDlg::BoostDlg(int idx, const QString &zoneName, double temperature, QWidget QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted(void)), this, SLOT(accept(void))); + connect(buttonBox, SIGNAL(accepted(void)), this, SLOT(send_result(void))); connect(buttonBox, SIGNAL(rejected(void)), this, SLOT(reject(void))); - connect(this, SIGNAL(accepted(void)), this, SLOT(send_result(void))); QVBoxLayout *topLayout = new QVBoxLayout; @@ -86,6 +85,13 @@ void BoostDlg::send_result(void) emit boost_changed(m_idx, data); } +void BoostDlg::reject(void) +{ + struct boost_data data; + + emit boost_changed(-1, data); +} + BoostDlg::~BoostDlg() { } diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index afe088c..fb46eb4 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -27,6 +27,8 @@ MainWindow::MainWindow(QWidget *parent) : { ZoneItem *zone; + m_boost = NULL; + Settings *s = Settings::getInstance(); for (int i = 0; i < s->nbZones(); i++) { @@ -109,11 +111,23 @@ MainWindow::~MainWindow() void MainWindow::boost_slot(int idx, struct boost_data &data) { + if (idx == -1) { + /* + * user has hit cancel + */ + goto out; + } + qDebug() << "room " << m_zones.at(idx)->m_name << " new BOOST " << data.temperature << " end: " << data.end_date; m_zones.at(idx)->m_boost = data; apply_order_to_heaters(); +out: + m_central_widget.removeWidget(m_boost); + delete m_boost; + m_boost = NULL; + show_main(); } void MainWindow::show_boost(void) @@ -130,11 +144,11 @@ void MainWindow::show_boost(void) if ((idx < 0) || (idx >= MAX_NB_ZONES)) return; - BoostDlg boost(idx, m_zones.at(idx)->m_name, m_zones.at(idx)->m_target_temperature, this); + m_boost = new BoostDlg(idx, m_zones.at(idx)->m_name, m_zones.at(idx)->m_target_temperature, NULL); - connect(&boost, SIGNAL(boost_changed(int, struct boost_data &)), this, SLOT(boost_slot(int, struct boost_data &))); - boost.showFullScreen(); - boost.exec(); + connect(m_boost, SIGNAL(boost_changed(int, struct boost_data &)), this, SLOT(boost_slot(int, struct boost_data &))); + m_central_widget.addWidget(m_boost); + m_central_widget.setCurrentWidget(m_boost); } void MainWindow::show_menu(void) @@ -146,6 +160,11 @@ void MainWindow::show_menu(void) menu.exec(); } +void MainWindow::show_main(void) +{ + m_central_widget.setCurrentIndex(0); +} + void MainWindow::update_state_btn(enum power_states st) { switch (st) {