Start implementing switch off timer in gui.

Этот коммит содержится в:
Andrius Štikonas 2015-11-16 01:51:27 +00:00
родитель af7a1545d1
Коммит 504a700b80
3 изменённых файлов: 66 добавлений и 19 удалений

Просмотреть файл

@ -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();
}

Просмотреть файл

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

Просмотреть файл

@ -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>