# HG changeset patch # User IBBoard # Date 1280608321 0 # Node ID 5ee15def17e7a8719f914c6c1ac9d376c14362ab # Parent 7eaa8a1715e2840d8ea0d8a38fde93e0154e44db 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 diff -r 7eaa8a1715e2 -r 5ee15def17e7 Handler/NewUnitEventHandler.cs --- /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 callback; + + public NewUnitEventHandler(Category category, SingleArgMethodInvoker callbackMethod) + { + cat = category; + callback = callbackMethod; + } + + public void CreateNewUnit() + { + callback(cat); + } + } +} diff -r 7eaa8a1715e2 -r 5ee15def17e7 IBBoard.WarFoundry.GUI.QtSharp.csproj --- 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 @@ + + @@ -101,12 +103,17 @@ PreserveNewest + + + PreserveNewest + + diff -r 7eaa8a1715e2 -r 5ee15def17e7 MainWindow.cs --- 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(obj); + } + private QStandardItem CreateTreeItem(WarFoundryObject obj) { - QVariant wrappedObject = QVariant.FromValue(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 diff -r 7eaa8a1715e2 -r 5ee15def17e7 icons/ui/add.png Binary file icons/ui/add.png has changed diff -r 7eaa8a1715e2 -r 5ee15def17e7 qt-gui/CreateNewUnitLayout.cs --- /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 + diff -r 7eaa8a1715e2 -r 5ee15def17e7 qt-gui/CreateNewUnitLayout.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 @@ + + + CreateNewArmyLayout + + + Qt::WindowModal + + + + 0 + 0 + 400 + 214 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + unit type: + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + + + false + + + + + + + + + buttonBox + accepted() + CreateNewArmyLayout + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CreateNewArmyLayout + reject() + + + 316 + 260 + + + 286 + 274 + + + + +