dolphin/Source/Core/DolphinQt/QtUtils/ModalMessageBox.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.6 KiB
C++
Raw Normal View History

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>
ModalMessageBox::ModalMessageBox(QWidget* parent, Qt::WindowModality modality)
: QMessageBox(parent != nullptr ? parent->window() : nullptr)
2019-03-04 12:48:40 -07:00
{
setWindowModality(modality);
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.
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,
ModalMessageBox::StandardButton default_button,
Qt::WindowModality modality)
2019-03-04 12:48:40 -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,
StandardButtons buttons, StandardButton default_button,
Qt::WindowModality modality)
2019-03-04 12:48:40 -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,
StandardButtons buttons, StandardButton default_button,
Qt::WindowModality modality)
2019-03-04 12:48:40 -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,
StandardButtons buttons, StandardButton default_button,
Qt::WindowModality modality)
2019-03-04 12:48:40 -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,
StandardButtons buttons, StandardButton default_button,
Qt::WindowModality modality)
2019-03-04 12:48:40 -07:00
{
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button,
modality);
2019-03-04 12:48:40 -07:00
}