In the Showcase application that can be found in http://demo.qafe.com in the tree on the left in the application in Showcase Samples, Components, other components you’ll find the items/nodes “Menu” and “Toolbar”.
Toolbars and Menus are special components. They can be reused! What does this mean ? We use the menu component for this explanation, but it could also go for the toolbar of course.
Say you have an application with several windows defined in QAML. You want each of the windows to have a menu, just like you know it from Firefox with “File”, “Edit” etc. Since the menus are the same for each of your windows, it would be cumbersome to define the menu for each window separately. That’s why in QAFE we use “menu-definition” components. Since it is a definition, it can be referenced to by components, especially the rootpanel (the first panel of each window).
The menu is a global defintion which can be referenced by the rootpanel (the first panel of each window) by using attribute “menu” to the id of the menu-definition.
The code would be someting like this
<rootpanel menu="main_menu"> ..... </rootpanel>
The menu-definition is on the same level as the window (in the hierachy of QAML) and looks something like this:
<menu-definition id="main_menu">
<menu id="file_menu" displayname="File">
<menu id="file_menu_save" displayname="Save" />
<menu id="file_menu_save_and_proceed" displayname="Save as.." />
<separator />
<menu id="file_menu_print" displayname="Print.." />
<separator />
<menu id="file_menu_close_all" displayname="Close All" />
<separator />
<menu id="file_menu_exit" displayname="Exit" />
</menu>
</menu-definition>
The same goes for the toolbar, only then the tag is
toolbar-definition
Note: In a previous post we said about large projects. Of course the menu-definitions and toolbar-definitions are ideally stored in separate files, which are merged when loading.
Hopefully this part helps in creating useful and maintainable applications.
