Allow user to select whether to confirm exit or not

audioplugins
Phil Taylor 2021-07-11 17:30:02 +01:00
rodzic 29ef8d482d
commit 99b1e7f407
2 zmienionych plików z 32 dodań i 5 usunięć

Wyświetl plik

@ -108,11 +108,33 @@ wfmain::~wfmain()
void wfmain::closeEvent(QCloseEvent *event) void wfmain::closeEvent(QCloseEvent *event)
{ {
// Are you sure? // Are you sure?
QMessageBox::StandardButton resBtn = QMessageBox::question( this, QString("Confirm close"), if (!prefs.confirmExit) {
tr("Are you sure you wish to exit?\n"), QApplication::exit();
QMessageBox::No | QMessageBox::Yes, }
QMessageBox::Yes); QCheckBox *cb = new QCheckBox("Don't ask me again");
if (resBtn == QMessageBox::Yes) { QMessageBox msgbox;
msgbox.setText("Are you sure you wish to exit?\n");
msgbox.setIcon(QMessageBox::Icon::Question);
QAbstractButton *yesButton = msgbox.addButton(QMessageBox::Yes);
msgbox.addButton(QMessageBox::No);
msgbox.setDefaultButton(QMessageBox::Yes);
msgbox.setCheckBox(cb);
QObject::connect(cb, &QCheckBox::stateChanged, [this](int state){
if (static_cast<Qt::CheckState>(state) == Qt::CheckState::Checked) {
prefs.confirmExit=false;
} else {
prefs.confirmExit=true;
}
settings->beginGroup("Interface");
settings->setValue("ConfirmExit", this->prefs.confirmExit);
settings->endGroup();
settings->sync();
});
msgbox.exec();
if (msgbox.clickedButton() == yesButton) {
QApplication::exit(); QApplication::exit();
} else { } else {
event->ignore(); event->ignore();
@ -1159,6 +1181,7 @@ void wfmain::setDefPrefs()
defPrefs.localAFgain = 255; defPrefs.localAFgain = 255;
defPrefs.wflength = 160; defPrefs.wflength = 160;
defPrefs.wftheme = static_cast<int>(QCPColorGradient::gpJet); defPrefs.wftheme = static_cast<int>(QCPColorGradient::gpJet);
defPrefs.confirmExit = true;
udpDefPrefs.ipAddress = QString(""); udpDefPrefs.ipAddress = QString("");
udpDefPrefs.controlLANPort = 50001; udpDefPrefs.controlLANPort = 50001;
@ -1189,6 +1212,8 @@ void wfmain::loadSettings()
restoreGeometry(settings->value("windowGeometry").toByteArray()); restoreGeometry(settings->value("windowGeometry").toByteArray());
restoreState(settings->value("windowState").toByteArray()); restoreState(settings->value("windowState").toByteArray());
setWindowState(Qt::WindowActive); // Works around QT bug to returns window+keyboard focus. setWindowState(Qt::WindowActive); // Works around QT bug to returns window+keyboard focus.
prefs.confirmExit = settings->value("ConfirmExit", defPrefs.confirmExit).toBool();
settings->endGroup(); settings->endGroup();
// Load color schemes: // Load color schemes:
@ -1478,6 +1503,7 @@ void wfmain::saveSettings()
settings->setValue("windowGeometry", saveGeometry()); settings->setValue("windowGeometry", saveGeometry());
settings->setValue("windowState", saveState()); settings->setValue("windowState", saveState());
settings->setValue("WFLength", prefs.wflength); settings->setValue("WFLength", prefs.wflength);
settings->setValue("ConfirmExit", prefs.confirmExit);
settings->endGroup(); settings->endGroup();
// Radio and Comms: C-IV addr, port to use // Radio and Comms: C-IV addr, port to use

Wyświetl plik

@ -671,6 +671,7 @@ private:
unsigned char localAFgain; unsigned char localAFgain;
unsigned int wflength; unsigned int wflength;
int wftheme; int wftheme;
bool confirmExit;
// plot scheme // plot scheme
} prefs; } prefs;