Browse Source

thermostat: edit_prog: save new prog (WIP)

master
Richard Genoud 4 years ago
parent
commit
cfb54ce255
5 changed files with 46 additions and 22 deletions
  1. +1
    -0
      soft/thermostat/inc/edit_dlg.h
  2. +8
    -0
      soft/thermostat/inc/edit_prog_dlg.h
  3. +4
    -0
      soft/thermostat/src/edit_dlg.cpp
  4. +32
    -22
      soft/thermostat/src/edit_prog_dlg.cpp
  5. +1
    -0
      soft/thermostat/src/mainwindow.cpp

+ 1
- 0
soft/thermostat/inc/edit_dlg.h View File

@ -43,6 +43,7 @@ private slots:
void reject(void);
void delete_prog_clicked(void);
void edit_prog_clicked(void);
void refresh_progs(void);
signals:
void close_edit_dlg(void);


+ 8
- 0
soft/thermostat/inc/edit_prog_dlg.h View File

@ -11,10 +11,14 @@
#include <QWidget>
#include <QObject>
#include <QPushButton>
#include <QTimeEdit>
#include <QDoubleSpinBox>
#include "settings.h"
#define NB_DoW 7
class EditProgDlg : public QWidget
{
Q_OBJECT
@ -27,6 +31,10 @@ public:
private:
void set_font(QWidget *widget);
QDoubleSpinBox m_temperature;
QPushButton *m_dow_btn[NB_DoW];
QTimeEdit *m_start_time_widget;
QTimeEdit *m_end_time_widget;
struct Program *m_prog;
private slots:
void save(void);


+ 4
- 0
soft/thermostat/src/edit_dlg.cpp View File

@ -206,6 +206,10 @@ void EditDlg::set_font(QWidget *widget)
widget->setSizePolicy(*szQPolicy);
}
void EditDlg::refresh_progs(void)
{
}
void EditDlg::save(void)
{
Settings *s = Settings::getInstance();


+ 32
- 22
soft/thermostat/src/edit_prog_dlg.cpp View File

@ -24,13 +24,13 @@
#define SPIN_ARROW_H 25
#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;
m_prog = &p;
// ************* Temperature ******************
QLabel *temperature_label = new QLabel(QString(tr("target:")));
@ -72,22 +72,21 @@ EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f)
// ************* 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);
m_dow_btn[0] = new QPushButton(tr("Mo"), this);
m_dow_btn[1] = new QPushButton(tr("Tu"), this);
m_dow_btn[2] = new QPushButton(tr("We"), this);
m_dow_btn[3] = new QPushButton(tr("Th"), this);
m_dow_btn[4] = new QPushButton(tr("Fr"), this);
m_dow_btn[5] = new QPushButton(tr("Sa"), this);
m_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);
m_dow_btn[i]->setProperty("idx", i);
set_font(m_dow_btn[i]);
m_dow_btn[i]->setSizePolicy(*szPolicy);
m_dow_btn[i]->setChecked(true);
if (p.DoW & (1 << i))
dow_btn[i]->setDown(true);
dowLayout->addWidget(dow_btn[i], 0, Qt::AlignHCenter);
m_dow_btn[i]->setDown(true);
dowLayout->addWidget(m_dow_btn[i], 0, Qt::AlignHCenter);
}
// ************* start time ******************
@ -95,7 +94,7 @@ EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f)
QLabel *start_time_label = new QLabel(QString(tr("Start time:")));
set_font(start_time_label);
QTimeEdit *start_time_widget = new QTimeEdit(p.start_time);
m_start_time_widget = new QTimeEdit(p.start_time);
sheet = QString("QTimeEdit { height: %1px; font-size: %4px }"
"QTimeEdit::up-button { width: %2px; height: %3px }"
@ -104,16 +103,16 @@ EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f)
.arg(SPIN_ARROW_W)
.arg(SPIN_ARROW_H)
.arg(SPIN_FONT_SZ);
start_time_widget->setStyleSheet(sheet);
m_start_time_widget->setStyleSheet(sheet);
startTimeLayout->addWidget(start_time_label);
startTimeLayout->addWidget(start_time_widget);
startTimeLayout->addWidget(m_start_time_widget);
// ************* end time ******************
QHBoxLayout *endTimeLayout = new QHBoxLayout;
QLabel *end_time_label = new QLabel(QString(tr("End time:")));
set_font(end_time_label);
QTimeEdit *end_time_widget = new QTimeEdit(p.end_time);
m_end_time_widget = new QTimeEdit(p.end_time);
sheet = QString("QTimeEdit { height: %1px; font-size: %4px }"
"QTimeEdit::up-button { width: %2px; height: %3px }"
@ -122,9 +121,9 @@ EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f)
.arg(SPIN_ARROW_W)
.arg(SPIN_ARROW_H)
.arg(SPIN_FONT_SZ);
end_time_widget->setStyleSheet(sheet);
m_end_time_widget->setStyleSheet(sheet);
endTimeLayout->addWidget(end_time_label);
endTimeLayout->addWidget(end_time_widget);
endTimeLayout->addWidget(m_end_time_widget);
// ************* OK / CANCEL Buttons ******************
set_font(ok_btn);
@ -171,6 +170,17 @@ void EditProgDlg::set_font(QWidget *widget)
void EditProgDlg::save(void)
{
// update the prog
m_prog->temperature = m_temperature.value();
m_prog->DoW = 0;
for (int i = 0; i < NB_DoW; i++) {
if (m_dow_btn[i]->isChecked()) {
m_prog->DoW |= 1 << i;
}
}
m_prog->start_time = m_start_time_widget->time();
m_prog->end_time = m_end_time_widget->time();
emit close_edit_prog_dlg();
}


+ 1
- 0
soft/thermostat/src/mainwindow.cpp View File

@ -219,6 +219,7 @@ void MainWindow::do_show_edit_prog_dlg(struct Program &p)
m_central_widget.addWidget(edit_prog_dlg);
m_central_widget.setCurrentWidget(edit_prog_dlg);
connect(edit_prog_dlg, SIGNAL(close_edit_prog_dlg(void)), this, SLOT(do_close_edit_prog_dlg(void)));
connect(edit_prog_dlg, SIGNAL(close_edit_prog_dlg(void)), m_edit_dlg, SLOT(refresh_progs(void)));
}
void MainWindow::do_close_edit_prog_dlg(void)


Loading…
Cancel
Save