changeset 28:5ee15def17e7

Re #244: Create "New Unit" dialog in Qt# app * Add handler to feed back event (Qt widgets and events can't contain enough data) * Add actions to toolbar as army changes * Add initial "new unit" dialog by stripping down "new army" dialog
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Jul 2010 20:32:01 +0000
parents 7eaa8a1715e2
children 246237c88b9b
files Handler/NewUnitEventHandler.cs IBBoard.WarFoundry.GUI.QtSharp.csproj MainWindow.cs icons/ui/add.png qt-gui/CreateNewUnitLayout.cs qt-gui/CreateNewUnitLayout.ui
diffstat 6 files changed, 223 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Handler/NewUnitEventHandler.cs	Sat Jul 31 20:32:01 2010 +0000
     1.3 @@ -0,0 +1,25 @@
     1.4 +// This file (Main.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +using IBBoard.WarFoundry.API.Commands;
     1.8 +using IBBoard.WarFoundry.API.Objects;
     1.9 +
    1.10 +namespace IBBoard.WarFoundry.GUI.QtSharp.Handler
    1.11 +{
    1.12 +	public class NewUnitEventHandler
    1.13 +	{
    1.14 +		private Category cat;
    1.15 +		private SingleArgMethodInvoker<Category> callback;
    1.16 +		
    1.17 +		public NewUnitEventHandler(Category category, SingleArgMethodInvoker<Category> callbackMethod)
    1.18 +		{
    1.19 +			cat = category;
    1.20 +			callback = callbackMethod;
    1.21 +		}
    1.22 +		
    1.23 +		public void CreateNewUnit()
    1.24 +		{
    1.25 +			callback(cat);
    1.26 +		}
    1.27 +	}
    1.28 +}
     2.1 --- a/IBBoard.WarFoundry.GUI.QtSharp.csproj	Sat Jul 31 20:30:30 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.GUI.QtSharp.csproj	Sat Jul 31 20:32:01 2010 +0000
     2.3 @@ -39,6 +39,8 @@
     2.4      <Compile Include="qt-gui\MainWindowLayout.cs" />
     2.5      <Compile Include="qt-gui\CreateNewArmyLayout.cs" />
     2.6      <Compile Include="NewArmyDialog.cs" />
     2.7 +    <Compile Include="Handler\NewUnitEventHandler.cs" />
     2.8 +    <Compile Include="qt-gui\CreateNewUnitLayout.cs" />
     2.9    </ItemGroup>
    2.10    <ItemGroup>
    2.11      <None Include="compile-ui.sh" />
    2.12 @@ -101,12 +103,17 @@
    2.13      <None Include="WarFoundryQtPref.xml">
    2.14        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.15      </None>
    2.16 +    <None Include="qt-gui\CreateNewUnitLayout.ui" />
    2.17 +    <None Include="icons\ui\add.png">
    2.18 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.19 +    </None>
    2.20    </ItemGroup>
    2.21    <ItemGroup>
    2.22      <Folder Include="qt-gui\" />
    2.23      <Folder Include="icons\" />
    2.24      <Folder Include="icons\ui\" />
    2.25      <Folder Include="lib\" />
    2.26 +    <Folder Include="Handler\" />
    2.27    </ItemGroup>
    2.28    <ItemGroup>
    2.29      <Content Include="icons\App.png">
     3.1 --- a/MainWindow.cs	Sat Jul 31 20:30:30 2010 +0000
     3.2 +++ b/MainWindow.cs	Sat Jul 31 20:32:01 2010 +0000
     3.3 @@ -14,6 +14,7 @@
     3.4  using IBBoard.WarFoundry.API.Factories;
     3.5  using IBBoard.WarFoundry.API.Objects;
     3.6  using IBBoard.WarFoundry.API.Savers;
     3.7 +using IBBoard.WarFoundry.GUI.QtSharp.Handler;
     3.8  
     3.9  namespace IBBoard.WarFoundry.GUI.QtSharp
    3.10  {
    3.11 @@ -28,6 +29,7 @@
    3.12  		private QFileDialog saveArmyDialog;
    3.13  		private QFileDialog openArmyDialog;
    3.14  		private Preferences preferences;
    3.15 +		private QAction[] categoryActions;
    3.16  		
    3.17  		public MainWindow ()
    3.18  		{
    3.19 @@ -60,6 +62,7 @@
    3.20  			ConnectMenuActions();
    3.21  			SetUpToolbar();
    3.22  			layout.unitTabs.Clear();
    3.23 +			categoryActions = new QAction[0];
    3.24  			WarFoundryCore.ArmyChanged+= HandleWarFoundryCoreArmyChanged;
    3.25  			CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated;
    3.26  		}
    3.27 @@ -145,6 +148,7 @@
    3.28  			CommandStack.Reset();
    3.29  			loadedFilePath = null;
    3.30  			layout.actionSaveArmy.Enabled = false;
    3.31 +			SetCategoryButtons(newValue == null ? new Category[0] : newValue.Race.Categories);
    3.32  			SetPointsPanelText();
    3.33  			SetAppTitle();
    3.34  		}
    3.35 @@ -473,9 +477,14 @@
    3.36  			layout.armyTree.SetModel(treeModel);
    3.37  		}
    3.38  		
    3.39 +		private QVariant WrapObject(WarFoundryObject obj)
    3.40 +		{
    3.41 +			return QVariant.FromValue<WarFoundryObject>(obj);
    3.42 +		}
    3.43 +
    3.44  		private QStandardItem CreateTreeItem(WarFoundryObject obj)
    3.45  		{
    3.46 -			QVariant wrappedObject = QVariant.FromValue<WarFoundryObject>(obj);
    3.47 +			QVariant wrappedObject = WrapObject(obj);
    3.48  			QStandardItem item = new QStandardItem(obj.Name);
    3.49  			item.SetData(wrappedObject);
    3.50  			return item;
    3.51 @@ -496,11 +505,37 @@
    3.52  			return item;
    3.53  		}
    3.54  
    3.55 -		void SetCategoryButtons (Category[] categories)
    3.56 +		private void SetCategoryButtons(Category[] categories)
    3.57  		{
    3.58 -			//TODO create category buttons
    3.59 +			foreach (QAction action in categoryActions)
    3.60 +			{
    3.61 +				layout.toolBar.RemoveAction(action);
    3.62 +			}
    3.63 +			
    3.64 +			if (categories != null && categories.Length > 0)
    3.65 +			{
    3.66 +				int catCount = categories.Length;
    3.67 +				categoryActions = new QAction[catCount];
    3.68 +				int i = 0;
    3.69 +				
    3.70 +				foreach (Category category in categories)
    3.71 +				{
    3.72 +					QAction action = new QAction(this);
    3.73 +					action.icon = new QIcon("icons/ui/add.png");
    3.74 +					NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnit);
    3.75 +					ConnectMenuAction(action, handler.CreateNewUnit);
    3.76 +					categoryActions[i] = action;
    3.77 +					layout.toolBar.AddAction(action);
    3.78 +					i++;
    3.79 +				}
    3.80 +			}
    3.81  		}
    3.82 -		
    3.83 +
    3.84 +		private void AddUnit(Category cat)
    3.85 +		{
    3.86 +			QMessageBox.Information(this, "Add unit", cat.Name);
    3.87 +		}
    3.88 +
    3.89  		void EnableCategoryButtons ()
    3.90  		{
    3.91  			//TODO enable category buttons
     4.1 Binary file icons/ui/add.png has changed
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/qt-gui/CreateNewUnitLayout.cs	Sat Jul 31 20:32:01 2010 +0000
     5.3 @@ -0,0 +1,68 @@
     5.4 +/********************************************************************************
     5.5 +** Form generated from reading ui file 'CreateNewUnitLayout.ui'
     5.6 +**
     5.7 +** Created: Sat Jul 31 21:11:26 2010
     5.8 +**      by: Qt User Interface Compiler for C# version 4.6.3
     5.9 +**
    5.10 +** WARNING! All changes made in this file will be lost when recompiling ui file!
    5.11 +********************************************************************************/
    5.12 +
    5.13 +
    5.14 +using Qyoto;
    5.15 +
    5.16 +public class Ui_CreateNewArmyLayout
    5.17 +{
    5.18 +    public QGridLayout gridLayout;
    5.19 +    public QDialogButtonBox buttonBox;
    5.20 +    public QLabel lblUnitType;
    5.21 +    public QListWidget unitTypeList;
    5.22 +
    5.23 +    public void SetupUi(QDialog CreateNewArmyLayout)
    5.24 +    {
    5.25 +    if (CreateNewArmyLayout.ObjectName == "")
    5.26 +        CreateNewArmyLayout.ObjectName = "CreateNewArmyLayout";
    5.27 +    CreateNewArmyLayout.WindowModality = Qt.WindowModality.WindowModal;
    5.28 +    QSize Size = new QSize(400, 214);
    5.29 +    Size = Size.ExpandedTo(CreateNewArmyLayout.MinimumSizeHint());
    5.30 +    CreateNewArmyLayout.Size = Size;
    5.31 +    gridLayout = new QGridLayout(CreateNewArmyLayout);
    5.32 +    gridLayout.ObjectName = "gridLayout";
    5.33 +    buttonBox = new QDialogButtonBox(CreateNewArmyLayout);
    5.34 +    buttonBox.ObjectName = "buttonBox";
    5.35 +    buttonBox.Orientation = Qt.Orientation.Horizontal;
    5.36 +    buttonBox.StandardButtons = Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Cancel") | Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Ok");
    5.37 +
    5.38 +    gridLayout.AddWidget(buttonBox, 1, 2, 1, 1);
    5.39 +
    5.40 +    lblUnitType = new QLabel(CreateNewArmyLayout);
    5.41 +    lblUnitType.ObjectName = "lblUnitType";
    5.42 +    lblUnitType.Alignment = Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignRight") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTop") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTrailing");
    5.43 +
    5.44 +    gridLayout.AddWidget(lblUnitType, 0, 0, 1, 1);
    5.45 +
    5.46 +    unitTypeList = new QListWidget(CreateNewArmyLayout);
    5.47 +    unitTypeList.ObjectName = "unitTypeList";
    5.48 +    unitTypeList.Enabled = false;
    5.49 +
    5.50 +    gridLayout.AddWidget(unitTypeList, 0, 2, 1, 1);
    5.51 +
    5.52 +
    5.53 +    RetranslateUi(CreateNewArmyLayout);
    5.54 +    QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewArmyLayout, Qt.SLOT("accept()"));
    5.55 +    QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewArmyLayout, Qt.SLOT("reject()"));
    5.56 +
    5.57 +    QMetaObject.ConnectSlotsByName(CreateNewArmyLayout);
    5.58 +    } // SetupUi
    5.59 +
    5.60 +    public void RetranslateUi(QDialog CreateNewArmyLayout)
    5.61 +    {
    5.62 +    CreateNewArmyLayout.WindowTitle = QApplication.Translate("CreateNewArmyLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8);
    5.63 +    lblUnitType.Text = QApplication.Translate("CreateNewArmyLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8);
    5.64 +    } // RetranslateUi
    5.65 +
    5.66 +}
    5.67 +
    5.68 +namespace Ui {
    5.69 +    public class CreateNewArmyLayout : Ui_CreateNewArmyLayout {}
    5.70 +} // namespace Ui
    5.71 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/qt-gui/CreateNewUnitLayout.ui	Sat Jul 31 20:32:01 2010 +0000
     6.3 @@ -0,0 +1,84 @@
     6.4 +<?xml version="1.0" encoding="UTF-8"?>
     6.5 +<ui version="4.0">
     6.6 + <class>CreateNewArmyLayout</class>
     6.7 + <widget class="QDialog" name="CreateNewArmyLayout">
     6.8 +  <property name="windowModality">
     6.9 +   <enum>Qt::WindowModal</enum>
    6.10 +  </property>
    6.11 +  <property name="geometry">
    6.12 +   <rect>
    6.13 +    <x>0</x>
    6.14 +    <y>0</y>
    6.15 +    <width>400</width>
    6.16 +    <height>214</height>
    6.17 +   </rect>
    6.18 +  </property>
    6.19 +  <property name="windowTitle">
    6.20 +   <string>Dialog</string>
    6.21 +  </property>
    6.22 +  <layout class="QGridLayout" name="gridLayout">
    6.23 +   <item row="1" column="2">
    6.24 +    <widget class="QDialogButtonBox" name="buttonBox">
    6.25 +     <property name="orientation">
    6.26 +      <enum>Qt::Horizontal</enum>
    6.27 +     </property>
    6.28 +     <property name="standardButtons">
    6.29 +      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    6.30 +     </property>
    6.31 +    </widget>
    6.32 +   </item>
    6.33 +   <item row="0" column="0">
    6.34 +    <widget class="QLabel" name="lblUnitType">
    6.35 +     <property name="text">
    6.36 +      <string>unit type:</string>
    6.37 +     </property>
    6.38 +     <property name="alignment">
    6.39 +      <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
    6.40 +     </property>
    6.41 +    </widget>
    6.42 +   </item>
    6.43 +   <item row="0" column="2">
    6.44 +    <widget class="QListWidget" name="unitTypeList">
    6.45 +     <property name="enabled">
    6.46 +      <bool>false</bool>
    6.47 +     </property>
    6.48 +    </widget>
    6.49 +   </item>
    6.50 +  </layout>
    6.51 + </widget>
    6.52 + <resources/>
    6.53 + <connections>
    6.54 +  <connection>
    6.55 +   <sender>buttonBox</sender>
    6.56 +   <signal>accepted()</signal>
    6.57 +   <receiver>CreateNewArmyLayout</receiver>
    6.58 +   <slot>accept()</slot>
    6.59 +   <hints>
    6.60 +    <hint type="sourcelabel">
    6.61 +     <x>248</x>
    6.62 +     <y>254</y>
    6.63 +    </hint>
    6.64 +    <hint type="destinationlabel">
    6.65 +     <x>157</x>
    6.66 +     <y>274</y>
    6.67 +    </hint>
    6.68 +   </hints>
    6.69 +  </connection>
    6.70 +  <connection>
    6.71 +   <sender>buttonBox</sender>
    6.72 +   <signal>rejected()</signal>
    6.73 +   <receiver>CreateNewArmyLayout</receiver>
    6.74 +   <slot>reject()</slot>
    6.75 +   <hints>
    6.76 +    <hint type="sourcelabel">
    6.77 +     <x>316</x>
    6.78 +     <y>260</y>
    6.79 +    </hint>
    6.80 +    <hint type="destinationlabel">
    6.81 +     <x>286</x>
    6.82 +     <y>274</y>
    6.83 +    </hint>
    6.84 +   </hints>
    6.85 +  </connection>
    6.86 + </connections>
    6.87 +</ui>