Skip to content

Commit 8775ca0

Browse files
committed
Qt: Convert more message boxes to window modal
1 parent db7598f commit 8775ca0

File tree

4 files changed

+72
-87
lines changed

4 files changed

+72
-87
lines changed

src/duckstation-qt/consolesettingswidget.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ void ConsoleSettingsWidget::onEnableCPUClockSpeedControlChecked(int state)
190190
"system requirements.\n\nBy enabling this option you are agreeing to not create any bug reports unless you "
191191
"have confirmed the bug also occurs with overclocking disabled.\n\nThis warning will only be shown once.");
192192

193-
QMessageBox* mb =
194-
new QMessageBox(QMessageBox::Warning, tr("CPU Overclocking Warning"), message, QMessageBox::NoButton, this);
193+
QMessageBox* const mb = QtUtils::NewMessageBox(QMessageBox::Warning, tr("CPU Overclocking Warning"), message,
194+
QMessageBox::NoButton, QMessageBox::NoButton, Qt::WindowModal, this);
195195
mb->setAttribute(Qt::WA_DeleteOnClose, true);
196-
mb->setWindowModality(Qt::WindowModal);
197196
const QPushButton* const yes_button =
198197
mb->addButton(tr("Yes, I will confirm bugs without overclocking before reporting."), QMessageBox::YesRole);
199198
const QPushButton* const no_button = mb->addButton(tr("No, take me back to safety."), QMessageBox::NoRole);

src/duckstation-qt/gamecheatsettingswidget.cpp

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -395,58 +395,42 @@ void GameCheatSettingsWidget::checkForMasterDisable()
395395

396396
if (!game_settings_enabled)
397397
{
398-
QMessageBox mbox(this);
399-
mbox.setIcon(QMessageBox::Warning);
400-
mbox.setWindowTitle(tr("Confirm Game Settings Enable"));
401-
mbox.setWindowIcon(QtHost::GetAppIcon());
402-
mbox.setTextFormat(Qt::RichText);
403-
mbox.setText(
398+
QMessageBox* mbox = QtUtils::NewMessageBox(
399+
QMessageBox::Warning, tr("Confirm Game Settings Enable"),
404400
tr("<h3>Game settings are currently disabled.</h3><p>This is <strong>not</strong> the default. Enabling this "
405-
"cheat will not have any effect until game settings are enabled. Do you want to do this now?"));
406-
407-
mbox.addButton(QMessageBox::Yes);
408-
mbox.addButton(QMessageBox::No);
409-
410-
QCheckBox* cb = new QCheckBox(&mbox);
401+
"cheat will not have any effect until game settings are enabled. Do you want to do this now?"),
402+
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton, Qt::WindowModal, this);
403+
QCheckBox* cb = new QCheckBox(mbox);
404+
cb->setAttribute(Qt::WA_DeleteOnClose, true);
411405
cb->setText(tr("Do not show again"));
412-
mbox.setCheckBox(cb);
406+
mbox->setCheckBox(cb);
413407

414-
const int res = mbox.exec();
415-
if (res == QMessageBox::No)
416-
{
417-
m_master_enable_ignored = cb->isChecked();
418-
}
419-
else
420-
{
408+
connect(mbox, &QMessageBox::accepted, this, []() {
421409
Host::SetBaseBoolSettingValue("Main", "ApplyGameSettings", true);
422410
Host::CommitBaseSettingChanges();
423411
g_emu_thread->applySettings(false);
424-
}
412+
});
413+
414+
mbox->show();
425415
}
426416

