Browse Source

thermostat: add edit_prog dialog

master
Richard Genoud 4 years ago
parent
commit
333e71d26e
7 changed files with 210 additions and 0 deletions
  1. +2
    -0
      soft/thermostat/inc/edit_dlg.h
  2. +41
    -0
      soft/thermostat/inc/edit_prog_dlg.h
  3. +3
    -0
      soft/thermostat/inc/mainwindow.h
  4. +20
    -0
      soft/thermostat/src/edit_dlg.cpp
  5. +121
    -0
      soft/thermostat/src/edit_prog_dlg.cpp
  6. +21
    -0
      soft/thermostat/src/mainwindow.cpp
  7. +2
    -0
      soft/thermostat/thermostat.pro

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

@ -42,9 +42,11 @@ private slots:
void add(void);
void reject(void);
void delete_prog_clicked(void);
void edit_prog_clicked(void);
signals:
void close_edit_dlg(void);
void show_edit_prog_dlg(struct Program &p);
};
#endif // EDITDLG_H


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

@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2020 Richard Genoud
*
*/
#ifndef EDITPROGDLG_H
#define EDITPROGDLG_H
#include <QWidget>
#include <QObject>
#include <QDoubleSpinBox>
#include "settings.h"
class EditProgDlg : public QWidget
{
Q_OBJECT
public:
EditProgDlg(struct Program &p, QWidget *parent = Q_NULLPTR,
Qt::WindowFlags f = Qt::WindowFlags());
~EditProgDlg();
private:
void set_font(QWidget *widget);
QDoubleSpinBox m_temperature;
private slots:
void save(void);
void reject(void);
signals:
void close_edit_prog_dlg(void);
};
#endif // EDITPROGDLG_H
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

+ 3
- 0
soft/thermostat/inc/mainwindow.h View File

@ -22,6 +22,7 @@
#include "boost_dlg.h"
#include "menu_dlg.h"
#include "edit_dlg.h"
#include "edit_prog_dlg.h"
#include "settings.h"
class MainWindow : public QMainWindow
@ -59,6 +60,8 @@ private slots:
void boost_slot(int idx, struct boost_data &data);
void do_show_holiday_dlg(void);
void do_close_holiday_dlg(void);
void do_show_edit_prog_dlg(struct Program &p);
void do_close_edit_prog_dlg(void);
void set_holiday_mode(QDateTime end_date);
signals:


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

@ -185,6 +185,7 @@ QHBoxLayout *EditDlg::add_prog_layout(const struct Program *p, int idx)
delete_btn->setProperty("idx", idx);
connect(delete_btn, SIGNAL(clicked(void)), this, SLOT(delete_prog_clicked(void)));
connect(edit_btn, SIGNAL(clicked(void)), this, SLOT(edit_prog_clicked(void)));
progLayout->addWidget(edit_btn, 0, Qt::AlignHCenter);
progLayout->addWidget(delete_btn, 0, Qt::AlignHCenter);
@ -314,6 +315,25 @@ void EditDlg::delete_prog_clicked(void)
}
}
void EditDlg::edit_prog_clicked(void)
{
QObject* obj = sender();
QVariant v;
int idx;
v = obj->property("idx");
if (!v.isValid())
return;
idx = v.toInt();
if (idx >= m_progs.count()) {
// TODO ERROR: index mismatch
return;
}
emit show_edit_prog_dlg(m_progs[idx]);
}
EditDlg::~EditDlg()
{
}


+ 121
- 0
soft/thermostat/src/edit_prog_dlg.cpp View File

