QtUtils: Add ModalMessageBox

This commit is contained in:
spycrab 2019-03-04 20:48:40 +01:00
parent a59010fa29
commit d1cb79f644
4 changed files with 82 additions and 1 deletions

View File

@ -104,6 +104,7 @@ add_executable(dolphin-emu
QtUtils/DoubleClickEventFilter.cpp
QtUtils/ElidedButton.cpp
QtUtils/FlowLayout.cpp
QtUtils/ModalMessageBox.cpp
QtUtils/ImageConverter.cpp
QtUtils/SignalDaemon.cpp
QtUtils/WindowActivationEventFilter.cpp

View File

@ -154,6 +154,7 @@
<QtMoc Include="QtUtils\DoubleClickEventFilter.h" />
<QtMoc Include="QtUtils\ElidedButton.h" />
<QtMoc Include="QtUtils\FlowLayout.h" />
<QtMoc Include="QtUtils\ModalMessageBox.h" />
<QtMoc Include="QtUtils\WindowActivationEventFilter.h" />
<QtMoc Include="QtUtils\WrapInScrollArea.h" />
<QtMoc Include="RenderWidget.h" />
@ -245,6 +246,7 @@
<ClCompile Include="$(QtMocOutPrefix)MemoryViewWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)MemoryWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)MenuBar.cpp" />
<ClCompile Include="$(QtMocOutPrefix)ModalMessageBox.cpp" />
<ClCompile Include="$(QtMocOutPrefix)NetPlayDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)NetPlaySetupDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)NewBreakpointDialog.cpp" />
@ -371,6 +373,7 @@
<ClCompile Include="QtUtils\ElidedButton.cpp" />
<ClCompile Include="QtUtils\FlowLayout.cpp" />
<ClCompile Include="QtUtils\ImageConverter.cpp" />
<ClCompile Include="QtUtils\ModalMessageBox.cpp" />
<ClCompile Include="QtUtils\WindowActivationEventFilter.cpp" />
<ClCompile Include="QtUtils\WrapInScrollArea.cpp" />
<ClCompile Include="RenderWidget.cpp" />
@ -491,4 +494,4 @@
<Message Text="Copy: @(BinaryFiles) -&gt; $(BinaryOutputDir)" Importance="High" />
<Copy SourceFiles="@(BinaryFiles)" DestinationFolder="$(BinaryOutputDir)" />
</Target>
</Project>
</Project>

View File

@ -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);
}

View File

@ -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);
};