From 504a700b80d2ad573ab70370a81b94a7c0e1e402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 16 Nov 2015 01:51:27 +0000 Subject: [PATCH] Start implementing switch off timer in gui. --- dialog.cpp | 26 +++++++++++++++++------- dialog.h | 1 + dialog.ui | 58 +++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 66 insertions(+), 19 deletions(-) diff --git a/dialog.cpp b/dialog.cpp index 070b264..7c2d7f1 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -27,8 +27,10 @@ Dialog::Dialog(std::vector *sockets_vector, QWidget *parent) : sockets = sockets_vector; ui->setupUi(this); connect(ui->toggleButton, &QPushButton::clicked, this, &Dialog::togglePower); - connect(ui->comboBox, static_cast(&QComboBox::currentIndexChanged), this, &Dialog::updateUi); + connect(ui->socketsComboBox, static_cast(&QComboBox::currentIndexChanged), this, &Dialog::updateUi); + connect(ui->offTimerEnabled, &QCheckBox::released, this, &Dialog::toggleOffTimer); updateUi(); + ui->offTimer->setEnabled(false); } Dialog::~Dialog() @@ -39,23 +41,27 @@ Dialog::~Dialog() void Dialog::updateUi() { for (unsigned int i = 0; i < (*sockets).size(); ++i) { - ui->comboBox->setItemText(i, (*sockets)[i]->socketName); + ui->socketsComboBox->setItemText(i, (*sockets)[i]->socketName); } - if (ui->comboBox->currentIndex() != -1) { + unsigned int index = ui->socketsComboBox->currentIndex(); + if (index != -1) { ui->toggleButton->setEnabled(true); - ui->toggleButton->setText((*sockets)[ui->comboBox->currentIndex()]->powered ? QStringLiteral("Turn off") : QStringLiteral("Turn on")); + ui->offTimerEnabled->setEnabled(true); + ui->toggleButton->setText((*sockets)[index]->powered ? QStringLiteral("Turn off") : QStringLiteral("Turn on")); + ui->offTimerEnabled->setChecked((*sockets)[index]->offTimerEnabled); } else { ui->toggleButton->setEnabled(false); + ui->offTimerEnabled->setEnabled(false); } } void Dialog::discovered() { - ui->comboBox->clear(); + ui->socketsComboBox->clear(); for (std::vector::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) { connect(*i, &Socket::stateChanged, this, &Dialog::updateUi); - ui->comboBox->addItem("Socket"); + ui->socketsComboBox->addItem("Socket"); } updateUi(); @@ -63,5 +69,11 @@ void Dialog::discovered() void Dialog::togglePower() { - (*sockets)[ui->comboBox->currentIndex()]->toggle(); + (*sockets)[ui->socketsComboBox->currentIndex()]->toggle(); +} + +void Dialog::toggleOffTimer() +{ + ui->offTimerEnabled->setCheckState(Qt::PartiallyChecked); + (*sockets)[ui->socketsComboBox->currentIndex()]->toggleOffTimer(); } diff --git a/dialog.h b/dialog.h index 1b10fc0..27828ef 100644 --- a/dialog.h +++ b/dialog.h @@ -40,6 +40,7 @@ private: Ui::Dialog *ui; std::vector *sockets; void togglePower(); + void toggleOffTimer(); }; #endif // DIALOG_H diff --git a/dialog.ui b/dialog.ui index 18337a3..bca21cf 100644 --- a/dialog.ui +++ b/dialog.ui @@ -6,8 +6,8 @@ 0 0 - 434 - 269 + 464 + 279 @@ -16,35 +16,35 @@ - 300 - 200 + 360 + 220 84 33 - + - + 30 10 - 351 - 33 + 419 + 100 - - + + Sockets: - - + + 250 @@ -53,6 +53,40 @@ + + + + + + + HH:mm:ss + + + + + + + Automatic switch off on a specified delay after switch on + + + Switch off timer: + + + + + + + Enable + + + true + + +