7
7
#include " RootController.h"
8
8
#include " DeveloperListWidget.h"
9
9
#include < QProcess>
10
+ #include < QMovie>
10
11
#include < QDebug>
11
12
#include < QRegularExpression>
12
-
13
+ #include < QTimer>
14
+ #include < unistd.h>
13
15
AboutWidget::AboutWidget (Device *device, QWidget *parent)
14
16
: StandardWidget(device, parent),
15
- ui(new Ui::AboutWidget)
17
+ ui(new Ui::AboutWidget), msgBox( nullptr )
16
18
{
17
19
ui->setupUi (this );
18
20
// Setup the UI
@@ -94,13 +96,79 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
94
96
95
97
connect (ui->developerList , SIGNAL (clicked ()), SLOT (developerList ()));
96
98
connect (ui->toggleSwitch , SIGNAL (stateChanged (int )), this , SLOT (eventModeBackground (int )));
99
+ connect (ui->toggleSwitch , SIGNAL (stateChanged (int )), this , SLOT (rebootBox ()));
97
100
}
98
101
99
102
AboutWidget::~AboutWidget ()
100
103
{
104
+ if (msgBox)
105
+ {
106
+ msgBox->deleteLater (); // or delete msgBox; if you want to directly delete
107
+ }
101
108
delete ui;
102
109
}
103
110
111
+ void AboutWidget::rebootBox ()
112
+ {
113
+ qDebug () << " In rebootBox()" ;
114
+
115
+ if (!msgBox)
116
+ {
117
+ // Create the QMessageBox
118
+ msgBox = new QMessageBox (this );
119
+ msgBox->setWindowTitle (" Switch Event Mode" );
120
+ msgBox->setMaximumSize (500 , 480 ); // Limit the size of the QMessageBox
121
+ msgBox->setStandardButtons (QMessageBox::NoButton);
122
+
123
+ // Create QLabel for the GIF
124
+ QLabel *gifLabel = new QLabel ();
125
+ gifLabel->setAlignment (Qt::AlignCenter); // Center the GIF label
126
+
127
+ // Create QLabel for the message text
128
+ QLabel *messageLabel = new QLabel (" Switching Event Mode Now..." );
129
+ messageLabel->setAlignment (Qt::AlignCenter); // Center the message label
130
+
131
+ // Create a container widget and a new vertical layout
132
+ QWidget *container = new QWidget ();
133
+ QVBoxLayout *vLayout = new QVBoxLayout (container);
134
+
135
+ // Add the GIF label and message label to the vertical layout
136
+ vLayout->addWidget (gifLabel);
137
+ vLayout->addWidget (messageLabel);
138
+
139
+ // Adjust the vertical layout spacing and margins
140
+ vLayout->setSpacing (10 );
141
+ vLayout->setContentsMargins (10 , 10 , 10 , 10 );
142
+
143
+ // Set the layout of the container
144
+ container->setLayout (vLayout);
145
+
146
+ // Access the internal layout of the QMessageBox
147
+ QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout ());
148
+ if (msgBoxLayout)
149
+ {
150
+ msgBoxLayout->addWidget (container, 0 , 0 , 1 , msgBoxLayout->columnCount ());
151
+ }
152
+ else
153
+ {
154
+ qDebug () << " msgBoxLayout is nullptr!" ; // Debugging message if layout is nullptr
155
+ }
156
+
157
+ // Setup and start the GIF movie
158
+ QMovie *movie = new QMovie (" ://qml/botguy_noMargin.gif" );
159
+ movie->setScaledSize (QSize (200 , 240 ));
160
+ gifLabel->setMovie (movie);
161
+ movie->start ();
162
+
163
+ // Show the QMessageBox non-blocking
164
+ msgBox->setText (" " ); // Hide the default text to avoid duplication
165
+ }
166
+ msgBox->show ();
167
+
168
+ // Debug information
169
+ qDebug () << " Message box displayed, starting event mode change sequence..." ;
170
+ }
171
+
104
172
QString AboutWidget::getRaspberryPiType ()
105
173
{
106
174
QProcess process;
@@ -115,12 +183,11 @@ QString AboutWidget::getRaspberryPiType()
115
183
{
116
184
qDebug () << " Successfully got Raspberry Pi Type:" << output.trimmed (); // Trim output to remove whitespace
117
185
118
-
119
- if (output.trimmed () == " a020d3" || output.trimmed () == " a020d4" )
186
+ if (output.trimmed () == " a020d3" || output.trimmed () == " a020d4" )
120
187
{
121
188
piType = " 3B+" ;
122
189
}
123
- else if (output.trimmed () == " a02082" || output.trimmed () == " a22082" || output.trimmed () == " a32082" || output.trimmed () == " a52082" || output.trimmed () == " a22083" )
190
+ else if (output.trimmed () == " a02082" || output.trimmed () == " a22082" || output.trimmed () == " a32082" || output.trimmed () == " a52082" || output.trimmed () == " a22083" )
124
191
{
125
192
piType = " 3B" ;
126
193
}
@@ -192,22 +259,30 @@ void AboutWidget::eventModeBackground(int checked)
192
259
qDebug () << " Checked: " << checked;
193
260
194
261
ui->toggleSwitch ->setEnabled (false );
195
-
262
+ // rebootBox();
196
263
if (checked == 2 ) // Enable Event Mode
197
264
{
198
265
199
266
setEventModeState (" true" );
200
267
emit eventModeEnabled ();
201
268
NetworkManager::ref ().deactivateAP ();
202
- ui->toggleSwitch ->setEnabled (true );
203
269
}
204
270
else // Disable Event Mode
205
271
{
206
272
setEventModeState (" false" );
207
273
emit eventModeDisabled ();
208
274
NetworkManager::ref ().enableAP ();
209
- ui->toggleSwitch ->setEnabled (true );
210
275
}
276
+
277
+ QTimer::singleShot (3000 , this , [this ]()
278
+ {
279
+ if (msgBox)
280
+ {
281
+ msgBox->hide ();
282
+ delete msgBox;
283
+ msgBox = nullptr ;
284
+ }
285
+ ui->toggleSwitch ->setEnabled (true ); });
211
286
}
212
287
213
288
void AboutWidget::developerList ()
0 commit comments