changeset 6:bbf40d66dfe4

Re #242: Create Qt# UI for WarFoundry * Fix warnings about Connect strings not being signals Re #243: Create new Qt# "Create Army" dialog * Change from List View to List Widget (views need models, which only handle QVariants and not arbitrary objects) * Populate Game System list * Populate races list on game system selection changed * Set text on some labels
author IBBoard <dev@ibboard.co.uk>
date Wed, 27 Jan 2010 20:58:56 +0000
parents 1bd8febee385
children 09bc9a4df412
files MainWindow.cs NewArmyDialog.cs qt-gui/CreateNewArmyLayout.cs qt-gui/CreateNewArmyLayout.ui
diffstat 4 files changed, 64 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/MainWindow.cs	Mon Jan 25 20:54:33 2010 +0000
     1.2 +++ b/MainWindow.cs	Wed Jan 27 20:58:56 2010 +0000
     1.3 @@ -38,7 +38,7 @@
     1.4  		
     1.5  		private void ConnectMenuActions()
     1.6  		{
     1.7 -			QObject.Connect(layout.actionCreateArmy, "triggered()", CreateNewArmy);
     1.8 +			QObject.Connect(layout.actionCreateArmy, SIGNAL("triggered()"), CreateNewArmy);
     1.9  		}
    1.10  		
    1.11  		private void CreateNewArmy()
     2.1 --- a/NewArmyDialog.cs	Mon Jan 25 20:54:33 2010 +0000
     2.2 +++ b/NewArmyDialog.cs	Wed Jan 27 20:58:56 2010 +0000
     2.3 @@ -3,7 +3,10 @@
     2.4  // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     2.5  
     2.6  using System;
     2.7 +using System.Collections.Generic;
     2.8  using Qyoto;
     2.9 +using IBBoard.WarFoundry.API;
    2.10 +using IBBoard.WarFoundry.API.Objects;
    2.11  
    2.12  namespace IBBoard.WarFoundry.GUI.QtSharp
    2.13  {
    2.14 @@ -11,11 +14,57 @@
    2.15  	{
    2.16  		private Ui_CreateNewArmyLayout layout;
    2.17  		
    2.18 +		//TODO: Replace local cached arrays with some kind of storing as user data on controls, if possible
    2.19 +		//Qt doesn't seem to support it by default, but there should be a better alternative
    2.20 +		private GameSystem[] gameSystems;
    2.21 +		private Race[] races;
    2.22 +		
    2.23  		public NewArmyDialog ()
    2.24  		{
    2.25  			layout = new Ui_CreateNewArmyLayout();
    2.26  			layout.SetupUi(this);
    2.27  			
    2.28 +			PopulateControls();
    2.29 +			layout.gameSystems.CurrentIndex = -1;
    2.30 +			QObject.Connect(layout.gameSystems, SIGNAL("currentIndexChanged(int)"), GameSystemSelectionChanged);
    2.31 +		}
    2.32 +		
    2.33 +		private void PopulateControls()
    2.34 +		{
    2.35 +			gameSystems = WarFoundryLoader.GetDefault().GetGameSystems();
    2.36 +			
    2.37 +			foreach (GameSystem system in gameSystems)
    2.38 +			{
    2.39 +				layout.gameSystems.AddItem(system.Name);
    2.40 +			}
    2.41 +		}
    2.42 +		
    2.43 +		private void GameSystemSelectionChanged()
    2.44 +		{
    2.45 +			layout.raceList.Clear();
    2.46 +			
    2.47 +			if (layout.gameSystems.CurrentIndex != -1)
    2.48 +			{
    2.49 +				races = WarFoundryLoader.GetDefault().GetRaces(GetSelectedSystem());
    2.50 +				
    2.51 +				foreach (Race race in races)
    2.52 +				{
    2.53 +					layout.raceList.AddItem(race.Name);
    2.54 +				}
    2.55 +			}				
    2.56 +		}
    2.57 +		
    2.58 +		private GameSystem GetSelectedSystem()
    2.59 +		{
    2.60 +			GameSystem system = null;			
    2.61 +			int selectedIndex = layout.gameSystems.CurrentIndex;
    2.62 +			
    2.63 +			if (selectedIndex != -1)
    2.64 +			{
    2.65 +				system = gameSystems[selectedIndex];
    2.66 +			}
    2.67 +			
    2.68 +			return system;
    2.69  		}
    2.70  	}
    2.71  }
     3.1 --- a/qt-gui/CreateNewArmyLayout.cs	Mon Jan 25 20:54:33 2010 +0000
     3.2 +++ b/qt-gui/CreateNewArmyLayout.cs	Wed Jan 27 20:58:56 2010 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4  /********************************************************************************
     3.5  ** Form generated from reading ui file 'CreateNewArmyLayout.ui'
     3.6  **
     3.7 -** Created: Sat Jan 23 20:40:44 2010
     3.8 +** Created: Wed Jan 27 20:53:01 2010
     3.9  **      by: Qt User Interface Compiler for C# version 4.5.3
    3.10  **
    3.11  ** WARNING! All changes made in this file will be lost when recompiling ui file!
    3.12 @@ -17,11 +17,11 @@
    3.13      public QComboBox gameSystems;
    3.14      public QLabel lblGameSystem;
    3.15      public QLabel lblRace;
    3.16 -    public QListView raceList;
    3.17      public QLabel lblArmyName;
    3.18      public QLabel lblArmySize;
    3.19      public QSpinBox armySize;
    3.20      public QLineEdit armyName;
    3.21 +    public QListWidget raceList;
    3.22  
    3.23      public void SetupUi(QDialog CreateNewArmyLayout)
    3.24      {
    3.25 @@ -56,11 +56,6 @@
    3.26  
    3.27      gridLayout.AddWidget(lblRace, 1, 0, 1, 1);
    3.28  
    3.29 -    raceList = new QListView(CreateNewArmyLayout);
    3.30 -    raceList.ObjectName = "raceList";
    3.31 -
    3.32 -    gridLayout.AddWidget(raceList, 1, 2, 1, 1);
    3.33 -
    3.34      lblArmyName = new QLabel(CreateNewArmyLayout);
    3.35      lblArmyName.ObjectName = "lblArmyName";
    3.36      lblArmyName.Alignment = Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignRight") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTrailing") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignVCenter");
    3.37 @@ -83,6 +78,11 @@
    3.38  
    3.39      gridLayout.AddWidget(armyName, 2, 2, 1, 1);
    3.40  
    3.41 +    raceList = new QListWidget(CreateNewArmyLayout);
    3.42 +    raceList.ObjectName = "raceList";
    3.43 +
    3.44 +    gridLayout.AddWidget(raceList, 1, 2, 1, 1);
    3.45 +
    3.46  
    3.47      RetranslateUi(CreateNewArmyLayout);
    3.48      QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewArmyLayout, Qt.SLOT("accept()"));
    3.49 @@ -96,8 +96,8 @@
    3.50      CreateNewArmyLayout.WindowTitle = QApplication.Translate("CreateNewArmyLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8);
    3.51      lblGameSystem.Text = QApplication.Translate("CreateNewArmyLayout", "game system:", null, QApplication.Encoding.UnicodeUTF8);
    3.52      lblRace.Text = QApplication.Translate("CreateNewArmyLayout", "race:", null, QApplication.Encoding.UnicodeUTF8);
    3.53 -    lblArmyName.Text = QApplication.Translate("CreateNewArmyLayout", "TextLabel", null, QApplication.Encoding.UnicodeUTF8);
    3.54 -    lblArmySize.Text = QApplication.Translate("CreateNewArmyLayout", "TextLabel", null, QApplication.Encoding.UnicodeUTF8);
    3.55 +    lblArmyName.Text = QApplication.Translate("CreateNewArmyLayout", "army name:", null, QApplication.Encoding.UnicodeUTF8);
    3.56 +    lblArmySize.Text = QApplication.Translate("CreateNewArmyLayout", "army size:", null, QApplication.Encoding.UnicodeUTF8);
    3.57      } // RetranslateUi
    3.58  
    3.59  }
     4.1 --- a/qt-gui/CreateNewArmyLayout.ui	Mon Jan 25 20:54:33 2010 +0000
     4.2 +++ b/qt-gui/CreateNewArmyLayout.ui	Wed Jan 27 20:58:56 2010 +0000
     4.3 @@ -47,13 +47,10 @@
     4.4       </property>
     4.5      </widget>
     4.6     </item>
     4.7 -   <item row="1" column="2">
     4.8 -    <widget class="QListView" name="raceList"/>
     4.9 -   </item>
    4.10     <item row="2" column="0">
    4.11      <widget class="QLabel" name="lblArmyName">
    4.12       <property name="text">
    4.13 -      <string>TextLabel</string>
    4.14 +      <string>army name:</string>
    4.15       </property>
    4.16       <property name="alignment">
    4.17        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    4.18 @@ -63,7 +60,7 @@
    4.19     <item row="3" column="0">
    4.20      <widget class="QLabel" name="lblArmySize">
    4.21       <property name="text">
    4.22 -      <string>TextLabel</string>
    4.23 +      <string>army size:</string>
    4.24       </property>
    4.25       <property name="alignment">
    4.26        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    4.27 @@ -76,6 +73,9 @@
    4.28     <item row="2" column="2">
    4.29      <widget class="QLineEdit" name="armyName"/>
    4.30     </item>
    4.31 +   <item row="1" column="2">
    4.32 +    <widget class="QListWidget" name="raceList"/>
    4.33 +   </item>
    4.34    </layout>
    4.35   </widget>
    4.36   <resources/>