427417
if (!cheats_enabled)
428418
{
429-
QMessageBox mbox(this);
430-
mbox.setIcon(QMessageBox::Warning);
431-
mbox.setWindowTitle(tr("Confirm Cheat Enable"));
432-
mbox.setWindowIcon(QtHost::GetAppIcon());
433-
mbox.setTextFormat(Qt::RichText);
434-
mbox.setText(tr("<h3>Cheats are not currently enabled for this game.</h3><p>Enabling this cheat will not have any "
435-
"effect until cheats are enabled for this game. Do you want to do this now?"));
436-
437-
mbox.addButton(QMessageBox::Yes);
438-
mbox.addButton(QMessageBox::No);
439-
440-
QCheckBox* cb = new QCheckBox(&mbox);
419+
QMessageBox* mbox = QtUtils::NewMessageBox(
420+
QMessageBox::Warning, tr("Confirm Cheat Enable"),
421+
tr("<h3>Cheats are not currently enabled for this game.</h3><p>Enabling this cheat will not have any "
422+
"effect until cheats are enabled for this game. Do you want to do this now?"),
423+
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton, Qt::WindowModal, this);
424+
QCheckBox* cb = new QCheckBox(mbox);
425+
cb->setAttribute(Qt::WA_DeleteOnClose, true);
441426
cb->setText(tr("Do not show again"));
442427
cb->setChecked(m_master_enable_ignored);
443-
mbox.setCheckBox(cb);
428+
mbox->setCheckBox(cb);
429+
430+
connect(mbox, &QMessageBox::accepted, this, [this]() { m_ui.enableCheats->setChecked(true); });
431+
connect(mbox, &QMessageBox::rejected, this, [this, cb]() { m_master_enable_ignored = cb->isChecked(); });
444432

445-
const int res = mbox.exec();
446-
if (res == QMessageBox::No)
447-
m_master_enable_ignored = cb->isChecked();
448-
else
449-
m_ui.enableCheats->setChecked(true);
433+
mbox->show();
450434
}
451435
}
452436

src/duckstation-qt/mainwindow.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,29 +1273,36 @@ void MainWindow::startFileOrChangeDisc(const QString& qpath)
12731273

12741274
void MainWindow::promptForDiscChange(const QString& path)
12751275
{
1276+
if (m_was_disc_change_request || System::IsGPUDumpPath(path.toStdString()))
1277+
{
1278+
switchToEmulationView();
1279+
g_emu_thread->changeDisc(path, false, true);
1280+
}
1281+
12761282
SystemLock lock(pauseAndLockSystem());
12771283

1278-
bool reset_system = false;
1279-
if (!m_was_disc_change_request && !System::IsGPUDumpPath(path.toStdString()))
1280-
{
1281-
QMessageBox mb(QMessageBox::Question, tr("Confirm Disc Change"),
1282-
tr("Do you want to swap discs or boot the new image (via system reset)?"), QMessageBox::NoButton,
1283-
this);
1284-
/*const QAbstractButton* const swap_button = */ mb.addButton(tr("Swap Disc"), QMessageBox::YesRole);
1285-
const QAbstractButton* const reset_button = mb.addButton(tr("Reset"), QMessageBox::NoRole);
1286-
const QAbstractButton* const cancel_button = mb.addButton(tr("Cancel"), QMessageBox::RejectRole);
1287-
mb.exec();
1284+
QMessageBox* const mb =
1285+
QtUtils::NewMessageBox(QMessageBox::Question, tr("Confirm Disc Change"),
1286+
tr("Do you want to swap discs or boot the new image (via system reset)?"),
1287+
QMessageBox::NoButton, QMessageBox::NoButton, Qt::WindowModal, lock.getDialogParent());
1288+
mb->setAttribute(Qt::WA_DeleteOnClose, true);
12881289

1289-
const QAbstractButton* const clicked_button = mb.clickedButton();
1290+
/*const QAbstractButton* const swap_button = */ mb->addButton(tr("Swap Disc"), QMessageBox::YesRole);
1291+
const QAbstractButton* const reset_button = mb->addButton(tr("Reset"), QMessageBox::NoRole);
1292+
const QAbstractButton* const cancel_button = mb->addButton(tr("Cancel"), QMessageBox::RejectRole);
1293+
1294+
connect(mb, &QMessageBox::finished, this, [this, mb, reset_button, cancel_button, path, lock = std::move(lock)]() {
1295+
const QAbstractButton* const clicked_button = mb->clickedButton();
12901296
if (!clicked_button || clicked_button == cancel_button)
12911297
return;
12921298

1293-
reset_system = (clicked_button == reset_button);
1294-
}
1299+
const bool reset_system = (clicked_button == reset_button);
1300+
switchToEmulationView();
12951301

1296-
switchToEmulationView();
1302+
g_emu_thread->changeDisc(path, reset_system, true);
1303+
});
12971304

1298-
g_emu_thread->changeDisc(path, reset_system, true);
1305+
mb->show();
12991306
}
13001307

