Browse Source

Start implementing switch off timer in gui.

master
Andrius Štikonas 4 years ago
parent
commit
504a700b80
3 changed files with 66 additions and 19 deletions
  1. +19
    -7
      dialog.cpp
  2. +1
    -0
      dialog.h
  3. +46
    -12
      dialog.ui

+ 19
- 7
dialog.cpp View File

@@ -27,8 +27,10 @@ Dialog::Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent) :
sockets = sockets_vector;
ui->setupUi(this);
connect(ui->toggleButton, &QPushButton::clicked, this, &Dialog::togglePower);
connect(ui->comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &Dialog::updateUi);
connect(ui->socketsComboBox, static_cast<void(QComboBox::*)(int)>(&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<Socket*>::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();
}

+ 1
- 0
dialog.h View File

@@ -40,6 +40,7 @@ private:
Ui::Dialog *ui;
std::vector<Socket*> *sockets;
void togglePower();
void toggleOffTimer();
};

#endif // DIALOG_H

+ 46
- 12
dialog.ui View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>269</height>
<width>464</width>
<height>279</height>
</rect>
</property>
<property name="windowTitle">
@@ -16,35 +16,35 @@
<widget class="QPushButton" name="toggleButton">
<property name="geometry">
<rect>
<x>300</x>
<y>200</y>
<x>360</x>
<y>220</y>
<width>84</width>
<height>33</height>
</rect>
</property>
<property name="text">
<string></string>
<string/>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>10</y>
<width>351</width>
<height>33</height>
<width>419</width>
<height>100</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Sockets:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="socketsComboBox">
<property name="minimumSize">
<size>
<width>250</width>
@@ -53,6 +53,40 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTimeEdit" name="offTimer">
<property name="maximumTime">
<time>
<hour>18</hour>
<minute>12</minute>
<second>15</second>
</time>
</property>
<property name="displayFormat">
<string>HH:mm:ss</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="offTimerLabel">
<property name="toolTip">
<string>Automatic switch off on a specified delay after switch on</string>
</property>
<property name="text">
<string>Switch off timer:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="offTimerEnabled">
<property name="text">
<string>Enable</string>
</property>
<property name="tristate">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

Loading…
Cancel
Save