js8call/JS8_Main/SelfDestructMessageBox.cpp
Chris-AC9KH 356bdc0f50 Code cleanup - move loose source and header files in source tree to group folders
Rename all header files with .h extension
Fix function declaration in HamlibTransceiver.h that overrode member function but was not marked override
Remove unused variable in Modulator.cpp
Remove unused files from source tree
Remove duplicate LazyFillComboBox files
Reformat codebase to LLVM C++ standard
2026-01-02 16:46:38 -06:00

59 lines
1.7 KiB
C++

#include "SelfDestructMessageBox.h"
SelfDestructMessageBox::SelfDestructMessageBox(
int timeout, const QString &title, const QString &text,
QMessageBox::Icon icon, QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton, bool show_countdown,
QWidget *parent, Qt::WindowFlags flags)
: QMessageBox(icon, title, text, buttons, parent, flags),
m_show_countdown(show_countdown), m_timeout(timeout), m_text(text) {
setDefaultButton(defaultButton);
connect(&m_timer, &QTimer::timeout, this, &SelfDestructMessageBox::tick);
m_timer.setInterval(1000);
connect(this, &SelfDestructMessageBox::finished, this,
&SelfDestructMessageBox::stopTimer);
}
void SelfDestructMessageBox::showEvent(QShowEvent *event) {
tick();
m_timer.start();
QMessageBox::showEvent(event);
}
void SelfDestructMessageBox::stopTimer() { m_timer.stop(); }
void SelfDestructMessageBox::tick() {
m_timeout--;
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();
// click the default
auto d = defaultButton();
if (d) {
d->click();
}
}