Merge pull request #2438 from Cacodemon345/new-qt-fix

qt: Make fatal messageboxes have the correct icons
This commit is contained in:
Miran Grča
2022-07-10 00:27:02 +02:00
committed by GitHub
3 changed files with 16 additions and 8 deletions

View File

@@ -36,6 +36,7 @@ extern "C" {
#include <86box/config.h> #include <86box/config.h>
#include <86box/keyboard.h> #include <86box/keyboard.h>
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/ui.h>
#include <86box/discord.h> #include <86box/discord.h>
#include <86box/video.h> #include <86box/video.h>
#include <86box/machine.h> #include <86box/machine.h>
@@ -1448,18 +1449,25 @@ void MainWindow::refreshMediaMenu() {
ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA));
} }
void MainWindow::showMessage(const QString& header, const QString& message) { void MainWindow::showMessage(int flags, const QString& header, const QString& message) {
if (QThread::currentThread() == this->thread()) { if (QThread::currentThread() == this->thread()) {
showMessage_(header, message); showMessage_(flags, header, message);
} else { } else {
emit showMessageForNonQtThread(header, message); emit showMessageForNonQtThread(flags, header, message);
} }
} }
void MainWindow::showMessage_(const QString &header, const QString &message) { void MainWindow::showMessage_(int flags, const QString &header, const QString &message) {
QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this); QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this);
if (flags & (MBX_FATAL)) {
box.setIcon(QMessageBox::Critical);
}
else if (!(flags & (MBX_ERROR | MBX_WARNING))) {
box.setIcon(QMessageBox::Warning);
}
box.setTextFormat(Qt::TextFormat::RichText); box.setTextFormat(Qt::TextFormat::RichText);
box.exec(); box.exec();
if (cpu_thread_run == 0) QApplication::exit(-1);
} }
void MainWindow::keyPressEvent(QKeyEvent* event) void MainWindow::keyPressEvent(QKeyEvent* event)

View File

@@ -24,7 +24,7 @@ public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
void showMessage(const QString& header, const QString& message); void showMessage(int flags, const QString& header, const QString& message);
void getTitle(wchar_t* title); void getTitle(wchar_t* title);
void blitToWidget(int x, int y, int w, int h); void blitToWidget(int x, int y, int w, int h);
QSize getRenderWidgetSize(); QSize getRenderWidgetSize();
@@ -45,7 +45,7 @@ signals:
void setFullscreen(bool state); void setFullscreen(bool state);
void setMouseCapture(bool state); void setMouseCapture(bool state);
void showMessageForNonQtThread(const QString& header, const QString& message); void showMessageForNonQtThread(int flags, const QString& header, const QString& message);
void getTitleForNonQtThread(wchar_t* title); void getTitleForNonQtThread(wchar_t* title);
public slots: public slots:
void showSettings(); void showSettings();
@@ -100,7 +100,7 @@ private slots:
void on_actionRenderer_options_triggered(); void on_actionRenderer_options_triggered();
void refreshMediaMenu(); void refreshMediaMenu();
void showMessage_(const QString& header, const QString& message); void showMessage_(int flags, const QString& header, const QString& message);
void getTitle_(wchar_t* title); void getTitle_(wchar_t* title);
void on_actionMCA_devices_triggered(); void on_actionMCA_devices_triggered();

View File

@@ -93,7 +93,7 @@ int ui_msgbox_header(int flags, void *header, void* message) {
msgBox.exec(); msgBox.exec();
} else { } else {
// else scope it to main_window // else scope it to main_window
main_window->showMessage(hdr, msg); main_window->showMessage(flags, hdr, msg);
} }
return 0; return 0;
} }