Browse Source

Start implementing switch off timer in gui.

master
Andrius Štikonas 3 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) :
27 27
     sockets = sockets_vector;
28 28
     ui->setupUi(this);
29 29
     connect(ui->toggleButton, &QPushButton::clicked, this, &Dialog::togglePower);
30
-    connect(ui->comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &Dialog::updateUi);
30
+    connect(ui->socketsComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &Dialog::updateUi);
31
+    connect(ui->offTimerEnabled, &QCheckBox::released, this, &Dialog::toggleOffTimer);
31 32
     updateUi();
33
+    ui->offTimer->setEnabled(false);
32 34
 }
33 35
 
34 36
 Dialog::~Dialog()
@@ -39,23 +41,27 @@ Dialog::~Dialog()
39 41
 void Dialog::updateUi()
40 42
 {
41 43
     for (unsigned int i = 0; i < (*sockets).size(); ++i) {
42
-        ui->comboBox->setItemText(i, (*sockets)[i]->socketName);
44
+        ui->socketsComboBox->setItemText(i, (*sockets)[i]->socketName);
43 45
     }
44
-    if (ui->comboBox->currentIndex() != -1) {
46
+    unsigned int index = ui->socketsComboBox->currentIndex();
47
+    if (index != -1) {
45 48
         ui->toggleButton->setEnabled(true);
46
-        ui->toggleButton->setText((*sockets)[ui->comboBox->currentIndex()]->powered ? QStringLiteral("Turn off") : QStringLiteral("Turn on"));
49
+        ui->offTimerEnabled->setEnabled(true);
50
+        ui->toggleButton->setText((*sockets)[index]->powered ? QStringLiteral("Turn off") : QStringLiteral("Turn on"));
51
+        ui->offTimerEnabled->setChecked((*sockets)[index]->offTimerEnabled);
47 52
     }
48 53
     else {
49 54
         ui->toggleButton->setEnabled(false);
55
+        ui->offTimerEnabled->setEnabled(false);
50 56
     }
51 57
 }
52 58
 
53 59
 void Dialog::discovered()
54 60
 {
55
-    ui->comboBox->clear();
61
+    ui->socketsComboBox->clear();
56 62
     for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
57 63
         connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
58
-        ui->comboBox->addItem("Socket");
64
+        ui->socketsComboBox->addItem("Socket");
59 65
     }
60 66
 
61 67
     updateUi();
@@ -63,5 +69,11 @@ void Dialog::discovered()
63 69
 
64 70
 void Dialog::togglePower()
65 71
 {
66
-    (*sockets)[ui->comboBox->currentIndex()]->toggle();
72
+    (*sockets)[ui->socketsComboBox->currentIndex()]->toggle();
73
+}
74
+
75
+void Dialog::toggleOffTimer()
76
+{
77
+    ui->offTimerEnabled->setCheckState(Qt::PartiallyChecked);
78
+    (*sockets)[ui->socketsComboBox->currentIndex()]->toggleOffTimer();
67 79
 }

+ 1
- 0
dialog.h View File

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

+ 46
- 12
dialog.ui View File

@@ -6,8 +6,8 @@
6 6
    <rect>
7 7
     <x>0</x>
8 8
     <y>0</y>
9
-    <width>434</width>
10
-    <height>269</height>
9
+    <width>464</width>
10
+    <height>279</height>
11 11
    </rect>
12 12
   </property>
13 13
   <property name="windowTitle">
@@ -16,35 +16,35 @@
16 16
   <widget class="QPushButton" name="toggleButton">
17 17
    <property name="geometry">
18 18
     <rect>
19
-     <x>300</x>
20
-     <y>200</y>
19
+     <x>360</x>
20
+     <y>220</y>
21 21
      <width>84</width>
22 22
      <height>33</height>
23 23
     </rect>
24 24
    </property>
25 25
    <property name="text">
26
-    <string></string>
26
+    <string/>
27 27
    </property>
28 28
   </widget>
29
-  <widget class="QWidget" name="">
29
+  <widget class="QWidget" name="layoutWidget">
30 30
    <property name="geometry">
31 31
     <rect>
32 32
      <x>30</x>
33 33
      <y>10</y>
34
-     <width>351</width>
35
-     <height>33</height>
34
+     <width>419</width>
35
+     <height>100</height>
36 36
     </rect>
37 37
    </property>
38
-   <layout class="QHBoxLayout" name="horizontalLayout">
39
-    <item>
38
+   <layout class="QGridLayout" name="gridLayout">
39
+    <item row="0" column="0">
40 40
      <widget class="QLabel" name="label">
41 41
       <property name="text">
42 42
        <string>Sockets:</string>
43 43
       </property>
44 44
      </widget>
45 45
     </item>
46
-    <item>
47
-     <widget class="QComboBox" name="comboBox">
46
+    <item row="0" column="1" colspan="2">
47
+     <widget class="QComboBox" name="socketsComboBox">
48 48
       <property name="minimumSize">
49 49
        <size>
50 50
         <width>250</width>
@@ -53,6 +53,40 @@
53 53
       </property>
54 54
      </widget>
55 55
     </item>
56
+    <item row="1" column="1">
57
+     <widget class="QTimeEdit" name="offTimer">
58
+      <property name="maximumTime">
59
+       <time>
60
+        <hour>18</hour>
61
+        <minute>12</minute>
62
+        <second>15</second>
63
+       </time>
64
+      </property>
65
+      <property name="displayFormat">
66
+       <string>HH:mm:ss</string>
67
+      </property>
68
+     </widget>
69
+    </item>
70
+    <item row="1" column="0">
71
+     <widget class="QLabel" name="offTimerLabel">
72
+      <property name="toolTip">
73
+       <string>Automatic switch off on a specified delay after switch on</string>
74
+      </property>
75
+      <property name="text">
76
+       <string>Switch off timer:</string>
77
+      </property>
78
+     </widget>
79
+    </item>
80
+    <item row="1" column="2">
81
+     <widget class="QCheckBox" name="offTimerEnabled">
82
+      <property name="text">
83
+       <string>Enable</string>
84
+      </property>
85
+      <property name="tristate">
86
+       <bool>true</bool>
87
+      </property>
88
+     </widget>
89
+    </item>
56 90
    </layout>
57 91
   </widget>
58 92
  </widget>

Loading…
Cancel
Save