From d588491823d1c02f2e4d479993476a6a3628eeed Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sat, 28 Mar 2020 22:44:21 -0400 Subject: [PATCH] Fixed issue with self destruct confirmation box and default behavior --- SelfDestructMessageBox.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/SelfDestructMessageBox.cpp b/SelfDestructMessageBox.cpp index 05d519e..89842f4 100644 --- a/SelfDestructMessageBox.cpp +++ b/SelfDestructMessageBox.cpp @@ -15,11 +15,10 @@ SelfDestructMessageBox::SelfDestructMessageBox( m_text(text), m_show_countdown(show_countdown) { + setDefaultButton(defaultButton); + connect(&m_timer, &QTimer::timeout, this, &SelfDestructMessageBox::tick); m_timer.setInterval(1000); - - setDefaultButton(defaultButton); - connect(this->defaultButton(), &QPushButton::clicked, this, &SelfDestructMessageBox::accept); } void SelfDestructMessageBox::showEvent(QShowEvent* event) @@ -35,10 +34,30 @@ void SelfDestructMessageBox::tick(){ if(m_timeout){ if(m_show_countdown){ setText(m_text.arg(m_timeout)); + } else { + + // if we don't show the countdown in the text, show it on the default button + auto d = defaultButton(); + if(d){ + auto text = d->text(); + if(text.contains(" (")){ + text = text.split(" (").first(); + } + + text = text.append(QString(" (%1) ").arg(m_timeout)); + d->setText(text); + } + } return; } + // stop the timer m_timer.stop(); - accept(); + + // click the default + auto d = defaultButton(); + if(d){ + d->click(); + } }