Relocate showToast from settings to MainWindow

This commit is contained in:
Nicolas Mailloux 2021-08-25 13:32:33 -04:00
parent 191efea6a8
commit 5929d59c9c
5 changed files with 34 additions and 15 deletions

View file

@ -594,8 +594,10 @@ void MainWindow::on_settingsBtn_clicked()
ui->settingsBtn->setStyleSheet("background: black");
ui->settingsBtn->setIcon(QIcon(":/resources/settings-inverted.png"));
// Create widget
// Create widget and make necessary connections
settingsChooserWindow = new settingsChooser();
connect(settingsChooserWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(settingsChooserWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
ui->stackedWidget->insertWidget(2, settingsChooserWindow);
global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = true;

View file

@ -327,6 +327,10 @@ settings::settings(QWidget *parent) :
}
if(global::device::isWifiAble == false) {
ui->checkOtaUpdateLabel->hide();
ui->checkOtaUpdateBtn->hide();
ui->checkOtaUpdateLabel->deleteLater();
ui->checkOtaUpdateBtn->deleteLater();
ui->checkOtaUpdateGridLayout->deleteLater();
}
@ -871,8 +875,8 @@ void settings::openUpdateDialog() {
// Show the dialog
generalDialogWindow = new generalDialog(this);
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
generalDialogWindow->show();
QApplication::processEvents();
}
@ -893,16 +897,10 @@ void settings::openUpdateDialogOTA(bool open) {
}
}
void settings::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay;
toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
toastWindow->show();
void settings::showToastNative(QString messageToDisplay) {
emit showToast(messageToDisplay);
}
void settings::closeIndefiniteToast() {
// Warning: use with caution
toastWindow->close();
void settings::closeIndefiniteToastNative() {
emit closeIndefiniteToast();
}

View file

@ -59,6 +59,10 @@ private slots:
void openUpdateDialog();
void launchOtaUpdater();
void openUpdateDialogOTA(bool open);
void showToastNative(QString messageToDisplay);
void closeIndefiniteToastNative();
signals:
void showToast(QString messageToDisplay);
void closeIndefiniteToast();

View file

@ -18,7 +18,7 @@ settingsChooser::settingsChooser(QWidget *parent) :
stylesheetFile.close();
// UI tweaks
if(checkconfig("/opt/inkbox_kobox_support") != true) {
if(checkconfig("/opt/inkbox_kobox_support") == false) {
ui->koboxSettingsBtn->hide();
ui->line_3->hide();
}
@ -73,6 +73,8 @@ void settingsChooser::on_inkboxSettingsBtn_clicked()
{
settingsWindow = new settings();
settingsWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(settingsWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
connect(settingsWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
settingsWindow->showFullScreen();
}
@ -82,3 +84,11 @@ void settingsChooser::on_koboxSettingsBtn_clicked()
koboxSettingsWindow->setAttribute(Qt::WA_DeleteOnClose);
koboxSettingsWindow->showFullScreen();
}
void settingsChooser::showToastNative(QString messageToDisplay) {
emit showToast(messageToDisplay);
}
void settingsChooser::closeIndefiniteToastNative() {
emit closeIndefiniteToast();
}

View file

@ -25,8 +25,13 @@ public:
private slots:
void on_inkboxSettingsBtn_clicked();
void on_koboxSettingsBtn_clicked();
void showToastNative(QString messageToDisplay);
void closeIndefiniteToastNative();
signals:
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
private:
Ui::settingsChooser *ui;