Mercurial > repos > IBBoard.WarFoundry.GUI.QtSharp
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 wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Handler/NewUnitEventHandler.cs Sat Jul 31 20:32:01 2010 +0000 @@ -0,0 +1,25 @@ +// This file (Main.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard +// +// 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. +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.GUI.QtSharp.Handler +{ + public class NewUnitEventHandler + { + private Category cat; + private SingleArgMethodInvoker<Category> callback; + + public NewUnitEventHandler(Category category, SingleArgMethodInvoker<Category> callbackMethod) + { + cat = category; + callback = callbackMethod; + } + + public void CreateNewUnit() + { + callback(cat); + } + } +}
--- a/IBBoard.WarFoundry.GUI.QtSharp.csproj Sat Jul 31 20:30:30 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.QtSharp.csproj Sat Jul 31 20:32:01 2010 +0000 @@ -39,6 +39,8 @@ <Compile Include="qt-gui\MainWindowLayout.cs" /> <Compile Include="qt-gui\CreateNewArmyLayout.cs" /> <Compile Include="NewArmyDialog.cs" /> + <Compile Include="Handler\NewUnitEventHandler.cs" /> + <Compile Include="qt-gui\CreateNewUnitLayout.cs" /> </ItemGroup> <ItemGroup> <None Include="compile-ui.sh" /> @@ -101,12 +103,17 @@ <None Include="WarFoundryQtPref.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="qt-gui\CreateNewUnitLayout.ui" /> + <None Include="icons\ui\add.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Folder Include="qt-gui\" /> <Folder Include="icons\" /> <Folder Include="icons\ui\" /> <Folder Include="lib\" /> + <Folder Include="Handler\" /> </ItemGroup> <ItemGroup> <Content Include="icons\App.png">
--- a/MainWindow.cs Sat Jul 31 20:30:30 2010 +0000 +++ b/MainWindow.cs Sat Jul 31 20:32:01 2010 +0000 @@ -14,6 +14,7 @@ using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Savers; +using IBBoard.WarFoundry.GUI.QtSharp.Handler; namespace IBBoard.WarFoundry.GUI.QtSharp { @@ -28,6 +29,7 @@ private QFileDialog saveArmyDialog; private QFileDialog openArmyDialog; private Preferences preferences; + private QAction[] categoryActions; public MainWindow () { @@ -60,6 +62,7 @@ ConnectMenuActions(); SetUpToolbar(); layout.unitTabs.Clear(); + categoryActions = new QAction[0]; WarFoundryCore.ArmyChanged+= HandleWarFoundryCoreArmyChanged; CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated; } @@ -145,6 +148,7 @@ CommandStack.Reset(); loadedFilePath = null; layout.actionSaveArmy.Enabled = false; + SetCategoryButtons(newValue == null ? new Category[0] : newValue.Race.Categories); SetPointsPanelText(); SetAppTitle(); } @@ -473,9 +477,14 @@ layout.armyTree.SetModel(treeModel); } + private QVariant WrapObject(WarFoundryObject obj) + { + return QVariant.FromValue<WarFoundryObject>(obj); + } + private QStandardItem CreateTreeItem(WarFoundryObject obj) { - QVariant wrappedObject = QVariant.FromValue<WarFoundryObject>(obj); + QVariant wrappedObject = WrapObject(obj); QStandardItem item = new QStandardItem(obj.Name); item.SetData(wrappedObject); return item; @@ -496,11 +505,37 @@ return item; } - void SetCategoryButtons (Category[] categories) + private void SetCategoryButtons(Category[] categories) { - //TODO create category buttons + foreach (QAction action in categoryActions) + { + layout.toolBar.RemoveAction(action); + } + + if (categories != null && categories.Length > 0) + { + int catCount = categories.Length; + categoryActions = new QAction[catCount]; + int i = 0; + + foreach (Category category in categories) + { + QAction action = new QAction(this); + action.icon = new QIcon("icons/ui/add.png"); + NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnit); + ConnectMenuAction(action, handler.CreateNewUnit); + categoryActions[i] = action; + layout.toolBar.AddAction(action); + i++; + } + } } - + + private void AddUnit(Category cat) + { + QMessageBox.Information(this, "Add unit", cat.Name); + } + void EnableCategoryButtons () { //TODO enable category buttons
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qt-gui/CreateNewUnitLayout.cs Sat Jul 31 20:32:01 2010 +0000 @@ -0,0 +1,68 @@ +/******************************************************************************** +** Form generated from reading ui file 'CreateNewUnitLayout.ui' +** +** Created: Sat Jul 31 21:11:26 2010 +** by: Qt User Interface Compiler for C# version 4.6.3 +** +** WARNING! All changes made in this file will be lost when recompiling ui file! +********************************************************************************/ + + +using Qyoto; + +public class Ui_CreateNewArmyLayout +{ + public QGridLayout gridLayout; + public QDialogButtonBox buttonBox; + public QLabel lblUnitType; + public QListWidget unitTypeList; + + public void SetupUi(QDialog CreateNewArmyLayout) + { + if (CreateNewArmyLayout.ObjectName == "") + CreateNewArmyLayout.ObjectName = "CreateNewArmyLayout"; + CreateNewArmyLayout.WindowModality = Qt.WindowModality.WindowModal; + QSize Size = new QSize(400, 214); + Size = Size.ExpandedTo(CreateNewArmyLayout.MinimumSizeHint()); + CreateNewArmyLayout.Size = Size; + gridLayout = new QGridLayout(CreateNewArmyLayout); + gridLayout.ObjectName = "gridLayout"; + buttonBox = new QDialogButtonBox(CreateNewArmyLayout); + buttonBox.ObjectName = "buttonBox"; + buttonBox.Orientation = Qt.Orientation.Horizontal; + buttonBox.StandardButtons = Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Cancel") | Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Ok"); + + gridLayout.AddWidget(buttonBox, 1, 2, 1, 1); + + lblUnitType = new QLabel(CreateNewArmyLayout); + lblUnitType.ObjectName = "lblUnitType"; + lblUnitType.Alignment = Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignRight") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTop") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTrailing"); + + gridLayout.AddWidget(lblUnitType, 0, 0, 1, 1); + + unitTypeList = new QListWidget(CreateNewArmyLayout); + unitTypeList.ObjectName = "unitTypeList"; + unitTypeList.Enabled = false; + + gridLayout.AddWidget(unitTypeList, 0, 2, 1, 1); + + + RetranslateUi(CreateNewArmyLayout); + QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewArmyLayout, Qt.SLOT("accept()")); + QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewArmyLayout, Qt.SLOT("reject()")); + + QMetaObject.ConnectSlotsByName(CreateNewArmyLayout); + } // SetupUi + + public void RetranslateUi(QDialog CreateNewArmyLayout) + { + CreateNewArmyLayout.WindowTitle = QApplication.Translate("CreateNewArmyLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8); + lblUnitType.Text = QApplication.Translate("CreateNewArmyLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8); + } // RetranslateUi + +} + +namespace Ui { + public class CreateNewArmyLayout : Ui_CreateNewArmyLayout {} +} // namespace Ui +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qt-gui/CreateNewUnitLayout.ui Sat Jul 31 20:32:01 2010 +0000 @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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> + <y>0</y> + <width>400</width> + <height>214</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="2"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="lblUnitType"> + <property name="text"> + <string>unit type:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QListWidget" name="unitTypeList"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>CreateNewArmyLayout</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>CreateNewArmyLayout</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>