Skip to content

Commit f31b5d0

Browse files
Editing loading screen for toggle switch
1 parent 6e516be commit f31b5d0

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/Create3Widget.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QGridLayout>
2727
int exampleIndex;
2828
QStringList programList;
29+
QMessageBox *msgBox;
2930

3031
class Create3SensorItemDelegate : public QItemDelegate
3132
{
@@ -116,7 +117,6 @@ void Create3Widget::toggleChanged()
116117
QString ipOutput = QString(output);
117118

118119
qDebug() << "IP OUTPUT: " << ipOutput; // Get current IP output
119-
120120

121121
if (ipOutput.contains("192.168.125.1"))
122122
{
@@ -137,9 +137,16 @@ void Create3Widget::toggleChanged()
137137
else
138138
{
139139
rebootBox();
140+
// Use a QTimer to delay the reboot process
141+
QTimer::singleShot(2000, this, [this, msgBox]()
142+
{
140143
QProcess process;
141144
process.startDetached("/bin/sh", QStringList() << "/home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
142145
<< "eth");
146+
147+
msgBox->close(); });
148+
149+
143150
}
144151
}
145152
else if (ipOutput.contains("192.168.186.3"))
@@ -159,64 +166,71 @@ void Create3Widget::toggleChanged()
159166
}
160167
else
161168
{
162-
rebootBox();
169+
rebootBox();
170+
// Use a QTimer to delay the reboot process
171+
QTimer::singleShot(2000, this, [this, msgBox]()
172+
{
163173
QProcess process;
164174
process.startDetached("/bin/sh", QStringList() << "/home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
165175
<< "wifi");
176+
177+
msgBox->close(); });
178+
166179
}
167180
}
168181
}
169182

170183
void Create3Widget::rebootBox()
171184
{
172185

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);
181191

192+
// Create QLabel for the GIF
182193
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
186195

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
188199

200+
// Create a container widget and a new vertical layout
189201
QWidget *container = new QWidget();
190202
QVBoxLayout *vLayout = new QVBoxLayout(container);
191203

204+
// Add the GIF label and message label to the vertical layout
192205
vLayout->addWidget(gifLabel);
193-
194206
vLayout->addWidget(messageLabel);
195-
vLayout->setAlignment(Qt::AlignCenter);
196-
gifLabel->setAlignment(Qt::AlignCenter);
197-
messageLabel->setAlignment(Qt::AlignCenter);
198207

199-
msgBoxLayout->setSpacing(0);
208+
// Adjust the vertical layout spacing and margins
200209
vLayout->setSpacing(10);
210+
vLayout->setContentsMargins(10, 10, 10, 10);
201211

212+
// Set the layout of the container
202213
container->setLayout(vLayout);
203214

215+
// Access the internal layout of the QMessageBox
216+
QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout());
204217
if (msgBoxLayout)
205218
{
206219
msgBoxLayout->addWidget(container, 0, 0, 1, msgBoxLayout->columnCount());
207220
}
208221

209-
gifLabel->move(200, -50);
210-
gifLabel->resize(400, 1100);
211-
222+
// Setup and start the GIF movie
212223
QMovie *movie = new QMovie("://qml/botguy_noMargin.gif");
213224
movie->setScaledSize(QSize(200, 240));
214225
gifLabel->setMovie(movie);
215226
movie->start();
216-
gifLabel->show();
217227

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...";
220234
}
221235

222236
QString Create3Widget::getIP()

0 commit comments

Comments
 (0)