KXMLGUI - User definable toolbars and actions

Andras Mantia amantia at kde.org
Mon Jun 14 17:01:45 BST 2010


On Monday 14 June 2010, Andreas Pakulat wrote:
> How did Quanta do this in KDE3? I mean xmlgui isn't a KDE4 feature,
> its been in there in KDE3 times as well and there's not been that
> many changes either.

It used XMLGUI. It is not static only, you can modify the UI 
dynamically. After all plugins do it all the time.
 When a toolbar file (an XML file, similar to the xmlgui rc files) is 
loaded, a new KXmlGuiClient (based) object is created and added to the 
application's guiFactory. Now when a new client is added, the 
createContainer() method is called, where depending on the  (XML) 
element that is processed from the GUI file, you can create your own 
widgets. This part was used to put a KTabWidget inside a toolbar and 
here was some magic, in the sense the code you see is like that because 
tests shown that works the best.
 In the KDE4 port it is all in the plugins/usertoolbars. For KDE4 I even 
did two implementations:
- create a real toolbar for every user toolbar loaded (this is the 
simple case, createContainer doesn't do anything)
- do it like in Quanta 3 and put them into a tabwidget, and the 
tabwidget into the toolbar.  This is better IMO since otherwise 
switching between two different kind of XML documents would trigger a 
relayout of the main toolbars, which is not that nice. 

The other magic was to get the actions in Configure Toolbars & Shortcuts 
right. In KDE3 and at the porting point in KDE4, it was needed to add 
the actions from a loaded toolbar to the main actionCollection object of 
the gui client as well. And vice versa, add all actions to the toolbar's 
actioncollection. Otherwise it is not possible to create custom toolbars 
with actions defined in the application itself or actions that were 
created from other toolbars (or with the Configure Actions dialog).

There is some extra code to handle translation of the toolbar names, so 
Standard/Style and to make sure the same toolbar is not loaded more than 
once, actions are not duplicated.

I think most of the used code is documented in the KDE api docs, but it 
isn't heavily used in other apps.

Andras


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100614/0a836295/attachment.sig>


More information about the kde-core-devel mailing list