aboutsummaryrefslogtreecommitdiff
path: root/src/debug_functions.cpp
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2021-12-25 20:40:39 -0600
committeroldmud0 <oldmud0@users.noreply.github.com>2021-12-25 20:40:39 -0600
commitdcff063f19fbcfa698a8f703fabaa92c2c7fc428 (patch)
treea24966d53cd4feb800a548ca9d8b66bc7d8c4bd6 /src/debug_functions.cpp
parentd1fb7fde16ec37dfa7b13e0a02489417655d315d (diff)
Don't hide "OK" on message timer, just disable it
Diffstat (limited to 'src/debug_functions.cpp')
-rw-r--r--src/debug_functions.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/debug_functions.cpp b/src/debug_functions.cpp
index 456aee8a..f4f7b3a7 100644
--- a/src/debug_functions.cpp
+++ b/src/debug_functions.cpp
@@ -1,7 +1,10 @@
#include <QCoreApplication>
+#include <QDialogButtonBox>
#include <QElapsedTimer>
#include <QMessageBox>
+#include <QPushButton>
#include <QTimer>
+
#include <functional>
#include "debug_functions.h"
@@ -22,16 +25,38 @@ void call_error(QString p_message)
void call_notice(QString p_message)
{
- QMessageBox *msgBox = new QMessageBox;
+ auto *msgBox = new QMessageBox;
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText(p_message);
msgBox->setWindowTitle(
QCoreApplication::translate("debug_functions", "Notice"));
- msgBox->setStandardButtons(QMessageBox::NoButton);
-
- QTimer::singleShot(3000, msgBox, std::bind(&QMessageBox::setStandardButtons,msgBox,QMessageBox::Ok));
+ msgBox->setStandardButtons(QMessageBox::Ok);
+ msgBox->setDefaultButton(QMessageBox::Ok);
+ msgBox->defaultButton()->setEnabled(false);
+
+ QTimer intervalTimer;
+ intervalTimer.setInterval(1000);
+
+ int counter = 3;
+ const auto updateCounter = [msgBox, &counter] {
+ if (counter <= 0)
+ return;
+ msgBox->defaultButton()->setText(
+ QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter));
+ counter--;
+ };
+
+ QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter);
+ intervalTimer.start();
+ updateCounter();
+
+ QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] {
+ msgBox->defaultButton()->setEnabled(true);
+ msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK"));
+ intervalTimer.stop();
+ });
msgBox->exec();