13011308
void MainWindow::onStartDiscActionTriggered()
@@ -3038,20 +3045,15 @@ void MainWindow::requestShutdown(bool allow_confirm, bool allow_save_to_state, b
30383045

30393046
SystemLock lock(pauseAndLockSystem());
30403047

3041-
QMessageBox* msgbox = new QMessageBox(lock.getDialogParent());
3042-
msgbox->setWindowTitle(tr("Confirm Shutdown"));
3043-
msgbox->setWindowModality(Qt::WindowModal);
3048+
QMessageBox* msgbox = QtUtils::NewMessageBox(
3049+
QMessageBox::Question, tr("Confirm Shutdown"), tr("Are you sure you want to shut down the virtual machine?"),
3050+
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes, Qt::WindowModal, lock.getDialogParent());
30443051
msgbox->setAttribute(Qt::WA_DeleteOnClose, true);
3045-
msgbox->setIcon(QMessageBox::Question);
3046-
msgbox->setText(tr("Are you sure you want to shut down the virtual machine?"));
30473052

30483053
QCheckBox* const save_cb = new QCheckBox(tr("Save State For Resume"), msgbox);
30493054
save_cb->setChecked(allow_save_to_state && save_state);
30503055
save_cb->setEnabled(allow_save_to_state);
30513056
msgbox->setCheckBox(save_cb);
3052-
msgbox->addButton(QMessageBox::Yes);
3053-
msgbox->addButton(QMessageBox::No);
3054-
msgbox->setDefaultButton(QMessageBox::Yes);
30553057
connect(msgbox, &QMessageBox::finished, this,
30563058
[this, lock = std::move(lock), save_cb, allow_save_to_state, check_safety, check_pause, exit_fullscreen_ui,
30573059
quit_afterwards](int result) mutable {

src/duckstation-qt/qthost.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,28 +2165,28 @@ void Host::ConfirmMessageAsync(std::string_view title, std::string_view message,
21652165
no_text = QtUtils::StringViewToQString(no_text), needs_pause]() mutable {
21662166
auto lock = g_main_window->pauseAndLockSystem();
21672167

2168-
bool result;
2169-
{
2170-
QMessageBox msgbox(lock.getDialogParent());
2171-
msgbox.setIcon(QMessageBox::Question);
2172-
msgbox.setWindowTitle(title);
2173-
msgbox.setText(message);
2174-
2175-
QPushButton* const yes_button = msgbox.addButton(yes_text, QMessageBox::AcceptRole);
2176-
msgbox.addButton(no_text, QMessageBox::RejectRole);
2177-
msgbox.exec();
2178-
result = (msgbox.clickedButton() == yes_button);
2179-
}
2180-
2181-
callback(result);
2182-
2183-
if (needs_pause)
2184-
{
2185-
Host::RunOnCPUThread([]() {
2186-
if (System::IsValid())
2187-
System::PauseSystem(false);
2188-
});
2189-
}
2168+
QMessageBox* const msgbox =
2169+
QtUtils::NewMessageBox(QMessageBox::Question, title, message, QMessageBox::NoButton, QMessageBox::NoButton,
2170+
Qt::WindowModal, lock.getDialogParent());
2171+
msgbox->setAttribute(Qt::WA_DeleteOnClose, true);
2172+
2173+
QPushButton* const yes_button = msgbox->addButton(yes_text, QMessageBox::AcceptRole);
2174+
msgbox->addButton(no_text, QMessageBox::RejectRole);
2175+
2176+
QObject::connect(msgbox, &QMessageBox::finished, lock.getDialogParent(),
2177+
[msgbox, yes_button, callback = std::move(callback), needs_pause]() {
2178+
const bool result = (msgbox->clickedButton() == yes_button);
2179+
callback(result);
2180+
2181+
if (needs_pause)
2182+
{
2183+
Host::RunOnCPUThread([]() {
2184+
if (System::IsValid())
2185+
System::PauseSystem(false);
2186+
});
2187+
}
2188+
});
2189+
msgbox->exec();
21902190
});
21912191
}
21922192
}

0 commit comments

Comments
 (0)