-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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) : QMessageBox(parent) | ||
{ | ||
setWindowModality(Qt::WindowModal); | ||
|
||
// No parent is still preferable to showing a hidden parent here. | ||
if (parent != nullptr && !parent->isVisible()) | ||
setParent(nullptr); | ||
} | ||
|
||
static inline int ExecMessageBox(ModalMessageBox::Icon icon, QWidget* parent, const QString& title, | ||
const QString& text, ModalMessageBox::StandardButtons buttons, | ||
ModalMessageBox::StandardButton default_button) | ||
{ | ||
ModalMessageBox msg(parent); | ||
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) | ||
{ | ||
return ExecMessageBox(QMessageBox::Critical, parent, title, text, buttons, default_button); | ||
} | ||
|
||
int ModalMessageBox::information(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons, StandardButton default_button) | ||
{ | ||
return ExecMessageBox(QMessageBox::Information, parent, title, text, buttons, default_button); | ||
} | ||
|
||
int ModalMessageBox::question(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons, StandardButton default_button) | ||
{ | ||
return ExecMessageBox(QMessageBox::Critical, parent, title, text, buttons, default_button); | ||
} | ||
|
||
int ModalMessageBox::warning(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons, StandardButton default_button) | ||
{ | ||
return ExecMessageBox(QMessageBox::Warning, parent, title, text, buttons, default_button); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2019 Dolphin Emulator Project | ||
// Licensed under GPLv2+ | ||
// Refer to the license.txt file included. | ||
|
||
#pragma once | ||
|
||
#include <QMessageBox> | ||
|
||
// Helper for making message boxes modal by default | ||
class ModalMessageBox : public QMessageBox | ||
{ | ||
public: | ||
explicit ModalMessageBox(QWidget* parent); | ||
|
||
static int critical(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons = Ok, StandardButton default_button = NoButton); | ||
static int information(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons = Ok, StandardButton default_button = NoButton); | ||
static int question(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons = Yes | No, StandardButton default_button = NoButton); | ||
static int warning(QWidget* parent, const QString& title, const QString& text, | ||
StandardButtons buttons = Ok, StandardButton default_button = NoButton); | ||
}; |