Author: cazfi Date: Wed Apr 29 19:46:01 2015 New Revision: 28947 URL: http://svn.gna.org/viewcvs/freeciv?rev=28947&view=rev Log: Ask user to confirm quitting of ruledit.
See patch #6043 Modified: trunk/tools/ruledit/ruledit_qt.cpp trunk/tools/ruledit/ruledit_qt.h Modified: trunk/tools/ruledit/ruledit_qt.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.cpp?rev=28947&r1=28946&r2=28947&view=diff ============================================================================== --- trunk/tools/ruledit/ruledit_qt.cpp (original) +++ trunk/tools/ruledit/ruledit_qt.cpp Wed Apr 29 19:46:01 2015 @@ -17,9 +17,11 @@ // Qt #include <QApplication> +#include <QCloseEvent> #include <QLabel> #include <QLineEdit> #include <QMainWindow> +#include <QMessageBox> #include <QPushButton> #include <QStackedLayout> #include <QVBoxLayout> @@ -55,14 +57,14 @@ **************************************************************************/ bool ruledit_qt_setup(int argc, char **argv) { - QMainWindow *main_window; + ruledit_main *main_window; QWidget *central; const QString title = QString::fromUtf8(R__("Freeciv Ruleset Editor")); qapp = new QApplication(argc, argv); - main_window = new QMainWindow; + central = new QWidget; + main_window = new ruledit_main(qapp, central); main_window->setWindowTitle(title); - central = new QWidget; gui = new ruledit_gui; gui->setup(central); @@ -252,3 +254,49 @@ { nation->flush_widgets(); } + +/************************************************************************** + Main window constructor +**************************************************************************/ +ruledit_main::ruledit_main(QApplication *qapp_in, QWidget *central_in) : QMainWindow() +{ + qapp = qapp_in; + central = central_in; +} + +/************************************************************************** + Open dialog to confirm that user wants to quit ruledit. +**************************************************************************/ +void ruledit_main::popup_quit_dialog() +{ + QMessageBox ask(central); + int ret; + + ask.setText(R__("Are you sure you want to quit?")); + ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok); + ask.setDefaultButton(QMessageBox::Cancel); + ask.setIcon(QMessageBox::Warning); + ask.setWindowTitle(R__("Quit?")); + ret = ask.exec(); + + switch (ret) { + case QMessageBox::Cancel: + return; + break; + case QMessageBox::Ok: + qapp->quit(); + break; + } +} + +/************************************************************************** + User clicked windows close button. +**************************************************************************/ +void ruledit_main::closeEvent(QCloseEvent *event) +{ + // Handle quit via confirmation dialog. + popup_quit_dialog(); + + // Do not handle quit here, but let user to answer to confirmation dialog. + event->ignore(); +} Modified: trunk/tools/ruledit/ruledit_qt.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.h?rev=28947&r1=28946&r2=28947&view=diff ============================================================================== --- trunk/tools/ruledit/ruledit_qt.h (original) +++ trunk/tools/ruledit/ruledit_qt.h Wed Apr 29 19:46:01 2015 @@ -16,6 +16,7 @@ // Qt #include <QApplication> +#include <QMainWindow> #include <QObject> #include <QLabel> #include <QTabWidget> @@ -32,6 +33,22 @@ class tab_tech; class tab_unit; class tab_nation; + +class ruledit_main : public QMainWindow +{ + Q_OBJECT + +public: + ruledit_main(QApplication *qapp_in, QWidget *central_in); + +private: + void popup_quit_dialog(); + QApplication *qapp; + QWidget *central; + +protected: + void closeEvent(QCloseEvent *event); +}; class ruledit_gui : public QObject { _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits