diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index bc3e4c0..23455b7 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -18,6 +18,7 @@ #include "mqttclient.h" #include "zoneitem.h" #include "boost_dlg.h" +#include "menu_dlg.h" #include "settings.h" class MainWindow : public QMainWindow @@ -34,6 +35,7 @@ private: QVector m_zones; QTimer *m_timer; BoostDlg *m_boost; + MenuDlg *m_menu; QStackedWidget m_central_widget; void update_state_btn(enum power_states st); double get_target_temperature(int room_idx); diff --git a/soft/thermostat/inc/menu_dlg.h b/soft/thermostat/inc/menu_dlg.h index 82e4324..5c7ef05 100644 --- a/soft/thermostat/inc/menu_dlg.h +++ b/soft/thermostat/inc/menu_dlg.h @@ -9,11 +9,11 @@ #ifndef MENUDLG_H #define MENUDLG_H -#include +#include #include #include -class MenuDlg : public QDialog +class MenuDlg : public QWidget { Q_OBJECT @@ -24,15 +24,15 @@ public: signals: void exit_requested(void); - -private slots: + void closed(void); void show_holiday_dlg(void); void show_save_cfg_dlg(void); void show_load_cfg_dlg(void); + +private slots: void show_confirm_exit_dlg(void); }; #endif // MENUDLG_H /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ - diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index fb46eb4..581c0de 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) : ZoneItem *zone; m_boost = NULL; + m_menu = NULL; Settings *s = Settings::getInstance(); @@ -124,9 +125,6 @@ void MainWindow::boost_slot(int idx, struct boost_data &data) apply_order_to_heaters(); out: - m_central_widget.removeWidget(m_boost); - delete m_boost; - m_boost = NULL; show_main(); } @@ -153,15 +151,43 @@ void MainWindow::show_boost(void) void MainWindow::show_menu(void) { - MenuDlg menu(this); + m_menu = new MenuDlg(NULL); + + connect(m_menu, SIGNAL(closed(void)), this, SLOT(show_main(void))); - /* TODO: fix dialog modality, use QStackedWidget instead */ - menu.showFullScreen(); - menu.exec(); + m_central_widget.addWidget(m_menu); + m_central_widget.setCurrentWidget(m_menu); } void MainWindow::show_main(void) { + QWidget *current = m_central_widget.currentWidget(); + + if (current == NULL) + goto out; + + if (m_central_widget.count() < 1) { + /* WTF ?! */ + return; + } + + if (m_central_widget.count() == 1) { + /* nothing to do */ + return; + } + + if (current == m_boost) { + m_boost = NULL; + } + + if (current == m_menu) { + m_menu = NULL; + } + + m_central_widget.removeWidget(current); + delete current; + +out: m_central_widget.setCurrentIndex(0); } diff --git a/soft/thermostat/src/menu_dlg.cpp b/soft/thermostat/src/menu_dlg.cpp index 078d2ef..67f2ca2 100644 --- a/soft/thermostat/src/menu_dlg.cpp +++ b/soft/thermostat/src/menu_dlg.cpp @@ -16,7 +16,7 @@ #include "menu_dlg.h" MenuDlg::MenuDlg(QWidget *parent, Qt::WindowFlags f) : - QDialog(parent, f) + QWidget(parent, f) { QGridLayout *mainLayout = new QGridLayout; @@ -32,27 +32,15 @@ MenuDlg::MenuDlg(QWidget *parent, Qt::WindowFlags f) : mainLayout->addWidget(exit_btn, 1, 0); mainLayout->addWidget(back_btn, 1, 2); - connect(holiday_btn, SIGNAL(clicked(void)), this, SLOT(show_holiday_dlg(void))); - connect(save_cfg_btn, SIGNAL(clicked(void)), this, SLOT(show_save_cfg_dlg(void))); - connect(load_cfg_btn, SIGNAL(clicked(void)), this, SLOT(show_load_cfg_dlg(void))); - connect(back_btn, SIGNAL(clicked(void)), this, SLOT(accept(void))); + connect(holiday_btn, SIGNAL(clicked(void)), this, SIGNAL(show_holiday_dlg(void))); + connect(save_cfg_btn, SIGNAL(clicked(void)), this, SIGNAL(show_save_cfg_dlg(void))); + connect(load_cfg_btn, SIGNAL(clicked(void)), this, SIGNAL(show_load_cfg_dlg(void))); + connect(back_btn, SIGNAL(clicked(void)), this, SIGNAL(closed(void))); connect(exit_btn, SIGNAL(clicked(void)), this, SLOT(show_confirm_exit_dlg(void))); this->setLayout(mainLayout); } -void MenuDlg::show_holiday_dlg(void) -{ -} - -void MenuDlg::show_save_cfg_dlg(void) -{ -} - -void MenuDlg::show_load_cfg_dlg(void) -{ -} - void MenuDlg::show_confirm_exit_dlg(void) { QMessageBox::StandardButton retval; @@ -67,5 +55,3 @@ MenuDlg::~MenuDlg() } /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ - -