26
26
#include < QGridLayout>
27
27
int exampleIndex;
28
28
QStringList programList;
29
+ QMessageBox *msgBox;
29
30
30
31
class Create3SensorItemDelegate : public QItemDelegate
31
32
{
@@ -116,7 +117,6 @@ void Create3Widget::toggleChanged()
116
117
QString ipOutput = QString (output);
117
118
118
119
qDebug () << " IP OUTPUT: " << ipOutput; // Get current IP output
119
-
120
120
121
121
if (ipOutput.contains (" 192.168.125.1" ))
122
122
{
@@ -137,9 +137,16 @@ void Create3Widget::toggleChanged()
137
137
else
138
138
{
139
139
rebootBox ();
140
+ // Use a QTimer to delay the reboot process
141
+ QTimer::singleShot (2000 , this , [this , msgBox]()
142
+ {
140
143
QProcess process;
141
144
process.startDetached (" /bin/sh" , QStringList () << " /home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
142
145
<< " eth" );
146
+
147
+ msgBox->close (); });
148
+
149
+
143
150
}
144
151
}
145
152
else if (ipOutput.contains (" 192.168.186.3" ))
@@ -159,64 +166,71 @@ void Create3Widget::toggleChanged()
159
166
}
160
167
else
161
168
{
162
- rebootBox ();
169
+ rebootBox ();
170
+ // Use a QTimer to delay the reboot process
171
+ QTimer::singleShot (2000 , this , [this , msgBox]()
172
+ {
163
173
QProcess process;
164
174
process.startDetached (" /bin/sh" , QStringList () << " /home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
165
175
<< " wifi" );
176
+
177
+ msgBox->close (); });
178
+
166
179
}
167
180
}
168
181
}
169
182
170
183
void Create3Widget::rebootBox ()
171
184
{
172
185
173
- QMessageBox msgBox (this );
174
- msgBox.setWindowTitle (" Reboot" );
175
- msgBox.setText (" Rebooting now..." );
176
-
177
- // msgBox.setText("Rebooting...");
178
- msgBox.setMaximumSize (500 , 480 );
179
- // msgBox.setStyleSheet("QLabel{min-width: 450px; min-height: 280px;}");
180
- msgBox.setStandardButtons (QMessageBox::NoButton);
186
+ // Create the QMessageBox
187
+ msgBox = new QMessageBox (this );
188
+ msgBox->setWindowTitle (" Reboot" );
189
+ msgBox->setMaximumSize (500 , 480 ); // Limit the size of the QMessageBox
190
+ msgBox->setStandardButtons (QMessageBox::NoButton);
181
191
192
+ // Create QLabel for the GIF
182
193
QLabel *gifLabel = new QLabel ();
183
- QLabel *messageLabel = new QLabel (msgBox.text ());
184
-
185
- QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox.layout ());
194
+ gifLabel->setAlignment (Qt::AlignCenter); // Center the GIF label
186
195
187
- msgBoxLayout->setVerticalSpacing (0 );
196
+ // Create QLabel for the message text
197
+ QLabel *messageLabel = new QLabel (" Rebooting now..." );
198
+ messageLabel->setAlignment (Qt::AlignCenter); // Center the message label
188
199
200
+ // Create a container widget and a new vertical layout
189
201
QWidget *container = new QWidget ();
190
202
QVBoxLayout *vLayout = new QVBoxLayout (container);
191
203
204
+ // Add the GIF label and message label to the vertical layout
192
205
vLayout->addWidget (gifLabel);
193
-
194
206
vLayout->addWidget (messageLabel);
195
- vLayout->setAlignment (Qt::AlignCenter);
196
- gifLabel->setAlignment (Qt::AlignCenter);
197
- messageLabel->setAlignment (Qt::AlignCenter);
198
207
199
- msgBoxLayout-> setSpacing ( 0 );
208
+ // Adjust the vertical layout spacing and margins
200
209
vLayout->setSpacing (10 );
210
+ vLayout->setContentsMargins (10 , 10 , 10 , 10 );
201
211
212
+ // Set the layout of the container
202
213
container->setLayout (vLayout);
203
214
215
+ // Access the internal layout of the QMessageBox
216
+ QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout ());
204
217
if (msgBoxLayout)
205
218
{
206
219
msgBoxLayout->addWidget (container, 0 , 0 , 1 , msgBoxLayout->columnCount ());
207
220
}
208
221
209
- gifLabel->move (200 , -50 );
210
- gifLabel->resize (400 , 1100 );
211
-
222
+ // Setup and start the GIF movie
212
223
QMovie *movie = new QMovie (" ://qml/botguy_noMargin.gif" );
213
224
movie->setScaledSize (QSize (200 , 240 ));
214
225
gifLabel->setMovie (movie);
215
226
movie->start ();
216
- gifLabel->show ();
217
227
218
- msgBox.setText (" " );
219
- msgBox.exec ();
228
+ // Show the QMessageBox non-blocking
229
+ msgBox->setText (" " ); // Hide the default text to avoid duplication
230
+ msgBox->show ();
231
+
232
+ // Debug information
233
+ qDebug () << " Message box displayed, starting reboot sequence..." ;
220
234
}
221
235
222
236
QString Create3Widget::getIP ()
0 commit comments