Browse Source

thermostat: add configuration dialog (WIP)

master
Richard Genoud 5 years ago
parent
commit
93159e39d4
5 changed files with 189 additions and 0 deletions
  1. +41
    -0
      soft/thermostat/inc/edit_dlg.h
  2. +3
    -0
      soft/thermostat/inc/mainwindow.h
  3. +116
    -0
      soft/thermostat/src/edit_dlg.cpp
  4. +27
    -0
      soft/thermostat/src/mainwindow.cpp
  5. +2
    -0
      soft/thermostat/thermostat.pro

+ 41
- 0
soft/thermostat/inc/edit_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 EDITDLG_H
#define EDITDLG_H
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QWidget>
#include <QObject>
#include <QDateTime>
class EditDlg : public QWidget
{
Q_OBJECT
public:
EditDlg(int idx, QWidget *parent = Q_NULLPTR,
Qt::WindowFlags f = Qt::WindowFlags());
~EditDlg();
int m_idx; // room index
private:
QDoubleSpinBox m_default_temperature;
private slots:
void save(void);
void reject(void);
signals:
void close_edit_dlg(void);
};
#endif // EDITDLG_H
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

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

@ -21,6 +21,7 @@
#include "zoneitem.h"
#include "boost_dlg.h"
#include "menu_dlg.h"
#include "edit_dlg.h"
#include "settings.h"
class MainWindow : public QMainWindow
@ -37,6 +38,7 @@ private:
QVector<ZoneItem *> m_zones;
QTimer *m_timer;
BoostDlg *m_boost;
EditDlg *m_edit_dlg;
MenuDlg *m_menu;
QDate m_end_holiday;
QStackedWidget m_central_widget;
@ -52,6 +54,7 @@ private slots:
void change_state(void);
void apply_order_to_heaters(void);
void show_boost(void);
void do_show_edit_dlg(void);
void show_main(void);
void show_menu(void);
void boost_slot(int idx, struct boost_data &data);


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

@ -0,0 +1,116 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2020 Richard Genoud
*
*/
#include <QDialogButtonBox>
#include <QSpinBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLocale>
#include <QLabel>
#include <QtMath>
#include <QDateTime>
#include <QTime>
#include "settings.h"
#include "edit_dlg.h"
#define SPIN_ARROW_W 75
#define SPIN_ARROW_H 50
#define SPIN_FONT_SZ 20
EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
Settings *s = Settings::getInstance();
const struct Room *r = NULL;
QString sheet;
r = &(s->m_rooms.at(idx));
QLabel *room_name = new QLabel(QString(tr("%1 default target:").arg(r->name)));
QFont font = room_name->font();
font.setPointSize(12);
font.setBold(true);
room_name->setFont(font);
QSizePolicy *szQPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
room_name->setSizePolicy(*szQPolicy);
m_idx = idx;
m_default_temperature.setDecimals(1);
m_default_temperature.setValue(r->default_temperature);
m_default_temperature.setSingleStep(0.1);
m_default_temperature.setSuffix(" °C");
m_default_temperature.setFont(font);
/*
* 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_default_temperature.setStyleSheet(sheet);
QHBoxLayout *upperLayout = new QHBoxLayout;
upperLayout->addWidget(room_name);
upperLayout->addWidget(&m_default_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);
ok_btn->setFont(font);
cancel_btn->setFont(font);
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(upperLayout);
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
}
void EditDlg::save(void)
{
emit close_edit_dlg();
}
void EditDlg::reject(void)
{
emit close_edit_dlg();
}
EditDlg::~EditDlg()
{
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

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

@ -18,6 +18,7 @@
#include "boost_dlg.h"
#include "menu_dlg.h"
#include "edit_dlg.h"
#include "holiday_dlg.h"
#include "mqttclient.h"
#include "zoneitem.h"
@ -41,6 +42,7 @@ MainWindow::MainWindow(QWidget *parent) :
zone->setProperty("idx", i);
zone->m_target_temperature = get_target_temperature(i);
connect(zone, SIGNAL(clicked()), this, SLOT(show_boost()));
connect(zone, SIGNAL(long_clicked()), this, SLOT(do_show_edit_dlg()));
m_zones << zone;
}
@ -161,6 +163,27 @@ void MainWindow::show_boost(void)
m_central_widget.setCurrentWidget(m_boost);
}
void MainWindow::do_show_edit_dlg(void)
{
QObject* obj = sender();
QVariant v;
v = obj->property("idx");
if (!v.isValid())
return;
int idx = v.toInt();
if ((idx < 0) || (idx >= MAX_NB_ZONES))
return;
m_edit_dlg = new EditDlg(idx);
connect(m_edit_dlg, SIGNAL(close_edit_dlg(void)), this, SLOT(show_main(void)));
m_central_widget.addWidget(m_edit_dlg);
m_central_widget.setCurrentWidget(m_edit_dlg);
}
void MainWindow::do_show_holiday_dlg(void)
{
HolidayDlg *holiday_dlg = new HolidayDlg(this);
@ -224,6 +247,10 @@ void MainWindow::show_main(void)
m_menu = NULL;
}
if (current == m_edit_dlg) {
m_edit_dlg = NULL;
}
m_central_widget.removeWidget(current);
delete current;


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

@ -28,6 +28,7 @@ SOURCES += src/main.cpp \
src/boost_dlg.cpp \
src/menu_dlg.cpp \
src/holiday_dlg.cpp \
src/edit_dlg.cpp \
HEADERS += inc/mainwindow.h \
@ -37,6 +38,7 @@ HEADERS += inc/mainwindow.h \
inc/boost_dlg.h \
inc/menu_dlg.h \
inc/holiday_dlg.h \
inc/edit_dlg.h \
RESOURCES += thermostat.qrc


Loading…
Cancel
Save