Author: mir3x
Date: Sun Dec 20 20:04:39 2015
New Revision: 31119

URL: http://svn.gna.org/viewcvs/freeciv?rev=31119&view=rev
Log:
Disband message box has been made non-modal.

See bug #24188


Modified:
    trunk/client/gui-qt/citydlg.cpp
    trunk/client/gui-qt/dialogs.cpp
    trunk/client/gui-qt/dialogs.h

Modified: trunk/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.cpp?rev=31119&r1=31118&r2=31119&view=diff
==============================================================================
--- trunk/client/gui-qt/citydlg.cpp     (original)
+++ trunk/client/gui-qt/citydlg.cpp     Sun Dec 20 20:04:39 2015
@@ -243,26 +243,17 @@
 ****************************************************************************/
 void unit_item::disband()
 {
-  QMessageBox ask(gui()->central_wdg);
-  int ret;
-
-  ask.setText(_("Are you sure you want to disband that unit?"));
-  ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
-  ask.setDefaultButton(QMessageBox::Cancel);
-  ask.setIcon(QMessageBox::Critical);
-  ask.setWindowTitle(_("Disband unit"));
-  ret = ask.exec();
-
-  switch (ret) {
-  case QMessageBox::Cancel:
-    return;
-    break;
-  case QMessageBox::Ok:
-    if (unit_can_do_action(qunit, ACTION_DISBAND_UNIT) && qunit) {
-      request_unit_disband(qunit);
-      break;
-    }
-  }
+  struct unit_list *punits;
+  struct unit *punit = player_unit_by_number(client_player(), qunit->id);
+
+  if (punit == nullptr) {
+    return;
+  }
+
+  punits = unit_list_new();
+  unit_list_append(punits, punit);
+  popup_disband_dialog(punits);
+  unit_list_destroy(punits);
 }
 
 /****************************************************************************

Modified: trunk/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=31119&r1=31118&r2=31119&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.cpp     (original)
+++ trunk/client/gui-qt/dialogs.cpp     Sun Dec 20 20:04:39 2015
@@ -2200,40 +2200,61 @@
   cd->show_me();
 }
 
+/***************************************************************************
+  Disband Message box contructor
+***************************************************************************/
+disband_box::disband_box(struct unit_list *punits,
+                         QWidget *parent) : QMessageBox(parent)
+{
+  QString str;
+  QPushButton *pb;
+
+  setAttribute(Qt::WA_DeleteOnClose);
+  setModal(false);
+  cpunits = unit_list_new();
+  unit_list_iterate(punits, punit) {
+    unit_list_append(cpunits, punit);
+  } unit_list_iterate_end;
+
+  str = QString(PL_("Are you sure you want to disband that %1 unit?",
+                  "Are you sure you want to disband those %1 units?",
+                  unit_list_size(punits))).arg(unit_list_size(punits));
+  setText(str);
+  pb = addButton(_("Yes"), QMessageBox::AcceptRole);
+  addButton(_("No"), QMessageBox::RejectRole);
+  setDefaultButton(QMessageBox::Cancel);
+  setIcon(QMessageBox::Question);
+  setWindowTitle(_("Disband units"));
+  connect(pb, SIGNAL(clicked()), this, SLOT(disband_clicked()));
+}
+
+/***************************************************************************
+  Clicked Yes in disband box
+***************************************************************************/
+void disband_box::disband_clicked()
+{
+  unit_list_iterate(cpunits, punit) {
+    if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
+      request_unit_disband(punit);
+    }
+  } unit_list_iterate_end;
+}
+
+/***************************************************************************
+  Destructor for disband box
+***************************************************************************/
+disband_box::~disband_box()
+{
+  unit_list_destroy(cpunits);
+}
+
 /****************************************************************************
   Pops up a dialog to confirm disband of the unit(s).
 ****************************************************************************/
 void popup_disband_dialog(struct unit_list *punits)
 {
-  QMessageBox ask(gui()->central_wdg);
-  int ret;
-  QString str;
-
-  if (!punits || unit_list_size(punits) == 0) {
-    return;
-  }
-  str = QString(PL_("Are you sure you want to disband that %1 unit?",
-                  "Are you sure you want to disband those %1 units?",
-                  unit_list_size(punits))).arg(unit_list_size(punits));
-  ask.setText(str);
-  ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
-  ask.setDefaultButton(QMessageBox::Cancel);
-  ask.setIcon(QMessageBox::Question);
-  ask.setWindowTitle(_("Disband units"));
-  ret = ask.exec();
-
-  switch (ret) {
-  case QMessageBox::Cancel:
-    return;
-    break;
-  case QMessageBox::Ok:
-    unit_list_iterate(punits, punit) {
-      if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
-        request_unit_disband(punit);
-      }
-    } unit_list_iterate_end;
-    break;
-  }
+  disband_box *ask = new disband_box(punits, gui()->central_wdg);
+  ask->show();
 }
 
 /**************************************************************************

Modified: trunk/client/gui-qt/dialogs.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.h?rev=31119&r1=31118&r2=31119&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.h       (original)
+++ trunk/client/gui-qt/dialogs.h       Sun Dec 20 20:04:39 2015
@@ -44,6 +44,20 @@
 typedef void (*pfcn_void)(QVariant, QVariant);
 void update_nationset_combo();
 void popup_races_dialog(struct player *pplayer);
+
+/***************************************************************************
+  Nonmodal message box for disbanding units
+***************************************************************************/
+class disband_box : public QMessageBox
+{
+  Q_OBJECT
+  struct unit_list *cpunits;
+public:
+  explicit disband_box(struct unit_list *punits, QWidget *parent = 0);
+  ~disband_box();
+private slots:
+  void disband_clicked();
+};
 
 /***************************************************************************
  Dialog for goto popup


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to