UiManager
Creating a Ui Manager
Creating a Ui Manager is easy:
Now add your ActionGroups:
ui->insert_action_group(gt1,0);
The parameter is the position. If you have a two groups called the same name, then the group with the lower number (earlier) will hide a high number (later) group.Now you want to add your ui definition, but first you'll have to create it:This can be in a separate file, to make menu editing easy:
<ui>
<menubar name='MyMenuBar'>
<menu action='FileMenu'>
<menuitem action='FileNew'/>
<menuitem action='FileOpen'/>
<separator/>
<menuitem action='FileQuit'/>
</menu>
<menu action='EditMenu'>
<menuitem action='EditCopy'/>
<menuitem action='EditPaste'/>
</menu>
</menubar>
<toolbar name='MyToolBar'>
<toolitem action='myfirstaction'/>
<toolitem action='my2action'/>
<separator/>
<toolitem action='Quit'>
</toolbar>
</ui>
This is a sample xml definition of a menu structure, with a toolbar. It can be several levels deep by just using a menu instead of a menuitem.Now, just add the ui definition(s) to the ui:
int id=ui->add_ui_from_file("menu.xml");
You can also add from a string with ui->add_ui_from_string();The return value is an id you can use to remove the ui definition from the ui manager. The ui's get merged.All this is a bunch of convenient shortcuts for doing it all by hand with:
ui->new_merge_id() and ui->add_ui().UiManager takes all this info and creates the appropriate widgets. You can get the widgets for packing into your containers (vbox or whatever) with the following:
object menub=ui->get_widget("/MyMenuBar");
object toolb=ui->get_widget("/MyToolBar");
Where "MyMenuBar" and "MyToolBar" are the names you used for the menubar and toolbar in the xml definition. The / means that it will search from the top of the xml tree.If you want to get the widget for a specific action, you can do something like:
object widget=ui->get_widget("/MyMenuBar/EditMenu/EditCopy");
This will get the widget for the menu item EditCopy from the example xml definition above.
Powered by PikeWiki2
|
|