Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/gui.git] / src / Qtx / QtxActionMenuMgr.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxActionMenuMgr.cxx
20 // Author:    Alexander SOLOVYEV, Sergey TELKOV
21
22 #include "QtxActionMenuMgr.h"
23
24 #include "QtxAction.h"
25
26 #include <qwidget.h>
27 #include <qmenubar.h>
28 #include <qpopupmenu.h>
29 #include <qwidgetlist.h>
30 #include <qobjectlist.h>
31 #include <qmainwindow.h>
32 #include <qfile.h>
33 #include <qdom.h>
34
35 /*!
36         Class: QtxActionMenuMgr::MenuAction
37         Level: Internal
38 */
39
40 class QtxActionMenuMgr::MenuAction : public QtxAction
41 {
42 public:
43   MenuAction( const QString&, const QString&, QObject*, const bool = false );
44   virtual ~MenuAction();
45
46   virtual bool addTo( QWidget* );
47
48   virtual bool removeFrom( QWidget* );
49
50   QPopupMenu*  popup() const;
51
52 private:
53   int          myId;
54   QPopupMenu*  myPopup;
55   bool         myEmptyEnabled;
56 };
57
58 QtxActionMenuMgr::MenuAction::MenuAction( const QString& text,
59                                           const QString& menuText,
60                                           QObject*       parent,
61                                           const bool     allowEmpty )
62 : QtxAction( text, menuText, 0, parent ),
63   myId( -1 ),
64   myPopup( 0 ),
65   myEmptyEnabled( allowEmpty )
66 {
67   myPopup = new QPopupMenu();
68 }
69
70 QtxActionMenuMgr::MenuAction::~MenuAction()
71 {
72   delete myPopup;
73 }
74
75 bool QtxActionMenuMgr::MenuAction::addTo( QWidget* w )
76 {
77   if ( myId != -1 || !w )
78     return false;
79
80   if ( !w->inherits( "QPopupMenu" ) && !w->inherits( "QMenuBar" ) )
81     return false;
82
83   if ( !myPopup )
84     return false;
85
86   if ( !myEmptyEnabled && !myPopup->count() )
87     return false;
88
89   if ( w->inherits( "QPopupMenu" ) && QAction::addTo( w ) )
90   {
91     QPopupMenu* pm = (QPopupMenu*)w;
92     myId = pm->idAt( pm->count() - 1 );
93     setPopup( pm, myId, myPopup );
94   }
95   else if ( w->inherits( "QMenuBar" ) )
96   {
97     QMenuBar* mb = (QMenuBar*)w;
98     myId = iconSet().isNull() ? mb->insertItem( menuText(), myPopup ) :
99                                 mb->insertItem( iconSet(), menuText(), myPopup );
100     mb->setItemEnabled( myId, isEnabled() );
101   }
102   else
103     return false;
104
105   return true;
106 }
107
108 bool QtxActionMenuMgr::MenuAction::removeFrom( QWidget* w )
109 {
110   if ( w->inherits( "QPopupMenu" ) && QAction::removeFrom( w ) )
111     myId = -1;
112   else if ( w->inherits( "QMenuBar" ) )
113   {
114     QMenuBar* mb = (QMenuBar*)w;
115     mb->removeItem( myId );
116     myId = -1;
117   }
118
119   return myId == -1;
120 }
121
122 QPopupMenu* QtxActionMenuMgr::MenuAction::popup() const
123 {
124   return myPopup;
125 }
126
127 /*!
128         Class: QtxActionMenuMgr
129         Level: Public
130 */
131
132
133 QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p )
134 : QtxActionMgr( p ),
135 myMenu( p ? p->menuBar() : 0 )
136 {
137   myRoot.id = -1;
138   myRoot.group = -1;
139
140   if ( myMenu ) {
141     connect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
142     if ( myMenu->inherits( "QMenuBar" ) )
143       connect( myMenu, SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) );
144   }
145 }
146
147 QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p )
148 : QtxActionMgr( p ),
149 myMenu( mw )
150 {
151   myRoot.id = -1;
152   myRoot.group = -1;
153
154   if ( myMenu )
155     connect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
156 }
157
158 QtxActionMenuMgr::~QtxActionMenuMgr()
159 {
160   for ( NodeListIterator it( myRoot.children ); it.current() && myMenu; ++it )
161   {
162     QAction* a = itemAction( it.current()->id );
163     if ( !a )
164       a = menuAction( it.current()->id );
165
166     if ( a )
167       a->removeFrom( myMenu );
168   }
169
170   for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr )
171     delete itr.data();
172 }
173
174 bool QtxActionMenuMgr::isVisible( const int actId, const int place ) const
175 {
176   MenuNode* node = find( actId, place );
177   return node && node->visible;
178 }
179
180 void QtxActionMenuMgr::setVisible( const int actId, const int place, const bool v )
181 {
182   MenuNode* node = find( actId, place );
183   if ( node )
184     node->visible = v;
185 }
186
187 int QtxActionMenuMgr::insert( const int id, const QString& menus, const int group, const int idx )
188 {
189   return insert( id, QStringList::split( "|", menus ), group, idx );
190 }
191
192 int QtxActionMenuMgr::insert( QAction* a, const QString& menus, const int group, const int idx )
193 {
194   return insert( a, QStringList::split( "|", menus ), group, idx );
195 }
196
197 int QtxActionMenuMgr::insert( const int id, const QStringList& menus, const int group, const int idx )
198 {
199   int pId = createMenu( menus, -1 );
200   if ( pId == -1 )
201     return -1;
202
203   return insert( id, pId, group, idx );
204 }
205
206 int QtxActionMenuMgr::insert( QAction* a, const QStringList& menus, const int group, const int idx )
207 {
208   int pId = createMenu( menus, -1 );
209   if ( pId == -1 )
210     return -1;
211
212   return insert( a, pId, group, idx );
213 }
214
215 int QtxActionMenuMgr::insert( const int id, const int pId, const int group, const int idx )
216 {
217   if ( id == -1 )
218     return -1;
219
220   MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
221   if ( !pNode )
222     return -1;
223
224   MenuNode* node = new MenuNode( pNode );
225   node->id = id;
226   node->idx = idx;
227   node->group = group;
228
229   pNode->children.append( node );
230
231   updateMenu( pNode, false );
232
233   return node->id;
234 }
235
236 int QtxActionMenuMgr::insert( QAction* a, const int pId, const int group, const int idx )
237 {
238   return insert( registerAction( a ), pId, group, idx );
239 }
240
241 int QtxActionMenuMgr::insert( const QString& title, const int pId, const int group, const int id, const int idx, const bool allowEmpty )
242 {
243   MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
244   if ( !pNode )
245     return -1;
246
247   MenuNode* eNode = id == -1 ? 0 : find( id );
248
249   int fid = -1;
250   for ( NodeListIterator it( pNode->children ); it.current() && fid == -1; ++it )
251   {
252     if ( myMenus.contains( it.current()->id ) &&
253          clearTitle( myMenus[it.current()->id]->menuText() ) == clearTitle( title ) )
254       fid = it.current()->id;
255   }
256
257   if ( fid != -1 )
258     return fid;
259
260   MenuAction* ma = new MenuAction( clearTitle( title ), title, this, allowEmpty );
261   connect( ma->popup(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) );
262
263   MenuNode* node = new MenuNode( pNode );
264   node->group = group;
265   node->idx = idx;
266   node->id = myMenus.insert( (id == -1 || eNode ) ? generateId() : id, ma ).key();
267
268   pNode->children.append( node );
269
270   updateMenu( pNode, false );
271
272   return node->id;
273 }
274
275 int QtxActionMenuMgr::insert( const QString& title, const QString& menus, const int group, const int id, const int idx, const bool allowEmpty )
276 {
277   return insert( title, QStringList::split( "|", menus ), group, id, idx, allowEmpty );
278 }
279
280 int QtxActionMenuMgr::insert( const QString& title, const QStringList& menus, const int group, const int id, const int idx, const bool allowEmpty )
281 {
282   int pId = createMenu( menus, -1 );
283   return insert( title, pId, group, id, idx, allowEmpty );
284 }
285
286 int QtxActionMenuMgr::append( const QString& title, const int pId, const int group, const int id, const bool allowEmpty )
287 {
288   return insert( title, pId, group, id, allowEmpty );
289 }
290
291 int QtxActionMenuMgr::append( const int id, const int pId, const int group )
292 {
293   return insert( id, pId, group );
294 }
295
296 int QtxActionMenuMgr::append( QAction* a, const int pId, const int group )
297 {
298   return insert( a, pId, group );
299 }
300
301 int QtxActionMenuMgr::prepend( const QString& title, const int pId, const int group, const int id, const bool allowEmpty )
302 {
303   return insert( title, pId, group, id, 0, allowEmpty );
304 }
305
306 int QtxActionMenuMgr::prepend( const int id, const int pId, const int group )
307 {
308   return insert( id, pId, group, 0 );
309 }
310
311 int QtxActionMenuMgr::prepend( QAction* a, const int pId, const int group )
312 {
313   return insert( a, pId, group, 0 );
314 }
315
316 void QtxActionMenuMgr::remove( const int id )
317 {
318   removeMenu( id, 0 );
319   update();
320 }
321
322 void QtxActionMenuMgr::remove( const int id, const int pId, const int group )
323 {
324   MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
325   if ( !pNode )
326     return;
327
328   NodeList delNodes;
329   for ( NodeListIterator it( pNode->children ); it.current(); ++it )
330   {
331     if ( it.current()->id == id && ( it.current()->group == group || group == -1 ) )
332       delNodes.append( it.current() );
333   }
334
335   for ( NodeListIterator itr( delNodes ); itr.current(); ++itr )
336     pNode->children.remove( itr.current() );
337
338   updateMenu( pNode, false );
339 }
340
341 void QtxActionMenuMgr::show( const int id )
342 {
343   setShown( id, true );
344 }
345
346 void QtxActionMenuMgr::hide( const int id )
347 {
348   setShown( id, false );
349 }
350
351 bool QtxActionMenuMgr::isShown( const int id ) const
352 {
353   bool res = false;
354   MenuNode* node = find( id );
355   if ( node )
356     res = node->visible;
357   return res;
358 }
359
360 void QtxActionMenuMgr::setShown( const int id, const bool on )
361 {
362   NodeList aNodes;
363   find( id, aNodes );
364
365   QMap<MenuNode*, int> updMap;
366   for ( NodeListIterator it( aNodes ); it.current(); ++it )
367   {
368     if ( it.current()->visible != on )
369     {
370       it.current()->visible = on;
371       updMap.insert( it.current()->parent, 0 );
372     }
373   }
374
375   for ( QMap<MenuNode*, int>::ConstIterator itr = updMap.begin(); itr != updMap.end(); ++itr )
376     updateMenu( itr.key(), false );
377 }
378
379 void QtxActionMenuMgr::onDestroyed( QObject* obj )
380 {
381   if ( myMenu == obj )
382     myMenu = 0;
383 }
384
385 void QtxActionMenuMgr::onHighlighted( int id )
386 {
387   const QObject* snd = sender();
388   int pid = 0, realId;
389   if ( myMenu && snd == myMenu )
390     pid = -1;
391   else {
392     for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) {
393       if ( itr.data()->popup() && itr.data()->popup() == snd )
394         pid = itr.key();
395     }
396   }
397   if ( pid ) {
398     realId = findId( id, pid );
399     if ( realId != -1 ) {
400       bool updatesEnabled = isUpdatesEnabled();
401       setUpdatesEnabled( false );
402       emit menuHighlighted( pid, realId );
403       setUpdatesEnabled( updatesEnabled );
404       updateMenu( find( realId ) );
405     }
406   }
407 }
408
409 void QtxActionMenuMgr::setWidget( QWidget* mw )
410 {
411   if ( myMenu == mw )
412     return;
413
414   if ( myMenu )
415     disconnect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
416
417   myMenu = mw;
418
419   if ( myMenu )
420     connect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
421 }
422
423 QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int actId, const int pId, const bool rec ) const
424 {
425   return find( actId, find( pId ), rec );
426 }
427
428 QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int id, MenuNode* startNode, const bool rec ) const
429 {
430   MenuNode* node = 0;
431   MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
432   for ( NodeListIterator it( start->children ); it.current() && !node; ++it )
433   {
434     if ( it.current()->id == id )
435       node = it.current();
436     else if ( rec )
437       node = find( id, it.current(), rec );
438   }
439   return node;
440 }
441
442 bool QtxActionMenuMgr::find( const int id, NodeList& lst, MenuNode* startNode ) const
443 {
444   MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
445   for ( NodeListIterator it( start->children ); it.current(); ++it )
446   {
447     if ( it.current()->id == id )
448       lst.prepend( it.current() );
449
450     find( id, lst, it.current() );
451   }
452   return !lst.isEmpty();
453 }
454
455 QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, const int pId, const bool rec ) const
456 {
457   return find( title, find( pId ), rec );
458 }
459
460 bool QtxActionMenuMgr::find( const QString& title, NodeList& lst, MenuNode* startNode ) const
461 {
462   MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
463   for ( NodeListIterator it( start->children ); it.current(); ++it )
464   {
465     QAction* a = itemAction( it.current()->id );
466     if ( !a )
467       a = menuAction( it.current()->id );
468     if ( a && clearTitle( a->menuText() ) == clearTitle( title ) )
469       lst.prepend( it.current() );
470
471     find( title, lst, it.current() );
472   }
473   return !lst.isEmpty();
474 }
475
476 QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, MenuNode* startNode, const bool rec ) const
477 {
478   MenuNode* node = 0;
479   MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
480   for ( NodeListIterator it( start->children ); it.current() && !node; ++it )
481   {
482     QAction* a = itemAction( it.current()->id );
483     if ( !a )
484       a = menuAction( it.current()->id );
485     if ( a && clearTitle( a->menuText() ) == clearTitle( title ) )
486       node = it.current();
487     if ( !node && rec )
488       node = find( title, it.current(), rec );
489   }
490   return node;
491 }
492
493 int QtxActionMenuMgr::findId( const int id, const int pid ) const
494 {
495   MenuNode* start = pid != -1 ? find( pid ) : (MenuNode*)&myRoot;
496   if ( start ) {
497     for ( NodeListIterator it( start->children ); it.current(); ++it ) {
498       if ( it.current()->id == id ) return id;
499     }
500   }
501   return -1;
502 }
503
504 void QtxActionMenuMgr::removeMenu( const int id, MenuNode* startNode )
505 {
506   MenuNode* start = startNode ? startNode : &myRoot;
507   for ( NodeListIterator it( start->children ); it.current(); ++it )
508   {
509     if ( it.current()->id == id )
510       start->children.remove( it.current() );
511     else
512       removeMenu( id, it.current() );
513   }
514 }
515
516 QAction* QtxActionMenuMgr::itemAction( const int id ) const
517 {
518   return action( id );
519 }
520
521 QtxActionMenuMgr::MenuAction* QtxActionMenuMgr::menuAction( const int id ) const
522 {
523   MenuAction* a = 0;
524
525   if ( myMenus.contains( id ) )
526     a = myMenus[id];
527
528   return a;
529 }
530
531 void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bool updParent )
532 {
533   if ( !isUpdatesEnabled() )
534     return;
535
536   MenuNode* node = startNode ? startNode : &myRoot;
537
538   QWidget* mw = menuWidget( node );
539   if ( !mw )
540     return;
541
542   bool filled = checkWidget( mw );
543
544   for ( NodeListIterator it1( node->children ); it1.current(); ++it1 )
545   {
546     QAction* a = itemAction( it1.current()->id );
547     if ( !a )
548       a = menuAction( it1.current()->id );
549
550     if ( a )
551       a->removeFrom( mw );
552   }
553
554   if ( mw->inherits( "QMenuBar" ) )
555     ((QMenuBar*)mw)->clear();
556   else if ( mw->inherits( "QPopupMenu" ) )
557     ((QPopupMenu*)mw)->clear();
558
559   QMap<int, NodeList> idMap;
560   for ( NodeListIterator it2( node->children ); it2.current(); ++it2 )
561   {
562     NodeList& lst = idMap[it2.current()->group];
563     int idx = it2.current()->idx;
564     if ( idx < 0 || idx >= lst.count() )
565       lst.append( it2.current() );
566     else
567       lst.insert( idx, it2.current() );
568   }
569
570   QIntList groups = idMap.keys();
571   qHeapSort( groups );
572
573   groups.remove( -1 );
574   groups.append( -1 );
575
576   for ( QIntList::const_iterator gIt = groups.begin(); gIt != groups.end(); ++gIt )
577   {
578     if ( !idMap.contains( *gIt ) )
579       continue;
580
581     const NodeList& lst = idMap[*gIt];
582     for ( NodeListIterator iter( lst ); iter.current(); ++iter )
583     {
584       MenuNode* par = iter.current()->parent;
585       if ( !isVisible( iter.current()->id, par ? par->id : -1 ) )
586         continue;
587
588       if ( rec )
589         updateMenu( iter.current(), rec, false );
590
591       QAction* a = itemAction( iter.current()->id );
592       if ( !a )
593         a = menuAction( iter.current()->id );
594       if ( a ) {
595         QMenuData* md = dynamic_cast<QMenuData*>( mw );
596         int cnt = 0;
597         if ( md ) cnt = md->count();
598         a->addTo( mw );
599         if ( md && md->count() - cnt == 1 ) { //&& iter.current()->id > 0
600           int lid = md->idAt( cnt ); 
601           QMenuItem* mi = md->findItem( lid );
602           if ( mi && !mi->isSeparator() )
603             md->setId( cnt, iter.current()->id );
604         }
605       }
606     }
607   }
608
609   simplifySeparators( mw );
610
611   if ( updParent && node->parent && filled != checkWidget( mw ) )
612     updateMenu( node->parent, false );
613 }
614
615 void QtxActionMenuMgr::internalUpdate()
616 {
617   if ( isUpdatesEnabled() )
618     updateMenu();
619 }
620
621 bool QtxActionMenuMgr::checkWidget( QWidget* wid ) const
622 {
623   if ( !wid )
624     return false;
625
626   QMenuData* md = 0;
627   if ( wid->inherits( "QPopupMenu" ) )
628     md = (QPopupMenu*)wid;
629   else if ( wid->inherits( "QMenuBar" ) )
630     md = (QMenuBar*)wid;
631
632   return md->count();
633 }
634
635 QWidget* QtxActionMenuMgr::menuWidget( MenuNode* node) const
636 {
637   if ( !node || node == &myRoot )
638      return myMenu;
639
640   if ( !myMenus.contains( node->id ) || !myMenus[node->id] )
641     return 0;
642
643   return myMenus[node->id]->popup();
644 }
645
646 void QtxActionMenuMgr::simplifySeparators( QWidget* wid )
647 {
648   if ( wid && wid->inherits( "QPopupMenu" ) )
649     Qtx::simplifySeparators( (QPopupMenu*)wid, false );
650 }
651
652 QString QtxActionMenuMgr::clearTitle( const QString& txt ) const
653 {
654   QString res = txt;
655
656   for ( int i = 0; i < (int)res.length(); i++ )
657   {
658     if ( res.at( i ) == '&' )
659       res.remove( i--, 1 );
660   }
661
662   return res;
663 }
664
665 int QtxActionMenuMgr::createMenu( const QStringList& lst, const int pId )
666 {
667   if ( lst.isEmpty() )
668     return -1;
669
670   QStringList sl( lst );
671
672   QString title = sl.last().stripWhiteSpace();
673   sl.remove( sl.fromLast() );
674
675   int parentId = sl.isEmpty() ? pId : createMenu( sl, pId );
676
677   return insert( title, parentId, -1 );
678 }
679
680 bool QtxActionMenuMgr::load( const QString& fname, QtxActionMgr::Reader& r )
681 {
682   MenuCreator cr( &r, this );
683   return r.read( fname, cr );
684 }
685
686 bool QtxActionMenuMgr::containsMenu( const QString& title, const int pid ) const
687 {
688   return (bool)find( title, pid, false );
689 }
690
691 bool QtxActionMenuMgr::containsMenu( const int id, const int pid ) const
692 {
693   return (bool)find( id, pid, false );
694 }
695
696 /*!
697         Class: QtxActionMenuMgr::MenuCreator
698         Level: Public
699 */
700
701 QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r,
702                                             QtxActionMenuMgr* mgr )
703 : QtxActionMgr::Creator( r ),
704   myMgr( mgr )
705 {
706 }
707
708 QtxActionMenuMgr::MenuCreator::~MenuCreator()
709 {
710 }
711
712 int QtxActionMenuMgr::MenuCreator::append( const QString& tag, const bool subMenu,
713                                            const ItemAttributes& attr, const int pId )
714 {
715   if( !myMgr || !reader() )
716     return -1;
717
718   QString label   = reader()->option( "label",     "label"     ),
719           id      = reader()->option( "id",        "id"        ),
720           pos     = reader()->option( "pos",       "pos"       ),
721           group   = reader()->option( "group",     "group"     ),
722           tooltip = reader()->option( "tooltip",   "tooltip"   ),
723           sep     = reader()->option( "separator", "separator" ),
724           accel   = reader()->option( "accel",     "accel"     ),
725           icon    = reader()->option( "icon",      "icon"      ),
726           toggle  = reader()->option( "toggle",    "toggle"    );
727
728   int res = -1, actId = intValue( attr, id, -1 );
729
730   if( subMenu )
731     res = myMgr->insert( strValue( attr, label ), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) );
732   else if( tag==sep )
733     res = myMgr->insert( separator(), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) );
734   else
735   {
736     QPixmap pix; QIconSet set;
737     QString name = strValue( attr, icon );
738     if( !name.isEmpty() && loadPixmap( name, pix ) )
739       set = QIconSet( pix );
740
741     QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set,
742                                        strValue( attr, label ), 
743                                        QKeySequence( strValue( attr, accel ) ),
744                                        myMgr );
745     newAct->setToolTip( strValue( attr, tooltip ) );
746     QString toggleact = strValue( attr, toggle );
747     newAct->setToggleAction( !toggleact.isEmpty() );
748     newAct->setOn( toggleact.lower()=="true" );
749         
750     connect( newAct );
751     int aid = myMgr->registerAction( newAct, actId );
752     res = myMgr->insert( aid, pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) );
753   }
754
755   return res;
756 }