Salome HOME
Merge branch 'V8_0_BR'
[modules/gui.git] / src / Qtx / QtxActionToolMgr.cxx
1 // Copyright (C) 2007-2015  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 Get toolbar by given \a tid.
447   \param tid toolbar ID
448   \return toolbar or 0 if it is not found
449 */
450 QToolBar* QtxActionToolMgr::toolBar( const int tid ) const
451 {
452   QToolBar* tb = 0;
453   if ( myToolBars.contains( tid ) )
454     tb = myToolBars[tid].toolBar;
455   return tb;
456 }
457
458 /*!
459   \brief Get toolbar by given \a title.
460   \param title toolbar title
461   \return toolbar or 0 if it is not found
462 */
463 QToolBar* QtxActionToolMgr::toolBar( const QString& title ) const
464 {
465   return toolBar( find( title ) );
466 }
467
468 /*!
469   \bried Get all registered toolbars identifiers
470   \return list of toolbars ids
471 */
472 QIntList QtxActionToolMgr::toolBarsIds() const
473 {
474   return myToolBars.keys();
475 }
476
477 /*!
478   \brief Check if toolbar with given \a id already registered.
479   \param tid toolbar ID
480   \return \c true if toolbar is registered in the toolbar manager
481 */
482 bool QtxActionToolMgr::hasToolBar( const int tid ) const
483 {
484   return myToolBars.contains( tid );
485 }
486
487 /*!
488   \brief Check if toolbar with given \a id already registered.
489   \param title toolbar title
490   \return \c true if toolbar is registered in the toolbar manager
491 */
492 bool QtxActionToolMgr::hasToolBar( const QString& title ) const
493 {
494   return find( title ) != -1;
495 }
496
497 /*!
498   \brief Check if toolbar contains given action.
499   \param id action ID
500   \param tid toolbar ID
501   \return \c true if toolbar contains action
502 */
503 bool QtxActionToolMgr::containsAction( const int id, const int tid ) const
504 {
505   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
506   {
507     if ( tid == -1 || it.key() == tid )
508     {
509       const NodeList& list = it.value().nodes;
510       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit )
511         if ( (*nit).id == id )
512           return true;
513     }
514   }
515   return false;
516 }
517
518 /*!
519   \brief Get index of the action \a id within the toolbar \a tid
520   \param id action ID
521   \param tid toolbar ID
522   \return index of the action in the toolbar or -1 if action is not contained in the toolbar
523 */
524 int QtxActionToolMgr::index( const int id, const int tid ) const
525 {
526   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
527   {
528     if ( it.key() == tid )
529     {
530       const NodeList& list = it.value().nodes;
531       int idx = 0;
532       for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit, ++idx )
533         if ( (*nit).id == id ) return idx;
534     }
535   }
536   return -1;
537 }
538
539 /*!
540   \brief Called when toolbar is destroyed.
541
542   Clears internal pointer to the toolbar to disable crashes.
543 */
544 void QtxActionToolMgr::onToolBarDestroyed()
545 {
546   myToolBars.remove( find( (QToolBar*)sender() ) );
547 }
548
549 /*!
550   \brief Search toolbar by given \a name.
551   \param title toolbar title
552   \return toolbar ID or -1 if it is not found
553 */
554 int QtxActionToolMgr::find( const QString& title ) const
555 {
556   int id = -1;
557   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
558   {
559     if ( it.value().toolBar->windowTitle() == title )
560       id = it.key();
561   }
562   return id;
563 }
564
565 /*!
566   \brief Get toolbar identifier.
567   \param tb toolbar
568   \return toolbar ID or -1 if toolbar is not registered
569 */
570 int QtxActionToolMgr::find( QToolBar* tb ) const
571 {
572   int id = -1;
573   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
574   {
575     if ( it.value().toolBar == tb )
576       id = it.key();
577   }
578   return id;
579 }
580
581 /*!
582   \brief Update toolbar.
583   \param tid toolbar ID
584 */
585 void QtxActionToolMgr::updateToolBar( const int tid )
586 {
587   if ( !isUpdatesEnabled() )
588     return;
589
590   if ( !myToolBars.contains( tid ) )
591     return;
592
593   QToolBar* tb = myToolBars[tid].toolBar;
594   const NodeList& list = myToolBars[tid].nodes;
595
596   for ( NodeList::const_iterator it = list.begin(); it != list.end(); ++it )
597   {
598     QAction* a = action( (*it).id );
599     tb->removeAction( a );
600 //    if ( a )
601 //      a->removeFrom( tb );
602   }
603
604   tb->clear();
605
606   for ( NodeList::const_iterator itr = list.begin(); itr != list.end(); ++itr )
607   {
608     if ( !isVisible( (*itr).id, tid ) )
609       continue;
610
611     QAction* a = action( (*itr).id );
612     tb->addAction( a );
613 //    if ( a )
614 //      a->addTo( tb );
615   }
616
617   simplifySeparators( tb );
618   
619   // fix of 19921 -->
620   if ( !tb->isVisible() )
621     tb->adjustSize();
622   // fix of 19921 <--
623 }
624
625 /*!
626   \brief Update all registered toolbars.
627 */
628 void QtxActionToolMgr::internalUpdate()
629 {
630   if ( !isUpdatesEnabled() )
631     return;
632
633   for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 )
634     updateToolBar( it1.key() );
635
636   myUpdateIds.clear();
637 }
638
639 /*!
640   \brief Remove extra separators from the toolbar.
641   \param tb toolbar
642 */
643 void QtxActionToolMgr::simplifySeparators( QToolBar* tb )
644 {
645   Qtx::simplifySeparators( tb );
646 }
647
648 /*!
649   \brief Show action (in all toolbars).
650   \param id action ID
651 */
652 void QtxActionToolMgr::show( const int id )
653 {
654   setShown( id, true );
655 }
656
657 /*!
658   \brief Hide action (in all toolbars).
659   \param id action ID
660 */
661 void QtxActionToolMgr::hide( const int id )
662 {
663   setShown( id, false );
664 }
665
666 /*!
667   \brief Set visibility status for toolbar action with given \a id.
668   \param id action ID
669   \param on new visibility status
670 */
671 void QtxActionToolMgr::setShown( const int id, const bool on )
672 {
673   for ( ToolBarMap::Iterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
674     setVisible( id, it.key(), on );
675 }
676
677 /*!
678   \brief Get visibility status for toolbar action with given \a id.
679   \param id action ID
680   \return \c true if action is shown in all toolbars
681 */
682 bool QtxActionToolMgr::isShown( const int id ) const
683 {
684   QList<const ToolNode*> nodes;
685   for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
686   {
687     const NodeList& nl = it.value().nodes;
688     for ( NodeList::const_iterator itr = nl.begin(); itr != nl.end(); ++itr )
689     {
690       const ToolNode& node = *itr;
691       if ( node.id == id )
692         nodes.append( &node );
693     }
694   }
695
696   if ( nodes.isEmpty() )
697     return false;
698
699   bool vis = true;
700   for ( QList<const ToolNode*>::iterator itr = nodes.begin(); itr != nodes.end() && vis; ++itr )
701     vis = (*itr)->visible;
702
703   return vis;
704 }
705
706 /*!
707   \brief Check if an action with given \a id is visible in the toolbar \a tid.
708   \param id action ID
709   \param tid toolbar ID
710   \return \c true if action is shown in the toolbar
711 */
712 bool QtxActionToolMgr::isVisible( const int id, const int tid ) const
713 {
714   if ( !myToolBars.contains( tid ) )
715     return false;
716
717   bool vis = false;
718   const ToolBarInfo& inf = myToolBars[tid];
719   for ( NodeList::const_iterator it = inf.nodes.begin(); it != inf.nodes.end() && !vis; ++it )
720   {
721     const ToolNode& node = *it;
722     if ( node.id == id )
723
724       vis = node.visible;
725   }
726   return vis;
727 }
728
729 /*!
730   \brief Show/hide action with given \a id in the toolbar \a tid.
731   \param id action ID
732   \param tid toolbar ID
733   \param on new visibility status
734 */
735 void QtxActionToolMgr::setVisible( const int id, const int tid, const bool on )
736 {
737   if ( !myToolBars.contains( tid ) )
738     return;
739
740   bool changed = false;
741   NodeList& lst = myToolBars[tid].nodes;
742   for ( NodeList::iterator it = lst.begin(); it != lst.end(); ++it )
743   {
744     ToolNode& node = *it;
745     if ( node.id == id )
746     {
747       changed = changed || node.visible != on;
748       node.visible = on;
749     }
750   }
751
752   if ( changed ) {
753     triggerUpdate( tid );
754     updateContent();
755   }
756 }
757
758 /*!
759   \brief Load toolbar contents from the file.
760   \param fname file name
761   \param r actions reader
762   \return \c true on success and \c false on error
763 */
764 bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r )
765 {
766   ToolCreator cr( &r, this );
767   return r.read( fname, cr );
768 }
769
770 /*!
771   \brief Called when delayed content update is performed.
772
773   Customizes the content update operation.
774 */
775 void QtxActionToolMgr::updateContent()
776 {
777   if ( !isUpdatesEnabled() )
778     return;
779
780   for ( QMap<int,int>::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it )
781     updateToolBar( it.key() );
782   myUpdateIds.clear();
783 }
784
785 /*!
786   \brief Perform delayed toolbar update.
787   \param tid toolbar ID
788 */
789 void QtxActionToolMgr::triggerUpdate( const int tid )
790 {
791   myUpdateIds.insert( tid, 0 );
792   QtxActionMgr::triggerUpdate();
793 }
794
795
796 /*!
797   \class QtxActionToolMgr::ToolCreator
798   \brief Toolbars creator.
799
800   Used by Reader to create actions by reading descriptions from the file,
801   create toolbars and fill in the toolbara with the actions.
802 */
803
804 /*!
805   \brief Constructor.
806   \param r actions reader
807   \param mgr toolbar manager
808 */
809 QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r,
810                                             QtxActionToolMgr* mgr )
811 : QtxActionMgr::Creator( r ),
812   myMgr( mgr )
813 {
814 }
815
816 /*!
817   \brief Destructor.
818 */
819 QtxActionToolMgr::ToolCreator::~ToolCreator()
820 {
821 }
822
823 /*!
824   \brief Create and append to the action manager a new toolbar or toolbar action.
825   \param tag item tag name
826   \param subMenu \c true if this item is submenu (not used)
827   \param attr attributes map
828   \param tid toolbar ID
829   \return toolbar or toolbar action ID
830 */
831 int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool /*subMenu*/,
832                                            const ItemAttributes& attr, const int tid )
833 {  
834   if( !myMgr || !reader() )
835     return -1;
836
837   QString label   = reader()->option( "label",     "label"     ),
838           id      = reader()->option( "id",        "id"        ),
839           pos     = reader()->option( "pos",       "pos"       ),
840           group   = reader()->option( "group",     "group"     ),
841           tooltip = reader()->option( "tooltip",   "tooltip"   ),
842           sep     = reader()->option( "separator", "separator" ),
843           accel   = reader()->option( "accel",     "accel"     ),
844           icon    = reader()->option( "icon",      "icon"      ),
845           toggle  = reader()->option( "toggle",    "toggle"    );
846
847   int res = -1, actId = intValue( attr, id, -1 );
848   if( tid==-1 )
849     res = myMgr->createToolBar( strValue( attr, label ), intValue( attr, id, -1 ) );
850   else if( tag==sep )
851     res = myMgr->insert( separator(), tid, intValue( attr, pos, -1 ) );
852   else
853   {
854     QIcon set;
855     QPixmap pix;
856     QString name = strValue( attr, icon );
857     if( !name.isEmpty() && loadPixmap( name, pix ) )
858       set = QIcon( pix );
859
860     QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ),
861                                        QKeySequence( strValue( attr, accel ) ), myMgr );
862     QString toggleact = strValue( attr, toggle );
863     newAct->setCheckable( !toggleact.isEmpty() );
864     newAct->setChecked( toggleact.toLower() == "true" );
865         
866     connect( newAct );
867     int aid = myMgr->registerAction( newAct, actId );
868     res = myMgr->insert( aid, tid, intValue( attr, pos, -1 ) );
869   }
870
871   return res;
872 }