Skip to content

Commit

Permalink
Added gif to Event Mode toggle to prevent repeated mashing of button
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Dec 17, 2024
1 parent 9dd615d commit dfa6d92
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
6 changes: 5 additions & 1 deletion include/botui/AboutWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "StandardWidget.h" // Include here if needed for inheritance
#include <QProcess>

#include <QMessageBox>
namespace Ui
{
class AboutWidget;
Expand All @@ -29,9 +29,13 @@ public slots:
void developerList();
void eventModeBackground(int checked);

private slots:
void rebootBox();

private:
Ui::AboutWidget *ui;
QProcess proc;
QMessageBox *msgBox;
};

#endif
89 changes: 81 additions & 8 deletions src/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "RootController.h"
#include "DeveloperListWidget.h"
#include <QProcess>
#include <QMovie>
#include <QDebug>
#include <QRegularExpression>

#include <QTimer>
#include <unistd.h>
AboutWidget::AboutWidget(Device *device, QWidget *parent)
: StandardWidget(device, parent),
ui(new Ui::AboutWidget)
ui(new Ui::AboutWidget), msgBox(nullptr)
{
ui->setupUi(this);
// Setup the UI
Expand Down Expand Up @@ -98,9 +100,74 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)

AboutWidget::~AboutWidget()
{
if (msgBox)
{
msgBox->deleteLater(); // or delete msgBox; if you want to directly delete
}
delete ui;
}

void AboutWidget::rebootBox()
{
qDebug() << "In rebootBox()";

if (!msgBox)
{
// Create the QMessageBox
msgBox = new QMessageBox(this);
msgBox->setWindowTitle("Switch Event Mode");
msgBox->setMaximumSize(500, 480); // Limit the size of the QMessageBox
msgBox->setStandardButtons(QMessageBox::NoButton);

// Create QLabel for the GIF
QLabel *gifLabel = new QLabel();
gifLabel->setAlignment(Qt::AlignCenter); // Center the GIF label

// Create QLabel for the message text
QLabel *messageLabel = new QLabel("Switching Event Mode Now...");
messageLabel->setAlignment(Qt::AlignCenter); // Center the message label

// Create a container widget and a new vertical layout
QWidget *container = new QWidget();
QVBoxLayout *vLayout = new QVBoxLayout(container);

// Add the GIF label and message label to the vertical layout
vLayout->addWidget(gifLabel);
vLayout->addWidget(messageLabel);

// Adjust the vertical layout spacing and margins
vLayout->setSpacing(10);
vLayout->setContentsMargins(10, 10, 10, 10);

// Set the layout of the container
container->setLayout(vLayout);

// Access the internal layout of the QMessageBox
QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout());
if (msgBoxLayout)
{
msgBoxLayout->addWidget(container, 0, 0, 1, msgBoxLayout->columnCount());
}
else
{
qDebug() << "msgBoxLayout is nullptr!"; // Debugging message if layout is nullptr
}

// Setup and start the GIF movie
QMovie *movie = new QMovie("://qml/botguy_noMargin.gif");
movie->setScaledSize(QSize(200, 240));
gifLabel->setMovie(movie);
movie->start();

// Show the QMessageBox non-blocking
msgBox->setText(""); // Hide the default text to avoid duplication
}
msgBox->show();

// Debug information
qDebug() << "Message box displayed, starting event mode change sequence...";
}

QString AboutWidget::getRaspberryPiType()
{
QProcess process;
Expand All @@ -115,12 +182,11 @@ QString AboutWidget::getRaspberryPiType()
{
qDebug() << "Successfully got Raspberry Pi Type:" << output.trimmed(); // Trim output to remove whitespace


if(output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
if (output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
{
piType = "3B+";
}
else if(output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
else if (output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
{
piType = "3B";
}
Expand Down Expand Up @@ -192,22 +258,29 @@ void AboutWidget::eventModeBackground(int checked)
qDebug() << "Checked: " << checked;

ui->toggleSwitch->setEnabled(false);

rebootBox();
if (checked == 2) // Enable Event Mode
{

setEventModeState("true");
emit eventModeEnabled();
NetworkManager::ref().deactivateAP();
ui->toggleSwitch->setEnabled(true);
}
else // Disable Event Mode
{
setEventModeState("false");
emit eventModeDisabled();
NetworkManager::ref().enableAP();
ui->toggleSwitch->setEnabled(true);
}
ui->toggleSwitch->setEnabled(true);
QTimer::singleShot(2000, this, [this]() {
if (msgBox)
{
msgBox->hide();
delete msgBox;
msgBox = nullptr;
}
});
}

void AboutWidget::developerList()
Expand Down

0 comments on commit dfa6d92

Please sign in to comment.