diff --git a/src/qt_gui/kbm_config_dialog.cpp b/src/qt_gui/kbm_config_dialog.cpp index 6931c336c..bb3b3ac16 100644 --- a/src/qt_gui/kbm_config_dialog.cpp +++ b/src/qt_gui/kbm_config_dialog.cpp @@ -21,6 +21,8 @@ #include QString previous_game = "default"; +bool isHelpOpen = false; +HelpDialog* helpDialog; EditorDialog::EditorDialog(QWidget* parent) : QDialog(parent) { @@ -107,6 +109,11 @@ void EditorDialog::saveFile(QString game) { // Override the close event to show the save confirmation dialog only if changes were made void EditorDialog::closeEvent(QCloseEvent* event) { + if (isHelpOpen) { + helpDialog->close(); + isHelpOpen = false; + // at this point I might have to add this flag and the help dialog to the class itself + } if (hasUnsavedChanges()) { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Save Changes", "Do you want to save changes?", @@ -126,6 +133,10 @@ void EditorDialog::closeEvent(QCloseEvent* event) { } void EditorDialog::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { + if (isHelpOpen) { + helpDialog->close(); + isHelpOpen = false; + } close(); // Trigger the close action, same as pressing the close button } else { QDialog::keyPressEvent(event); // Call the base class implementation for other keys @@ -133,15 +144,22 @@ void EditorDialog::keyPressEvent(QKeyEvent* event) { } void EditorDialog::onSaveClicked() { + if (isHelpOpen) { + helpDialog->close(); + isHelpOpen = false; + } saveFile(gameComboBox->currentText()); reject(); // Close the dialog } void EditorDialog::onCancelClicked() { + if (isHelpOpen) { + helpDialog->close(); + isHelpOpen = false; + } reject(); // Close the dialog } -bool isHelpOpen = false; -HelpDialog* helpDialog; + void EditorDialog::onHelpClicked() { if (!isHelpOpen) { helpDialog = new HelpDialog(&isHelpOpen, this); diff --git a/src/qt_gui/kbm_help_dialog.cpp b/src/qt_gui/kbm_help_dialog.cpp index 6b27b5e9c..3381f9c62 100644 --- a/src/qt_gui/kbm_help_dialog.cpp +++ b/src/qt_gui/kbm_help_dialog.cpp @@ -62,6 +62,10 @@ void HelpDialog::closeEvent(QCloseEvent* event) { *help_open_ptr = false; close(); } +void HelpDialog::reject() { + *help_open_ptr = false; + close(); +} HelpDialog::HelpDialog(bool* open_flag, QWidget* parent) : QDialog(parent) { help_open_ptr = open_flag; diff --git a/src/qt_gui/kbm_help_dialog.h b/src/qt_gui/kbm_help_dialog.h index 4348f9a33..c2d6d22a6 100644 --- a/src/qt_gui/kbm_help_dialog.h +++ b/src/qt_gui/kbm_help_dialog.h @@ -37,6 +37,7 @@ public: protected: void closeEvent(QCloseEvent* event) override; + void reject() override; private: bool* help_open_ptr;