Start implementing switch off timer in gui.
This commit is contained in:
parent
af7a1545d1
commit
504a700b80
26
dialog.cpp
26
dialog.cpp
|
@ -27,8 +27,10 @@ Dialog::Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent) :
|
||||||
sockets = sockets_vector;
|
sockets = sockets_vector;
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->toggleButton, &QPushButton::clicked, this, &Dialog::togglePower);
|
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();
|
updateUi();
|
||||||
|
ui->offTimer->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog::~Dialog()
|
Dialog::~Dialog()
|
||||||
|
@ -39,23 +41,27 @@ Dialog::~Dialog()
|
||||||
void Dialog::updateUi()
|
void Dialog::updateUi()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < (*sockets).size(); ++i) {
|
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->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 {
|
else {
|
||||||
ui->toggleButton->setEnabled(false);
|
ui->toggleButton->setEnabled(false);
|
||||||
|
ui->offTimerEnabled->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::discovered()
|
void Dialog::discovered()
|
||||||
{
|
{
|
||||||
ui->comboBox->clear();
|
ui->socketsComboBox->clear();
|
||||||
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
|
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
|
||||||
connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
|
connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
|
||||||
ui->comboBox->addItem("Socket");
|
ui->socketsComboBox->addItem("Socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUi();
|
updateUi();
|
||||||
|
@ -63,5 +69,11 @@ void Dialog::discovered()
|
||||||
|
|
||||||
void Dialog::togglePower()
|
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
dialog.h
1
dialog.h
|
@ -40,6 +40,7 @@ private:
|
||||||
Ui::Dialog *ui;
|
Ui::Dialog *ui;
|
||||||
std::vector<Socket*> *sockets;
|
std::vector<Socket*> *sockets;
|
||||||
void togglePower();
|
void togglePower();
|
||||||
|
void toggleOffTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOG_H
|
#endif // DIALOG_H
|
||||||
|
|
58
dialog.ui
58
dialog.ui
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>434</width>
|
<width>464</width>
|
||||||
<height>269</height>
|
<height>279</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -16,35 +16,35 @@
|
||||||
<widget class="QPushButton" name="toggleButton">
|
<widget class="QPushButton" name="toggleButton">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>300</x>
|
<x>360</x>
|
||||||
<y>200</y>
|
<y>220</y>
|
||||||
<width>84</width>
|
<width>84</width>
|
||||||
<height>33</height>
|
<height>33</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string></string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>10</y>
|
<y>10</y>
|
||||||
<width>351</width>
|
<width>419</width>
|
||||||
<height>33</height>
|
<height>100</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Sockets:</string>
|
<string>Sockets:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="0" column="1" colspan="2">
|
||||||
<widget class="QComboBox" name="comboBox">
|
<widget class="QComboBox" name="socketsComboBox">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>250</width>
|
<width>250</width>
|
||||||
|
@ -53,6 +53,40 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in New Issue