Salome HOME
e9c8e052799f47d3f1350132f7c29c46bdef419a
[modules/gui.git] / src / Qtx / QtxActionToolMgr.cxx
1 // Copyright (C) 2007-2022  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   The parameter \a name can be specified to give an unique string identifier to the toolbar.
117   This can be useful in the multi-language environment where identifier of the toolbar should
118   not be dependant on the language chosen (e.g. to store positions of toolbars of main menu
119   in the preferences).
120
121   \param title toolbar title
122   \param name toolbar name (identifier)
123   \param tid requested toolbar ID
124   \param mw parent main window; if it is null, the tool manager's main window is used
125   \param vis show toolbar visible immediately after creation (true by default)
126   \return id of created/found toolbar
127 */
128 int QtxActionToolMgr::createToolBar( const QString& title, const QString& name, const int tid, QMainWindow* mw, bool vis )
129 {
130   return createToolBar( title, name, true, Qt::AllToolBarAreas, tid, mw, vis );
131 }
132
133 /*!
134   \brief Create toolbar and assign \a id to it.
135
136   If \a tid is less than 0, the identifier is generated automatically.
137   If toolbar with given \a tid is already registered, the toolbar will not be created.
138
139   The parameter \a name can be specified to give an unique string identifier to the toolbar.
140   This can be useful in the multi-language environment where identifier of the toolbar should
141   not be dependant on the language chosen (e.g. to store positions of toolbars of main menu
142   in the preferences).
143
144   \param title toolbar title
145   \param name toolbar name (identifier)
146   \param floatable if \c true, new toolbar is made floatable
147   \param dockAreas dock areas of the main window where the new toolbar can be situated
148   \param tid requested toolbar ID
149   \param mw parent main window; if it is null, the tool manager's main window is used
150   \param vis show toolbar visible immediately after creation (true by default)
151   \return id of created/found toolbar
152 */
153 int QtxActionToolMgr::createToolBar( const QString& title, const QString& name, bool floatable, Qt::ToolBarAreas dockAreas, 
154                                      int tid, QMainWindow* mw, bool vis )
155 {
156   static int _toolBarId = -1;
157
158   int tbId = -1;
159   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it )
160   {
161     if( it.value().toolBar->windowTitle().toLower() == title.toLower() &&
162         ( !mw || it.value().toolBar->parent()==mw ) )
163       tbId = it.key();
164   }
165
166   if ( tbId != -1 )
167     return tbId;
168
169   QMainWindow* tbw = mw ? mw : mainWindow();
170   QToolBar* tb = find( title, tbw );
171
172   tbId = tid < 0 ? --_toolBarId : tid;
173
174   myToolBars.insert( tbId, ToolBarInfo() );
175   ToolBarInfo& tInfo = myToolBars[tbId];
176
177   if ( !tb )
178   {
179     tb = new QtxToolBar( true, tbw );
180     //tb->setVisible( false );  // VSR: create toolbar visible initially
181     tb->setFloatable( floatable );
182     tb->setAllowedAreas( dockAreas );
183     tb->setMovable( dockAreas & Qt::AllToolBarAreas );
184     //mainWindow()->addToolBar( tb );
185     tb->setWindowTitle( title );
186     tb->setObjectName( name.isEmpty() ? title : name );
187     tb->setToolTip( title );
188     if ( !vis )
189       QApplication::postEvent( tb, new QHideEvent());
190    }
191
192   tInfo.toolBar = tb;
193   connect( tInfo.toolBar, SIGNAL( destroyed() ), this, SLOT( onToolBarDestroyed() ) );
194
195   return tbId;
196 }
197
198 /*!
199   \brief Create toolbar and assign \a id to it.
200
201   If \a tid is less than 0, the identifier is generated automatically.
202   If toolbar with given \a tid is already registered, the toolbar will not be created.
203
204   \param title toolbar title
205   \param floatable if \c true, new toolbar is made floatable
206   \param dockAreas dock areas of the main window where the new toolbar can be situated
207   \param tid requested toolbar ID
208   \param mw parent main window; if it is null, the tool manager's main window is used
209   \param vis show toolbar visible immediately after creation (true by default)
210   \return id of created/found toolbar
211 */
212 int QtxActionToolMgr::createToolBar( const QString& title, bool floatable, Qt::ToolBarAreas dockAreas, 
213                                      int tid, QMainWindow* mw, bool vis )
214 {
215   return createToolBar( title, QString(), floatable, dockAreas, tid, mw, vis );
216 }
217
218 /*!
219   \brief Search toolbar with given \a title owned by main window \mw. 
220   \param title toolbar title
221   \param mw main window
222   \return toolbar or 0 if it is not found
223 */
224 QToolBar* QtxActionToolMgr::find( const QString& title, QMainWindow* mw ) const
225 {
226   if ( !mw )
227     return 0;
228
229   QString pattern = title.toLower();
230
231   QToolBar* res = 0;
232   QList<QToolBar*> toolbars = mw->findChildren<QToolBar*>();
233   for ( QList<QToolBar*>::iterator it = toolbars.begin(); it != toolbars.end() && !res; ++it )
234   {
235     if ( (*it)->windowTitle().toLower() == pattern )
236       res = *it;
237   }
238   return res;
239 }
240
241 /*!
242   \brief Remove toolbar.
243   \param tid toolbar ID
244 */
245 void QtxActionToolMgr::removeToolBar( const int tid )
246 {
247   if ( !myToolBars.contains( tid ) )
248     return;
249
250   delete myToolBars[tid].toolBar;
251   myToolBars.remove( tid );
252 }
253
254 /*!
255   \brief Remove toolbar.
256   \param title toolbar title
257 */
258 void QtxActionToolMgr::removeToolBar( const QString& title )
259 {
260   removeToolBar( find( title ) );
261 }
262
263 /*!
264   \brief Insert action into toolbar.
265   \param id action ID
266   \param tid toolbar ID
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( const int id, const int tid, const int idx )
271 {
272   if ( !contains( id ) || !hasToolBar( tid ) )
273     return -1;
274 /*
275   if ( containsAction( id, tid ) )
276     remove( id, tid );
277 */
278   ToolNode node( id );
279
280   NodeList& list = myToolBars[tid].nodes;
281   int index = idx < 0 ? list.count() : qMin( idx, (int)list.count() );
282   list.insert( index, node );
283   triggerUpdate( tid );
284
285   return id;
286 }
287
288 /*!
289   \brief Insert action into toolbar.
290   \param a action
291   \param tid toolbar ID
292   \param idx action index in the toolbar (if < 0, action is appended to the end)
293   \return action ID
294 */
295 int QtxActionToolMgr::insert( QAction* a, const int tid, const int idx )
296 {
297   return insert( registerAction( a ), tid, idx );
298 }
299
300 /*!
301   \brief Insert action into toolbar.
302   \param id action ID
303   \param title toolbar title
304   \param idx action index in the toolbar (if < 0, action is appended to the end)
305   \return action ID
306 */
307 int QtxActionToolMgr::insert( const int id, const QString& title, const int idx )
308 {
309   return insert( id, createToolBar( title ), idx );
310 }
311
312 /*!
313   \brief Insert action into toolbar.
314   \param a action
315   \param title toolbar title
316   \param idx action index in the toolbar (if < 0, action is appended to the end)
317   \return action ID
318 */
319 int QtxActionToolMgr::insert( QAction* a, const QString& title, const int idx )
320 {
321   return insert( registerAction( a ), createToolBar( title ), idx );
322 }
323
324 /*!
325   \brief Append action to the end of toolbar.
326   \param id action ID
327   \param tid toolbar ID
328   \return action ID
329 */
330 int QtxActionToolMgr::append( const int id, const int tid )
331 {
332   return insert( id, tid );
333 }
334
335 /*!
336   \brief Append action to the end of toolbar.
337   \param a action
338   \param tid toolbar ID
339   \return action ID
340 */
341 int QtxActionToolMgr::append( QAction* a, const int tid )
342 {
343   return insert( a, tid );
344 }
345
346 /*!
347   \brief Append action to the end of toolbar.
348   \param id action ID
349   \param title toolbar title
350   \return action ID
351 */
352 int QtxActionToolMgr::append( const int id, const QString& title )
353 {
354   return insert( id, title );
355 }
356
357 /*!
358   \brief Append action to the end of toolbar.
359   \param a action
360   \param title toolbar title
361   \return action ID
362 */
363 int QtxActionToolMgr::append( QAction* a, const QString& title )
364 {
365   return insert( a, title );
366 }
367
368 /*!
369   \brief Insert action to the beginning of toolbar.
370   \param id action ID
371   \param tid toolbar ID
372   \return action ID
373 */
374 int QtxActionToolMgr::prepend( const int id, const int tid )
375 {
376   return insert( id, tid, 0 );
377 }
378
379 /*!
380   \brief Insert action to the beginning of toolbar.
381   \param a action
382   \param tid toolbar ID
383   \return action ID
384 */
385 int QtxActionToolMgr::prepend( QAction* a, const int tid )
386 {
387   return insert( a, tid, 0 );
388 }
389
390 /*!
391   \brief Insert action to the beginning of toolbar.
392   \param id action ID
393   \param title toolbar title
394   \return action ID
395 */
396 int QtxActionToolMgr::prepend( const int id, const QString& title )
397 {
398   return insert( id, title, 0 );
399 }
400
401 /*!
402   \brief Insert action to the beginning of toolbar.
403   \param a action ID
404   \param title toolbar title
405   \return action ID
406 */
407 int QtxActionToolMgr::prepend( QAction* a, const QString& title )
408 {
409   return insert( a, title, 0 );
410 }
411
412 /*!
413   \brief Remove action from toolbar.
414   \param id action ID
415   \param tid toolbar ID
416 */
417 void QtxActionToolMgr::remove( const int id, const int tid )
418 {
419   if ( !myToolBars.contains( tid ) )
420     return;
421
422   NodeList newList;
423   const NodeList& nodes = myToolBars[tid].nodes;
424   for ( NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it )
425   {
426     if ( (*it).id != id )
427       newList.append( *it );
428   }
429
430   myToolBars[tid].nodes = newList;
431
432   triggerUpdate( tid );
433 }
434
435 /*!
436   \brief Remove action from toolbar.
437   \param id action ID
438   \param title toolbar title
439 */
440 void QtxActionToolMgr::remove( const int id, const QString& title )
441 {
442   remove( id, find( title ) );
443 }
444
445 /*!
446   \brief Remove all actions from toolbar.
447   \param tid toolbar ID
448 */
449 void QtxActionToolMgr::clear( const int tid )
450 {
451   if ( !myToolBars.contains( tid ) )
452     return;
453
454   myToolBars[tid].nodes.clear();
455
456   triggerUpdate( tid );
457 }
458
459 /*!
460   \brief Remove all actions from toolbar.
461   \param title toolbar title
462 */
463 void QtxActionToolMgr::clear( const QString& title )
464 {
465   clear( find( title ) );
466 }
467
468 /*!
469   \brief Get toolbar by given \a tid.
470   \param tid toolbar ID
471   \return toolbar or 0 if it is not found
472 */
473 QToolBar* QtxActionToolMgr::toolBar( const int tid ) const
474 {
475   QToolBar* tb = 0;
476   if ( myToolBars.contains( tid ) )
477     tb = myToolBars[tid].toolBar;
478   return tb;
479 }
480
481 /*!
482   \brief Get toolbar by given \a title.
483   \param title toolbar title
484   \return toolbar or 0 if it is not found
485 */
486 QToolBar* QtxActionToolMgr::toolBar( const QString& title ) const
487 {
488   return toolBar( find( title ) );
489 }
490
491 /*!
492   \bried Get all registered toolbars identifiers
493   \return list of toolbars ids
494 */
495 QIntList QtxActionToolMgr::toolBarsIds() const
496 {
497   return myToolBars.keys();
498 }
499
500 /*!
501   \brief Check if toolbar with given \a id already registered.
502   \param tid toolbar ID
503   \return \c true if toolbar is registered in the toolbar manager
504 */
505 bool QtxActionToolMgr::hasToolBar( const int tid ) const
506 {
507   return myToolBars.contains( tid );
508 }
509
510 /*!
511   \brief Check if toolbar with given \a id already registered.
512   \param title toolbar title
513   \return \c true if toolbar is registered in the toolbar manager
514 */
515 bool QtxActionToolMgr::hasToolBar( const QString& title ) const
516 {
517   return find( title ) != -1;
518 }
519
520 /*!
521   \brief Check if toolbar contains given action.
522   \param id action ID
523   \param tid toolbar ID
524   \return \c true if toolbar contains action
525 */
526 bool QtxActionToolMgr::containsAction( const int id, const int tid ) const
527 {
528   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
529   {
530     if ( tid == -1 || it.key() == tid )
531     {
532       const NodeList& list = it.value().nodes;
533       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit )
534         if ( (*nit).id == id )
535           return true;
536     }
537   }
538   return false;
539 }
540
541 /*!
542   \brief Get index of the action \a id within the toolbar \a tid
543   \param id action ID
544   \param tid toolbar ID
545   \return index of the action in the toolbar or -1 if action is not contained in the toolbar
546 */
547 int QtxActionToolMgr::index( const int id, const int tid ) const
548 {
549   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
550   {
551     if ( it.key() == tid )
552     {
553       const NodeList& list = it.value().nodes;
554       int idx = 0;
555       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit, ++idx )
556         if ( (*nit).id == id ) return idx;
557     }
558   }
559   return -1;
560 }
561
562 /*!
563   \brief Called when toolbar is destroyed.
564
565   Clears internal pointer to the toolbar to disable crashes.
566 */
567 void QtxActionToolMgr::onToolBarDestroyed()
568 {
569   myToolBars.remove( find( (QToolBar*)sender() ) );
570 }
571
572 /*!
573   \brief Search toolbar by given \a name.
574   \param title toolbar title
575   \return toolbar ID or -1 if it is not found
576 */
577 int QtxActionToolMgr::find( const QString& title ) const
578 {
579   int id = -1;
580   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
581   {
582     if ( it.value().toolBar->windowTitle() == title )
583       id = it.key();
584   }
585   return id;
586 }
587
588 /*!
589   \brief Get toolbar identifier.
590   \param tb toolbar
591   \return toolbar ID or -1 if toolbar is not registered
592 */
593 int QtxActionToolMgr::find( QToolBar* tb ) const
594 {
595   int id = -1;
596   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
597   {
598     if ( it.value().toolBar == tb )
599       id = it.key();
600   }
601   return id;
602 }
603
604 /*!
605   \brief Update toolbar.
606   \param tid toolbar ID
607 */
608 void QtxActionToolMgr::updateToolBar( const int tid )
609 {
610   if ( !isUpdatesEnabled() )
611     return;
612
613   if ( !myToolBars.contains( tid ) )
614     return;
615
616   QToolBar* tb = myToolBars[tid].toolBar;
617   const NodeList& list = myToolBars[tid].nodes;
618
619   for ( NodeList::const_iterator it = list.begin(); it != list.end(); ++it )
620   {
621     QAction* a = action( (*it).id );
622     tb->removeAction( a );
623 //    if ( a )
624 //      a->removeFrom( tb );
625   }
626
627   tb->clear();
628
629   for ( NodeList::const_iterator itr = list.begin(); itr != list.end(); ++itr )
630   {
631     if ( !isVisible( (*itr).id, tid ) )
632       continue;
633
634     QAction* a = action( (*itr).id );
635     tb->addAction( a );
636 //    if ( a )
637 //      a->addTo( tb );
638   }
639
640   simplifySeparators( tb );
641   
642   // fix of 19921 -->
643   if ( !tb->isVisible() )
644     tb->adjustSize();
645   // fix of 19921 <--
646 }
647
648 /*!
649   \brief Update all registered toolbars.
650 */
651 void QtxActionToolMgr::internalUpdate()
652 {
653   if ( !isUpdatesEnabled() )
654     return;
655
656   for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 )
657     updateToolBar( it1.key() );
658
659   myUpdateIds.clear();
660 }
661
662 /*!
663   \brief Remove extra separators from the toolbar.
664   \param tb toolbar
665 */
666 void QtxActionToolMgr::simplifySeparators( QToolBar* tb )
667 {
668   Qtx::simplifySeparators( tb );
669 }
670
671 /*!
672   \brief Show action (in all toolbars).
673   \param id action ID
674 */
675 void QtxActionToolMgr::show( const int id )
676 {
677   setShown( id, true );
678 }
679
680 /*!
681   \brief Hide action (in all toolbars).
682   \param id action ID
683 */
684 void QtxActionToolMgr::hide( const int id )
685 {
686   setShown( id, false );
687 }
688
689 /*!
690   \brief Set visibility status for toolbar action with given \a id.
691   \param id action ID
692   \param on new visibility status
693 */
694 void QtxActionToolMgr::setShown( const int id, const bool on )
695 {
696   for ( ToolBarMap::Iterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
697     setVisible( id, it.key(), on );
698 }
699
700 /*!
701   \brief Get visibility status for toolbar action with given \a id.
702   \param id action ID
703   \return \c true if action is shown in all toolbars
704 */
705 bool QtxActionToolMgr::isShown( const int id ) const
706 {
707   QList<const ToolNode*> nodes;
708   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
709   {
710     const NodeList& nl = it.value().nodes;
711     for ( NodeList::const_iterator itr = nl.begin(); itr != nl.end(); ++itr )
712     {
713       const ToolNode& node = *itr;
714       if ( node.id == id )
715         nodes.append( &node );
716     }
717   }
718
719   if ( nodes.isEmpty() )
720     return false;
721
722   bool vis = true;
723   for ( QList<const ToolNode*>::iterator itr = nodes.begin(); itr != nodes.end() && vis; ++itr )
724     vis = (*itr)->visible;
725
726   return vis;
727 }
728
729 /*!
730   \brief Check if an action with given \a id is visible in the toolbar \a tid.
731   \param id action ID
732   \param tid toolbar ID
733   \return \c true if action is shown in the toolbar
734 */
735 bool QtxActionToolMgr::isVisible( const int id, const int tid ) const
736 {
737   if ( !myToolBars.contains( tid ) )
738     return false;
739
740   bool vis = false;
741   const ToolBarInfo& inf = myToolBars[tid];
742   for ( NodeList::const_iterator it = inf.nodes.begin(); it != inf.nodes.end() && !vis; ++it )
743   {
744     const ToolNode& node = *it;
745     if ( node.id == id )
746
747       vis = node.visible;
748   }
749   return vis;
750 }
751
752 /*!
753   \brief Show/hide action with given \a id in the toolbar \a tid.
754   \param id action ID
755   \param tid toolbar ID
756   \param on new visibility status
757 */
758 void QtxActionToolMgr::setVisible( const int id, const int tid, const bool on )
759 {
760   if ( !myToolBars.contains( tid ) )
761     return;
762
763   bool changed = false;
764   NodeList& lst = myToolBars[tid].nodes;
765   for ( NodeList::iterator it = lst.begin(); it != lst.end(); ++it )
766   {
767     ToolNode& node = *it;
768     if ( node.id == id )
769     {
770       changed = changed || node.visible != on;
771       node.visible = on;
772     }
773   }
774
775   if ( changed ) {
776     triggerUpdate( tid );
777     updateContent();
778   }
779 }
780
781 /*!
782   \brief Load toolbar contents from the file.
783   \param fname file name
784   \param r actions reader
785   \return \c true on success and \c false on error
786 */
787 bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r )
788 {
789   ToolCreator cr( &r, this );
790   return r.read( fname, cr );
791 }
792
793 /*!
794   \brief Called when delayed content update is performed.
795
796   Customizes the content update operation.
797 */
798 void QtxActionToolMgr::updateContent()
799 {
800   if ( !isUpdatesEnabled() )
801     return;
802
803   for ( QMap<int,int>::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it )
804     updateToolBar( it.key() );
805   myUpdateIds.clear();
806 }
807
808 /*!
809   \brief Perform delayed toolbar update.
810   \param tid toolbar ID
811 */
812 void QtxActionToolMgr::triggerUpdate( const int tid )
813 {
814   myUpdateIds.insert( tid, 0 );
815   QtxActionMgr::triggerUpdate();
816 }
817
818
819 /*!
820   \class QtxActionToolMgr::ToolCreator
821   \brief Toolbars creator.
822
823   Used by Reader to create actions by reading descriptions from the file,
824   create toolbars and fill in the toolbara with the actions.
825 */
826
827 /*!
828   \brief Constructor.
829   \param r actions reader
830   \param mgr toolbar manager
831 */
832 QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r,
833                                             QtxActionToolMgr* mgr )
834 : QtxActionMgr::Creator( r ),
835   myMgr( mgr )
836 {
837 }
838
839 /*!
840   \brief Destructor.
841 */
842 QtxActionToolMgr::ToolCreator::~ToolCreator()
843 {
844 }
845
846 /*!
847   \brief Create and append to the action manager a new toolbar or toolbar action.
848   \param tag item tag name
849   \param subMenu \c true if this item is submenu (not used)
850   \param attr attributes map
851   \param tid toolbar ID
852   \return toolbar or toolbar action ID
853 */
854 int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool /*subMenu*/,
855                                            const ItemAttributes& attr, const int tid )
856 {  
857   if( !myMgr || !reader() )
858     return -1;
859
860   QString label   = reader()->option( "label",     "label"     ),
861           id      = reader()->option( "id",        "id"        ),
862           pos     = reader()->option( "pos",       "pos"       ),
863           group   = reader()->option( "group",     "group"     ),
864           tooltip = reader()->option( "tooltip",   "tooltip"   ),
865           sep     = reader()->option( "separator", "separator" ),
866           accel   = reader()->option( "accel",     "accel"     ),
867           icon    = reader()->option( "icon",      "icon"      ),
868           toggle  = reader()->option( "toggle",    "toggle"    );
869
870   int res = -1, actId = intValue( attr, id, -1 );
871   if( tid==-1 )
872     res = myMgr->createToolBar( strValue( attr, label ), intValue( attr, id, -1 ) );
873   else if( tag==sep )
874     res = myMgr->insert( separator(), tid, intValue( attr, pos, -1 ) );
875   else
876   {
877     QIcon set;
878     QPixmap pix;
879     QString name = strValue( attr, icon );
880     if( !name.isEmpty() && loadPixmap( name, pix ) )
881       set = QIcon( pix );
882
883     QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ),
884                                        QKeySequence( strValue( attr, accel ) ), myMgr );
885     QString toggleact = strValue( attr, toggle );
886     newAct->setCheckable( !toggleact.isEmpty() );
887     newAct->setChecked( toggleact.toLower() == "true" );
888         
889     connect( newAct );
890     int aid = myMgr->registerAction( newAct, actId );
891     res = myMgr->insert( aid, tid, intValue( attr, pos, -1 ) );
892   }
893
894   return res;
895 }