Salome HOME
Revert "Synchronize adm files"
[modules/gui.git] / src / Qtx / QtxActionToolMgr.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      QtxActionToolMgr.cxx
24 // Author:    Alexander SOLOVYOV, Sergey TELKOV
25 //
26 #include "QtxActionToolMgr.h"
27
28 #include "QtxAction.h"
29 #include "QtxToolBar.h"
30
31 #include <QApplication>
32 #include <QHideEvent>
33 #include <QMainWindow>
34
35 /*!
36   \class QtxActionToolMgr::ToolNode
37   \brief Represents a toolbutton inside toolbar structure.
38   \internal
39 */
40
41 /*!
42   \fn QtxActionToolMgr::ToolNode::ToolNode()
43   \internal
44   \brief Default constructor.
45 */
46
47 /*!
48   \fn QtxActionToolMgr::ToolNode::ToolNode( const int _id )
49   \brief Constructor.
50   \internal
51   \param _id toolbar node ID
52 */
53
54 /*!
55   \class QtxActionToolMgr
56   \brief Toolbar actions manager.
57   
58   Toolbar manager allows using of set of action for automatic generating of
59   application toolbars and dynamic update of toolbars contents.
60
61   Use insert(), append() and remove() methods to create toolbar and add actions to it.
62   Methods show(), hide() allow displaying/erasing of specified toolbar items.
63
64   Toolbar manager automatically optimizes toolbars by removing extra separators, etc.
65 */
66
67 /*!
68   \brief Constructor.
69   \param p parent main window
70 */
71 QtxActionToolMgr::QtxActionToolMgr( QMainWindow* p )
72 : QtxActionMgr( p ),
73   myMainWindow( p )
74 {
75 }
76
77 /*!
78   \brief Destructor.
79 */
80 QtxActionToolMgr::~QtxActionToolMgr()
81 {
82 }
83
84 /*!
85   \brief Get parent main window.
86   \return main window pointer
87 */
88 QMainWindow* QtxActionToolMgr::mainWindow() const
89 {
90   return myMainWindow;
91 }
92
93 /*!
94   \brief Create toolbar and assign \a id to it.
95
96   If \a tid is less than 0, the identifier is generated automatically.
97   If toolbar with given \a tid is already registered, the toolbar will not be created.
98
99   \param title toolbar title
100   \param tid requested toolbar ID
101   \param mw parent main window; if it is null, the tool manager's main window is used
102   \param vis show toolbar visible immediately after creation (true by default)
103   \return id of created/found toolbar
104 */
105 int QtxActionToolMgr::createToolBar( const QString& title, const int tid, QMainWindow* mw, bool vis )
106 {
107   return createToolBar( title, true, Qt::AllToolBarAreas, tid, mw, vis );
108 }
109
110 /*!
111   \brief Create toolbar and assign \a id to it.
112
113   If \a tid is less than 0, the identifier is generated automatically.
114   If toolbar with given \a tid is already registered, the toolbar will not be created.
115
116   \param title toolbar title
117   \param floatable if \c true, new toolbar is made floatable
118   \param dockAreas dock areas of the main window where the new toolbar can be situated
119   \param tid requested toolbar ID
120   \param mw parent main window; if it is null, the tool manager's main window is used
121   \param vis show toolbar visible immediately after creation (true by default)
122   \return id of created/found toolbar
123 */
124 int QtxActionToolMgr::createToolBar( const QString& title, bool floatable, Qt::ToolBarAreas dockAreas, 
125                                      int tid, QMainWindow* mw, bool vis )
126 {
127   static int _toolBarId = -1;
128
129   int tbId = -1;
130   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it )
131   {
132     if( it.value().toolBar->windowTitle().toLower() == title.toLower() &&
133         ( !mw || it.value().toolBar->parent()==mw ) )
134       tbId = it.key();
135   }
136
137   if ( tbId != -1 )
138     return tbId;
139
140   QMainWindow* tbw = mw ? mw : mainWindow();
141   QToolBar* tb = find( title, tbw );
142
143   tbId = tid < 0 ? --_toolBarId : tid;
144
145   myToolBars.insert( tbId, ToolBarInfo() );
146   ToolBarInfo& tInfo = myToolBars[tbId];
147
148   if ( !tb )
149   {
150     tb = new QtxToolBar( true, tbw );
151     //tb->setVisible( false );  // VSR: create toolbar visible initially
152     tb->setFloatable( floatable );
153     tb->setAllowedAreas( dockAreas );
154     tb->setMovable( dockAreas & Qt::AllToolBarAreas );
155     //mainWindow()->addToolBar( tb );
156     tb->setWindowTitle( title );
157     tb->setObjectName( title );
158     tb->setToolTip( title );
159     if ( !vis )
160       QApplication::postEvent( tb, new QHideEvent());
161    }
162
163   tInfo.toolBar = tb;
164   connect( tInfo.toolBar, SIGNAL( destroyed() ), this, SLOT( onToolBarDestroyed() ) );
165
166   return tbId;
167 }
168
169 /*!
170   \brief Search toolbar with given \a title owned by main window \mw. 
171   \param title toolbar title
172   \param mw main window
173   \return toolbar or 0 if it is not found
174 */
175 QToolBar* QtxActionToolMgr::find( const QString& title, QMainWindow* mw ) const
176 {
177   if ( !mw )
178     return 0;
179
180   QString pattern = title.toLower();
181
182   QToolBar* res = 0;
183   QList<QToolBar*> toolbars = qFindChildren<QToolBar*>( mw );
184   for ( QList<QToolBar*>::iterator it = toolbars.begin(); it != toolbars.end() && !res; ++it )
185   {
186     if ( (*it)->windowTitle().toLower() == pattern )
187       res = *it;
188   }
189   return res;
190 }
191
192 /*!
193   \brief Remove toolbar.
194   \param tid toolbar ID
195 */
196 void QtxActionToolMgr::removeToolBar( const int tid )
197 {
198   if ( !myToolBars.contains( tid ) )
199     return;
200
201   delete myToolBars[tid].toolBar;
202   myToolBars.remove( tid );
203 }
204
205 /*!
206   \brief Remove toolbar.
207   \param title toolbar title
208 */
209 void QtxActionToolMgr::removeToolBar( const QString& title )
210 {
211   removeToolBar( find( title ) );
212 }
213
214 /*!
215   \brief Insert action into toolbar.
216   \param id action ID
217   \param tid toolbar ID
218   \param idx action index in the toolbar (if < 0, action is appended to the end)
219   \return action ID
220 */
221 int QtxActionToolMgr::insert( const int id, const int tid, const int idx )
222 {
223   if ( !contains( id ) || !hasToolBar( tid ) )
224     return -1;
225 /*
226   if ( containsAction( id, tid ) )
227     remove( id, tid );
228 */
229   ToolNode node( id );
230
231   NodeList& list = myToolBars[tid].nodes;
232   int index = idx < 0 ? list.count() : qMin( idx, (int)list.count() );
233   list.insert( index, node );
234   triggerUpdate( tid );
235
236   return id;
237 }
238
239 /*!
240   \brief Insert action into toolbar.
241   \param a action
242   \param tid toolbar ID
243   \param idx action index in the toolbar (if < 0, action is appended to the end)
244   \return action ID
245 */
246 int QtxActionToolMgr::insert( QAction* a, const int tid, const int idx )
247 {
248   return insert( registerAction( a ), tid, idx );
249 }
250
251 /*!
252   \brief Insert action into toolbar.
253   \param id action ID
254   \param title toolbar title
255   \param idx action index in the toolbar (if < 0, action is appended to the end)
256   \return action ID
257 */
258 int QtxActionToolMgr::insert( const int id, const QString& title, const int idx )
259 {
260   return insert( id, createToolBar( title ), idx );
261 }
262
263 /*!
264   \brief Insert action into toolbar.
265   \param a action
266   \param title toolbar title
267   \param idx action index in the toolbar (if < 0, action is appended to the end)
268   \return action ID
269 */
270 int QtxActionToolMgr::insert( QAction* a, const QString& title, const int idx )
271 {
272   return insert( registerAction( a ), createToolBar( title ), idx );
273 }
274
275 /*!
276   \brief Append action to the end of toolbar.
277   \param id action ID
278   \param tid toolbar ID
279   \return action ID
280 */
281 int QtxActionToolMgr::append( const int id, const int tid )
282 {
283   return insert( id, tid );
284 }
285
286 /*!
287   \brief Append action to the end of toolbar.
288   \param a action
289   \param tid toolbar ID
290   \return action ID
291 */
292 int QtxActionToolMgr::append( QAction* a, const int tid )
293 {
294   return insert( a, tid );
295 }
296
297 /*!
298   \brief Append action to the end of toolbar.
299   \param id action ID
300   \param title toolbar title
301   \return action ID
302 */
303 int QtxActionToolMgr::append( const int id, const QString& title )
304 {
305   return insert( id, title );
306 }
307
308 /*!
309   \brief Append action to the end of toolbar.
310   \param a action
311   \param title toolbar title
312   \return action ID
313 */
314 int QtxActionToolMgr::append( QAction* a, const QString& title )
315 {
316   return insert( a, title );
317 }
318
319 /*!
320   \brief Insert action to the beginning of toolbar.
321   \param id action ID
322   \param tid toolbar ID
323   \return action ID
324 */
325 int QtxActionToolMgr::prepend( const int id, const int tid )
326 {
327   return insert( id, tid, 0 );
328 }
329
330 /*!
331   \brief Insert action to the beginning of toolbar.
332   \param a action
333   \param tid toolbar ID
334   \return action ID
335 */
336 int QtxActionToolMgr::prepend( QAction* a, const int tid )
337 {
338   return insert( a, tid, 0 );
339 }
340
341 /*!
342   \brief Insert action to the beginning of toolbar.
343   \param id action ID
344   \param title toolbar title
345   \return action ID
346 */
347 int QtxActionToolMgr::prepend( const int id, const QString& title )
348 {
349   return insert( id, title, 0 );
350 }
351
352 /*!
353   \brief Insert action to the beginning of toolbar.
354   \param a action ID
355   \param title toolbar title
356   \return action ID
357 */
358 int QtxActionToolMgr::prepend( QAction* a, const QString& title )
359 {
360   return insert( a, title, 0 );
361 }
362
363 /*!
364   \brief Remove action from toolbar.
365   \param id action ID
366   \param tid toolbar ID
367 */
368 void QtxActionToolMgr::remove( const int id, const int tid )
369 {
370   if ( !myToolBars.contains( tid ) )
371     return;
372
373   NodeList newList;
374   const NodeList& nodes = myToolBars[tid].nodes;
375   for ( NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it )
376   {
377     if ( (*it).id != id )
378       newList.append( *it );
379   }
380
381   myToolBars[tid].nodes = newList;
382
383   triggerUpdate( tid );
384 }
385
386 /*!
387   \brief Remove action from toolbar.
388   \param id action ID
389   \param title toolbar title
390 */
391 void QtxActionToolMgr::remove( const int id, const QString& title )
392 {
393   remove( id, find( title ) );
394 }
395
396 /*!
397   \brief Get toolbar by given \a tid.
398   \param tid toolbar ID
399   \return toolbar or 0 if it is not found
400 */
401 QToolBar* QtxActionToolMgr::toolBar( const int tid ) const
402 {
403   QToolBar* tb = 0;
404   if ( myToolBars.contains( tid ) )
405     tb = myToolBars[tid].toolBar;
406   return tb;
407 }
408
409 /*!
410   \brief Get toolbar by given \a title.
411   \param title toolbar title
412   \return toolbar or 0 if it is not found
413 */
414 QToolBar* QtxActionToolMgr::toolBar( const QString& title ) const
415 {
416   return toolBar( find( title ) );
417 }
418
419 /*!
420   \bried Get all registered toolbars identifiers
421   \return list of toolbars ids
422 */
423 QIntList QtxActionToolMgr::toolBarsIds() const
424 {
425   return myToolBars.keys();
426 }
427
428 /*!
429   \brief Check if toolbar with given \a id already registered.
430   \param tid toolbar ID
431   \return \c true if toolbar is registered in the toolbar manager
432 */
433 bool QtxActionToolMgr::hasToolBar( const int tid ) const
434 {
435   return myToolBars.contains( tid );
436 }
437
438 /*!
439   \brief Check if toolbar with given \a id already registered.
440   \param title toolbar title
441   \return \c true if toolbar is registered in the toolbar manager
442 */
443 bool QtxActionToolMgr::hasToolBar( const QString& title ) const
444 {
445   return find( title ) != -1;
446 }
447
448 /*!
449   \brief Check if toolbar contains given action.
450   \param id action ID
451   \param tid toolbar ID
452   \return \c true if toolbar contains action
453 */
454 bool QtxActionToolMgr::containsAction( const int id, const int tid ) const
455 {
456   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
457   {
458     if ( tid == -1 || it.key() == tid )
459     {
460       const NodeList& list = it.value().nodes;
461       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit )
462         if ( (*nit).id == id )
463           return true;
464     }
465   }
466   return false;
467 }
468
469 /*!
470   \brief Get index of the action \a id within the toolbar \a tid
471   \param id action ID
472   \param tid toolbar ID
473   \return index of the action in the toolbar or -1 if action is not contained in the toolbar
474 */
475 int QtxActionToolMgr::index( const int id, const int tid ) const
476 {
477   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
478   {
479     if ( it.key() == tid )
480     {
481       const NodeList& list = it.value().nodes;
482       int idx = 0;
483       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit, ++idx )
484         if ( (*nit).id == id ) return idx;
485     }
486   }
487   return -1;
488 }
489
490 /*!
491   \brief Called when toolbar is destroyed.
492
493   Clears internal pointer to the toolbar to disable crashes.
494 */
495 void QtxActionToolMgr::onToolBarDestroyed()
496 {
497   myToolBars.remove( find( (QToolBar*)sender() ) );
498 }
499
500 /*!
501   \brief Search toolbar by given \a name.
502   \param title toolbar title
503   \return toolbar ID or -1 if it is not found
504 */
505 int QtxActionToolMgr::find( const QString& title ) const
506 {
507   int id = -1;
508   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
509   {
510     if ( it.value().toolBar->windowTitle() == title )
511       id = it.key();
512   }
513   return id;
514 }
515
516 /*!
517   \brief Get toolbar identifier.
518   \param tb toolbar
519   \return toolbar ID or -1 if toolbar is not registered
520 */
521 int QtxActionToolMgr::find( QToolBar* tb ) const
522 {
523   int id = -1;
524   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
525   {
526     if ( it.value().toolBar == tb )
527       id = it.key();
528   }
529   return id;
530 }
531
532 /*!
533   \brief Update toolbar.
534   \param tid toolbar ID
535 */
536 void QtxActionToolMgr::updateToolBar( const int tid )
537 {
538   if ( !isUpdatesEnabled() )
539     return;
540
541   if ( !myToolBars.contains( tid ) )
542     return;
543
544   QToolBar* tb = myToolBars[tid].toolBar;
545   const NodeList& list = myToolBars[tid].nodes;
546
547   for ( NodeList::const_iterator it = list.begin(); it != list.end(); ++it )
548   {
549     QAction* a = action( (*it).id );
550     tb->removeAction( a );
551 //    if ( a )
552 //      a->removeFrom( tb );
553   }
554
555   tb->clear();
556
557   for ( NodeList::const_iterator itr = list.begin(); itr != list.end(); ++itr )
558   {
559     if ( !isVisible( (*itr).id, tid ) )
560       continue;
561
562     QAction* a = action( (*itr).id );
563     tb->addAction( a );
564 //    if ( a )
565 //      a->addTo( tb );
566   }
567
568   simplifySeparators( tb );
569   
570   // fix of 19921 -->
571   if ( !tb->isVisible() )
572     tb->adjustSize();
573   // fix of 19921 <--
574 }
575
576 /*!
577   \brief Update all registered toolbars.
578 */
579 void QtxActionToolMgr::internalUpdate()
580 {
581   if ( !isUpdatesEnabled() )
582     return;
583
584   for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 )
585     updateToolBar( it1.key() );
586
587   myUpdateIds.clear();
588 }
589
590 /*!
591   \brief Remove extra separators from the toolbar.
592   \param tb toolbar
593 */
594 void QtxActionToolMgr::simplifySeparators( QToolBar* tb )
595 {
596   Qtx::simplifySeparators( tb );
597 }
598
599 /*!
600   \brief Show action (in all toolbars).
601   \param id action ID
602 */
603 void QtxActionToolMgr::show( const int id )
604 {
605   setShown( id, true );
606 }
607
608 /*!
609   \brief Hide action (in all toolbars).
610   \param id action ID
611 */
612 void QtxActionToolMgr::hide( const int id )
613 {
614   setShown( id, false );
615 }
616
617 /*!
618   \brief Set visibility status for toolbar action with given \a id.
619   \param id action ID
620   \param on new visibility status
621 */
622 void QtxActionToolMgr::setShown( const int id, const bool on )
623 {
624   for ( ToolBarMap::Iterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
625     setVisible( id, it.key(), on );
626 }
627
628 /*!
629   \brief Get visibility status for toolbar action with given \a id.
630   \param id action ID
631   \return \c true if action is shown in all toolbars
632 */
633 bool QtxActionToolMgr::isShown( const int id ) const
634 {
635   QList<const ToolNode*> nodes;
636   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
637   {
638     const NodeList& nl = it.value().nodes;
639     for ( NodeList::const_iterator itr = nl.begin(); itr != nl.end(); ++itr )
640     {
641       const ToolNode& node = *itr;
642       if ( node.id == id )
643         nodes.append( &node );
644     }
645   }
646
647   if ( nodes.isEmpty() )
648     return false;
649
650   bool vis = true;
651   for ( QList<const ToolNode*>::iterator itr = nodes.begin(); itr != nodes.end() && vis; ++itr )
652     vis = (*itr)->visible;
653
654   return vis;
655 }
656
657 /*!
658   \brief Check if an action with given \a id is visible in the toolbar \a tid.
659   \param id action ID
660   \param tid toolbar ID
661   \return \c true if action is shown in the toolbar
662 */
663 bool QtxActionToolMgr::isVisible( const int id, const int tid ) const
664 {
665   if ( !myToolBars.contains( tid ) )
666     return false;
667
668   bool vis = false;
669   const ToolBarInfo& inf = myToolBars[tid];
670   for ( NodeList::const_iterator it = inf.nodes.begin(); it != inf.nodes.end() && !vis; ++it )
671   {
672     const ToolNode& node = *it;
673     if ( node.id == id )
674
675       vis = node.visible;
676   }
677   return vis;
678 }
679
680 /*!
681   \brief Show/hide action with given \a id in the toolbar \a tid.
682   \param id action ID
683   \param tid toolbar ID
684   \param on new visibility status
685 */
686 void QtxActionToolMgr::setVisible( const int id, const int tid, const bool on )
687 {
688   if ( !myToolBars.contains( tid ) )
689     return;
690
691   bool changed = false;
692   NodeList& lst = myToolBars[tid].nodes;
693   for ( NodeList::iterator it = lst.begin(); it != lst.end(); ++it )
694   {
695     ToolNode& node = *it;
696     if ( node.id == id )
697     {
698       changed = changed || node.visible != on;
699       node.visible = on;
700     }
701   }
702
703   if ( changed )
704     triggerUpdate( tid );
705 }
706
707 /*!
708   \brief Load toolbar contents from the file.
709   \param fname file name
710   \param r actions reader
711   \return \c true on success and \c false on error
712 */
713 bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r )
714 {
715   ToolCreator cr( &r, this );
716   return r.read( fname, cr );
717 }
718
719 /*!
720   \brief Called when delayed content update is performed.
721
722   Customizes the content update operation.
723 */
724 void QtxActionToolMgr::updateContent()
725 {
726   if ( !isUpdatesEnabled() )
727     return;
728
729   for ( QMap<int,int>::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it )
730     updateToolBar( it.key() );
731   myUpdateIds.clear();
732 }
733
734 /*!
735   \brief Perform delayed toolbar update.
736   \param tid toolbar ID
737 */
738 void QtxActionToolMgr::triggerUpdate( const int tid )
739 {
740   myUpdateIds.insert( tid, 0 );
741   QtxActionMgr::triggerUpdate();
742 }
743
744
745 /*!
746   \class QtxActionToolMgr::ToolCreator
747   \brief Toolbars creator.
748
749   Used by Reader to create actions by reading descriptions from the file,
750   create toolbars and fill in the toolbara with the actions.
751 */
752
753 /*!
754   \brief Constructor.
755   \param r actions reader
756   \param mgr toolbar manager
757 */
758 QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r,
759                                             QtxActionToolMgr* mgr )
760 : QtxActionMgr::Creator( r ),
761   myMgr( mgr )
762 {
763 }
764
765 /*!
766   \brief Destructor.
767 */
768 QtxActionToolMgr::ToolCreator::~ToolCreator()
769 {
770 }
771
772 /*!
773   \brief Create and append to the action manager a new toolbar or toolbar action.
774   \param tag item tag name
775   \param subMenu \c true if this item is submenu (not used)
776   \param attr attributes map
777   \param tid toolbar ID
778   \return toolbar or toolbar action ID
779 */
780 int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool /*subMenu*/,
781                                            const ItemAttributes& attr, const int tid )
782 {  
783   if( !myMgr || !reader() )
784     return -1;
785
786   QString label   = reader()->option( "label",     "label"     ),
787           id      = reader()->option( "id",        "id"        ),
788           pos     = reader()->option( "pos",       "pos"       ),
789           group   = reader()->option( "group",     "group"     ),
790           tooltip = reader()->option( "tooltip",   "tooltip"   ),
791           sep     = reader()->option( "separator", "separator" ),
792           accel   = reader()->option( "accel",     "accel"     ),
793           icon    = reader()->option( "icon",      "icon"      ),
794           toggle  = reader()->option( "toggle",    "toggle"    );
795
796   int res = -1, actId = intValue( attr, id, -1 );
797   if( tid==-1 )
798     res = myMgr->createToolBar( strValue( attr, label ), intValue( attr, id, -1 ) );
799   else if( tag==sep )
800     res = myMgr->insert( separator(), tid, intValue( attr, pos, -1 ) );
801   else
802   {
803     QIcon set;
804     QPixmap pix;
805     QString name = strValue( attr, icon );
806     if( !name.isEmpty() && loadPixmap( name, pix ) )
807       set = QIcon( pix );
808
809     QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ),
810                                        QKeySequence( strValue( attr, accel ) ), myMgr );
811     QString toggleact = strValue( attr, toggle );
812     newAct->setCheckable( !toggleact.isEmpty() );
813     newAct->setChecked( toggleact.toLower() == "true" );
814         
815     connect( newAct );
816     int aid = myMgr->registerAction( newAct, actId );
817     res = myMgr->insert( aid, tid, intValue( attr, pos, -1 ) );
818   }
819
820   return res;
821 }