2019-03-04 19:48:40 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-04 19:48:40 +00:00
|
|
|
|
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
|
|
|
|
2019-08-01 17:52:28 +00:00
|
|
|
ModalMessageBox::ModalMessageBox(QWidget* parent, Qt::WindowModality modality)
|
2019-03-11 17:20:13 +00:00
|
|
|
: QMessageBox(parent != nullptr ? parent->window() : nullptr)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-08-01 17:52:28 +00:00
|
|
|
setWindowModality(modality);
|
2019-03-11 17:20:13 +00:00
|
|
|
setWindowFlags(Qt::Sheet | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
|
2019-03-04 19:48:40 +00:00
|
|
|
|
|
|
|
// No parent is still preferable to showing a hidden parent here.
|
2019-03-11 17:20:13 +00:00
|
|
|
if (parent != nullptr && !parent->window()->isVisible())
|
2019-03-04 19:48:40 +00:00
|
|
|
setParent(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ExecMessageBox(ModalMessageBox::Icon icon, QWidget* parent, const QString& title,
|
|
|
|
const QString& text, ModalMessageBox::StandardButtons buttons,
|
2019-11-10 22:57:43 +00:00
|
|
|
ModalMessageBox::StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-11-10 22:57:43 +00:00
|
|
|
ModalMessageBox msg(parent, modality);
|
2019-03-04 19:48:40 +00:00
|
|
|
msg.setIcon(icon);
|
|
|
|
msg.setWindowTitle(title);
|
|
|
|
msg.setText(text);
|
|
|
|
msg.setStandardButtons(buttons);
|
|
|
|
msg.setDefaultButton(default_button);
|
|
|
|
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(&msg);
|
2019-03-04 19:48:40 +00:00
|
|
|
return msg.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::critical(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 22:57:43 +00:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-11-10 22:57:43 +00:00
|
|
|
return ExecMessageBox(QMessageBox::Critical, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 19:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::information(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 22:57:43 +00:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-11-10 22:57:43 +00:00
|
|
|
return ExecMessageBox(QMessageBox::Information, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 19:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::question(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 22:57:43 +00:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-11-10 22:57:43 +00:00
|
|
|
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 19:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::warning(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 22:57:43 +00:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 19:48:40 +00:00
|
|
|
{
|
2019-11-10 22:57:43 +00:00
|
|
|
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 19:48:40 +00:00
|
|
|
}
|