Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / Qtx / QtxActionToolMgr.h
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/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      QtxActionToolMgr.h
20 // Author:    Alexander SOLOVYEV, Sergey TELKOV
21
22 #ifndef QTXACTIONTOOLMGR_H
23 #define QTXACTIONTOOLMGR_H
24
25 #include "Qtx.h"
26
27 #include <qaction.h>
28
29 #include "QtxActionMgr.h"
30
31 class QToolBar;
32 class QMainWindow;
33
34 #ifdef WIN32
35 #pragma warning( disable:4251 )
36 #endif
37
38 /*!
39   \class QtxActionToolMgr
40   Allows to use set of action to automatically build set of toolbars.
41   With help of methods insert/append/remove it is possible to 
42   describe toolbars and its internal structure.
43   This manager is able to attune toolbar by removing excess separators
44 */
45 class QTX_EXPORT QtxActionToolMgr : public QtxActionMgr
46 {
47   Q_OBJECT
48
49   /*!
50     \class ToolNode
51     Represents a toolbutton inside toolbar
52     For internal purposes only
53   */
54   class ToolNode
55   {
56   public:
57     ToolNode() : id( -1 ), visible( true ) {};
58
59     int       id;
60     bool      visible;
61   };
62
63   typedef QValueList<ToolNode> NodeList;
64
65 protected:
66   class ToolCreator;
67
68 public:
69   QtxActionToolMgr( QMainWindow* );
70   virtual ~QtxActionToolMgr();
71
72   QMainWindow*    mainWindow() const;
73
74   int             createToolBar( const QString&, int = -1 );
75   void            removeToolBar( const QString& );
76   void            removeToolBar( const int );
77
78   int             insert( const int, const int, const int = -1 );
79   int             insert( QAction*, const int, const int = -1 );
80   int             insert( const int, const QString&, const int = -1 );
81   int             insert( QAction*, const QString&, const int = -1 );
82
83   int             append( const int, const int );
84   int             append( QAction*, const int );
85   int             append( const int, const QString& );
86   int             append( QAction*, const QString& );
87
88   int             prepend( const int, const int );
89   int             prepend( QAction*, const int );
90   int             prepend( const int, const QString& );
91   int             prepend( QAction*, const QString& );
92
93   virtual bool    isVisible( const int, const int ) const;
94   virtual void    setVisible( const int, const int, const bool );
95
96   void            show( const int );
97   void            hide( const int );
98   bool            isShown( const int ) const;
99   void            setShown( const int, const bool );
100
101   void            remove( const int, const int );
102   void            remove( const int, const QString& );
103
104   QToolBar*       toolBar( const int ) const;
105   QToolBar*       toolBar( const QString& ) const;
106   
107   bool            hasToolBar( const int ) const;
108   bool            hasToolBar( const QString& ) const;
109
110   bool            containsAction( const int, const int = -1 ) const;
111
112   virtual bool    load( const QString&, QtxActionMgr::Reader& );
113
114 protected slots:
115   void            onToolBarDestroyed();
116
117 protected:
118   int             find( QToolBar* ) const;  
119   int             find( const QString& ) const;
120   QToolBar*       find( const QString&, QMainWindow* ) const;
121
122   virtual void    internalUpdate();
123   void            updateToolBar( const int );
124
125 private:
126   void            simplifySeparators( QToolBar* );
127
128 private:
129   typedef struct { NodeList nodes; QToolBar* toolBar; } ToolBarInfo;
130   typedef QMap<int, ToolBarInfo>                        ToolBarMap;
131
132 private:
133   ToolBarMap      myToolBars;
134   QMainWindow*    myMainWindow;
135 };
136
137 /*!
138   \class QtxActionToolMgr::ToolCreator
139   Allows to create automatically toolbar by data read from file
140 */
141 class QtxActionToolMgr::ToolCreator : public QtxActionMgr::Creator
142 {
143 public:
144   ToolCreator( QtxActionMgr::Reader*, QtxActionToolMgr* );
145   virtual ~ToolCreator();
146
147   virtual int append( const QString&, const bool,
148                       const ItemAttributes&, const int );
149
150 private:
151   QtxActionToolMgr* myMgr;
152 };
153
154 #endif