changeset 8:8a8735679d55

Re #243: Create "New Army" dialog in Qt# app * Disable "OK" button on army creation form * Add event hooks and methods to enable OK Button when all values are completed * Set properties on spinbox Still need to work out how to stop dialog showing up in task bar.
author IBBoard <dev@ibboard.co.uk>
date Sat, 30 Jan 2010 20:57:36 +0000
parents 09bc9a4df412
children 6bbc5c08c06d
files NewArmyDialog.cs qt-gui/CreateNewArmyLayout.cs qt-gui/CreateNewArmyLayout.ui
diffstat 3 files changed, 55 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/NewArmyDialog.cs	Sat Jan 30 20:02:32 2010 +0000
+++ b/NewArmyDialog.cs	Sat Jan 30 20:57:36 2010 +0000
@@ -27,6 +27,14 @@
 			PopulateControls();
 			layout.gameSystems.CurrentIndex = -1;
 			QObject.Connect(layout.gameSystems, SIGNAL("currentIndexChanged(int)"), GameSystemSelectionChanged);
+			QObject.Connect(layout.armyName, SIGNAL("textChanged(QString)"), ArmyNameChanged);
+			QObject.Connect(layout.armySize, SIGNAL("valueChanged(int)"), ArmySizeChanged);
+			SetOkayButtonState(false);
+		}
+		
+		private void SetOkayButtonState (bool boolValue)
+		{
+			layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue;
 		}
 		
 		private void PopulateControls()
@@ -41,6 +49,7 @@
 		
 		private void GameSystemSelectionChanged()
 		{
+			ValidateForm();
 			layout.raceList.Clear();
 			
 			if (layout.gameSystems.CurrentIndex != -1)
@@ -54,6 +63,15 @@
 			}				
 		}
 		
+		private void ValidateForm()
+		{
+			bool complete = (layout.gameSystems.CurrentIndex != -1);
+			complete &= (layout.raceList.CurrentRow != -1);
+			complete &= (layout.armyName.Text != "");
+			complete &= (layout.armySize.Value > 0);
+			SetOkayButtonState(complete);
+		}
+		
 		private GameSystem GetSelectedSystem()
 		{
 			GameSystem system = null;			
@@ -66,5 +84,15 @@
 			
 			return system;
 		}
+		
+		private void ArmyNameChanged()
+		{
+			ValidateForm();
+		}
+		
+		private void ArmySizeChanged()
+		{
+			ValidateForm();
+		}
 	}
 }
--- a/qt-gui/CreateNewArmyLayout.cs	Sat Jan 30 20:02:32 2010 +0000
+++ b/qt-gui/CreateNewArmyLayout.cs	Sat Jan 30 20:57:36 2010 +0000
@@ -1,7 +1,7 @@
 /********************************************************************************
 ** Form generated from reading ui file 'CreateNewArmyLayout.ui'
 **
-** Created: Wed Jan 27 20:53:01 2010
+** Created: Sat Jan 30 20:56:06 2010
 **      by: Qt User Interface Compiler for C# version 4.5.3
 **
 ** WARNING! All changes made in this file will be lost when recompiling ui file!
@@ -27,6 +27,7 @@
     {
     if (CreateNewArmyLayout.ObjectName == "")
         CreateNewArmyLayout.ObjectName = "CreateNewArmyLayout";
+    CreateNewArmyLayout.WindowModality = Qt.WindowModality.WindowModal;
     QSize Size = new QSize(400, 300);
     Size = Size.ExpandedTo(CreateNewArmyLayout.MinimumSizeHint());
     CreateNewArmyLayout.Size = Size;
@@ -70,6 +71,11 @@
 
     armySize = new QSpinBox(CreateNewArmyLayout);
     armySize.ObjectName = "armySize";
+    armySize.Frame = true;
+    armySize.buttonSymbols = QAbstractSpinBox.ButtonSymbols.UpDownArrows;
+    armySize.Maximum = 100000;
+    armySize.SingleStep = 10;
+    armySize.Value = 2000;
 
     gridLayout.AddWidget(armySize, 3, 2, 1, 1);
 
--- a/qt-gui/CreateNewArmyLayout.ui	Sat Jan 30 20:02:32 2010 +0000
+++ b/qt-gui/CreateNewArmyLayout.ui	Sat Jan 30 20:57:36 2010 +0000
@@ -2,6 +2,9 @@
 <ui version="4.0">
  <class>CreateNewArmyLayout</class>
  <widget class="QDialog" name="CreateNewArmyLayout">
+  <property name="windowModality">
+   <enum>Qt::WindowModal</enum>
+  </property>
   <property name="geometry">
    <rect>
     <x>0</x>
@@ -68,7 +71,23 @@
     </widget>
    </item>
    <item row="3" column="2">
-    <widget class="QSpinBox" name="armySize"/>
+    <widget class="QSpinBox" name="armySize">
+     <property name="frame">
+      <bool>true</bool>
+     </property>
+     <property name="buttonSymbols">
+      <enum>QAbstractSpinBox::UpDownArrows</enum>
+     </property>
+     <property name="maximum">
+      <number>100000</number>
+     </property>
+     <property name="singleStep">
+      <number>10</number>
+     </property>
+     <property name="value">
+      <number>2000</number>
+     </property>
+    </widget>
    </item>
    <item row="2" column="2">
     <widget class="QLineEdit" name="armyName"/>