2021-07-13 22:24:30 -07:00
|
|
|
#include "toast.h"
|
|
|
|
#include "ui_toast.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QTimer>
|
2021-07-14 15:23:54 -07:00
|
|
|
#include <QDebug>
|
2021-07-13 22:24:30 -07:00
|
|
|
|
|
|
|
toast::toast(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::toast)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-07-14 15:23:54 -07:00
|
|
|
|
|
|
|
if(global::toast::modalToast == true) {
|
|
|
|
global::toast::modalToast = false;
|
|
|
|
this->setModal(true);
|
|
|
|
}
|
|
|
|
|
2021-07-13 22:24:30 -07:00
|
|
|
ui->messageLabel->setStyleSheet("padding: 35px");
|
|
|
|
ui->messageLabel->setText(global::toast::message);
|
|
|
|
this->adjustSize();
|
|
|
|
centerToast();
|
|
|
|
if(global::toast::wifiToast == true) {
|
|
|
|
global::toast::wifiToast = false;
|
2021-07-14 15:23:54 -07:00
|
|
|
this->setModal(true);
|
2021-07-13 22:24:30 -07:00
|
|
|
wifiDialogWindow = new wifiDialog(this);
|
|
|
|
wifiDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(wifiDialogWindow, SIGNAL(wifiNetworksListReady(int)), SLOT(showWifiDialog(int)));
|
2021-07-14 15:23:54 -07:00
|
|
|
connect(wifiDialogWindow, SIGNAL(quit(int)), SLOT(exitSlot(int)));
|
|
|
|
connect(wifiDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreenNative()));
|
|
|
|
connect(wifiDialogWindow, SIGNAL(updateWifiIconSig(int)), SLOT(updateWifiIcon(int)));
|
|
|
|
connect(wifiDialogWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
|
|
|
|
connect(wifiDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
|
|
|
|
connect(wifiDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(close()));
|
2021-07-13 22:24:30 -07:00
|
|
|
}
|
|
|
|
else {
|
2021-07-14 15:23:54 -07:00
|
|
|
if(global::toast::indefiniteToast == false) {
|
|
|
|
QTimer::singleShot(5000, this, SLOT(close()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
global::toast::indefiniteToast = false;
|
|
|
|
}
|
2021-07-13 22:24:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toast::~toast()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::showWifiDialog(int networksFound) {
|
|
|
|
if(networksFound == 1) {
|
|
|
|
emit updateWifiIconSig(2);
|
|
|
|
this->hide();
|
|
|
|
wifiDialogWindow->show();
|
|
|
|
wifiDialogWindow->adjustSize();
|
|
|
|
wifiDialogWindow->centerDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::centerToast() {
|
2021-07-14 15:23:54 -07:00
|
|
|
// Centering toast (https://stackoverflow.com/a/58682351)
|
2021-07-13 22:24:30 -07:00
|
|
|
// Get current screen size
|
|
|
|
QRect rec = QGuiApplication::screenAt(this->pos())->geometry();
|
|
|
|
// Using minimum size of window
|
|
|
|
QSize size = this->minimumSize();
|
|
|
|
// Set top left point
|
|
|
|
QPoint topLeft = QPoint((rec.width() / 2) - (size.width() / 2), (rec.height() / 2) - (size.height() / 2));
|
2021-07-14 15:23:54 -07:00
|
|
|
// Set window position
|
2021-07-13 22:24:30 -07:00
|
|
|
setGeometry(QRect(topLeft, size));
|
|
|
|
}
|
|
|
|
|
2021-07-14 15:23:54 -07:00
|
|
|
void toast::exitSlot(int exitCode) {
|
|
|
|
if(exitCode == 0) {
|
|
|
|
toast::close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui->messageLabel->setText("No networks found");
|
|
|
|
QTimer::singleShot(5000, this, SLOT(close()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::refreshScreenNative() {
|
|
|
|
emit refreshScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::updateWifiIcon(int mode) {
|
|
|
|
emit updateWifiIconSig(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::showToastNative(QString messageToDisplay) {
|
|
|
|
emit showToast(messageToDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void toast::closeIndefiniteToastNative() {
|
|
|
|
emit closeIndefiniteToast();
|
2021-07-13 22:24:30 -07:00
|
|
|
}
|