@ -0,0 +1,121 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2020 Richard Genoud
*
*/
#include <QLoggingCategory>
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLocale>
#include <QLabel>
#include <QtMath>
#include <QDateTime>
#include <QTime>
#include "settings.h"
#include "edit_prog_dlg.h"
#define SPIN_ARROW_W 75
#define SPIN_ARROW_H 50
#define SPIN_FONT_SZ 20
EditProgDlg::EditProgDlg(struct Program &p, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
QString sheet;
QString text;
QLabel *temperature_label = new QLabel(QString(tr("target:")));
set_font(temperature_label);
m_temperature.setDecimals(1);
m_temperature.setValue(p.temperature);
m_temperature.setSingleStep(0.1);
m_temperature.setSuffix(" °C");
set_font(&m_temperature);
/*
* TODO: setting size in pixels sucks
* We should set size in mm or ratio of the window size
*/
sheet = QString("QDoubleSpinBox { height: %1px; font-size: %4px }"
"QDoubleSpinBox::up-button { width: %2px; height: %3px }"
"QDoubleSpinBox::down-button { width: %2px; height: %3px }")
.arg(2*SPIN_ARROW_H)
.arg(SPIN_ARROW_W)
.arg(SPIN_ARROW_H)
.arg(SPIN_FONT_SZ);
m_temperature.setStyleSheet(sheet);
QHBoxLayout *temperatureLayout = new QHBoxLayout;
temperatureLayout->addWidget(temperature_label);
temperatureLayout->addWidget(&m_temperature);
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);
set_font(ok_btn);
set_font(cancel_btn);
ok_btn->setSizePolicy(*szPolicy);
cancel_btn->setSizePolicy(*szPolicy);
connect(ok_btn, SIGNAL(clicked(void)), this, SLOT(save(void)));
connect(cancel_btn, SIGNAL(clicked(void)), this, SLOT(reject(void)));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addWidget(cancel_btn);
btnLayout->addWidget(ok_btn);
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addLayout(temperatureLayout);
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
}
void EditProgDlg::set_font(QWidget *widget)
{
QFont font = widget->font();
font.setPointSize(12);
font.setBold(true);
widget->setFont(font);
QSizePolicy *szQPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
widget->setSizePolicy(*szQPolicy);
}
void EditProgDlg::save(void)
{
emit close_edit_prog_dlg();
}
void EditProgDlg::reject(void)
{
emit close_edit_prog_dlg();
}
EditProgDlg::~EditProgDlg()
{
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

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

@ -178,6 +178,7 @@ void MainWindow::do_show_edit_dlg(void)
m_edit_dlg = new EditDlg(idx);
connect(m_edit_dlg, SIGNAL(close_edit_dlg(void)), this, SLOT(show_main(void)));
connect(m_edit_dlg, SIGNAL(show_edit_prog_dlg(struct Program&)), this, SLOT(do_show_edit_prog_dlg(struct Program &)));
m_central_widget.addWidget(m_edit_dlg);
m_central_widget.setCurrentWidget(m_edit_dlg);
}
@ -211,6 +212,26 @@ void MainWindow::set_holiday_mode(QDateTime end_date)
apply_order_to_heaters();
}
void MainWindow::do_show_edit_prog_dlg(struct Program &p)
{
EditProgDlg *edit_prog_dlg = new EditProgDlg(p, this);
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)));
}
void MainWindow::do_close_edit_prog_dlg(void)
{
QWidget *current = m_central_widget.currentWidget();
if (current == NULL)
return;
m_central_widget.removeWidget(current);
delete current;
}
void MainWindow::show_menu(void)
{
m_menu = new MenuDlg(NULL);


+ 2
- 0
soft/thermostat/thermostat.pro View File

@ -29,6 +29,7 @@ SOURCES += src/main.cpp \
src/menu_dlg.cpp \
src/holiday_dlg.cpp \
src/edit_dlg.cpp \
src/edit_prog_dlg.cpp \
HEADERS += inc/mainwindow.h \
@ -39,6 +40,7 @@ HEADERS += inc/mainwindow.h \
inc/menu_dlg.h \
inc/holiday_dlg.h \
inc/edit_dlg.h \
inc/edit_prog_dlg.h \
RESOURCES += thermostat.qrc


Loading…
Cancel
Save