2019-03-04 12:48:40 -07:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
2019-08-01 11:52:28 -06:00
|
|
|
ModalMessageBox::ModalMessageBox(QWidget* parent, Qt::WindowModality modality)
|
2019-03-11 11:20:13 -06:00
|
|
|
: QMessageBox(parent != nullptr ? parent->window() : nullptr)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-08-01 11:52:28 -06:00
|
|
|
setWindowModality(modality);
|
2019-03-11 11:20:13 -06:00
|
|
|
setWindowFlags(Qt::Sheet | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
|
2019-03-04 12:48:40 -07:00
|
|
|
|
|
|
|
// No parent is still preferable to showing a hidden parent here.
|
2019-03-11 11:20:13 -06:00
|
|
|
if (parent != nullptr && !parent->window()->isVisible())
|
2019-03-04 12:48:40 -07:00
|
|
|
setParent(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ExecMessageBox(ModalMessageBox::Icon icon, QWidget* parent, const QString& title,
|
|
|
|
const QString& text, ModalMessageBox::StandardButtons buttons,
|
2019-11-10 15:57:43 -07:00
|
|
|
ModalMessageBox::StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-11-10 15:57:43 -07:00
|
|
|
ModalMessageBox msg(parent, modality);
|
2019-03-04 12:48:40 -07:00
|
|
|
msg.setIcon(icon);
|
|
|
|
msg.setWindowTitle(title);
|
|
|
|
msg.setText(text);
|
|
|
|
msg.setStandardButtons(buttons);
|
|
|
|
msg.setDefaultButton(default_button);
|
|
|
|
|
|
|
|
return msg.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::critical(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 15:57:43 -07:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-11-10 15:57:43 -07:00
|
|
|
return ExecMessageBox(QMessageBox::Critical, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 12:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::information(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 15:57:43 -07:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-11-10 15:57:43 -07:00
|
|
|
return ExecMessageBox(QMessageBox::Information, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 12:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::question(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 15:57:43 -07:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-11-10 15:57:43 -07:00
|
|
|
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 12:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModalMessageBox::warning(QWidget* parent, const QString& title, const QString& text,
|
2019-11-10 15:57:43 -07:00
|
|
|
StandardButtons buttons, StandardButton default_button,
|
|
|
|
Qt::WindowModality modality)
|
2019-03-04 12:48:40 -07:00
|
|
|
{
|
2019-11-10 15:57:43 -07:00
|
|
|
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button,
|
|
|
|
modality);
|
2019-03-04 12:48:40 -07:00
|
|
|
}
|