Salome HOME
31c02209d0d2d8fb28fdb500a65c6bea3a788caf
[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/
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 class QTX_EXPORT QtxActionToolMgr : public QtxActionMgr
39 {
40   Q_OBJECT
41
42   class ToolNode
43   {
44   public:
45     ToolNode() : id( -1 ), visible( true ) {};
46
47     int       id;
48     bool      visible;
49   };
50
51   typedef QValueList<ToolNode> NodeList;
52
53 protected:
54   class ToolCreator;
55
56 public:
57   QtxActionToolMgr( QMainWindow* );
58   virtual ~QtxActionToolMgr();
59
60   QMainWindow*    mainWindow() const;
61
62   int             createToolBar( const QString&, int = -1 );
63   void            removeToolBar( const QString& );
64   void            removeToolBar( const int );
65
66   int             insert( const int, const int, const int = -1 );
67   int             insert( QAction*, const int, const int = -1 );
68   int             insert( const int, const QString&, const int = -1 );
69   int             insert( QAction*, const QString&, const int = -1 );
70
71   int             append( const int, const int );
72   int             append( QAction*, const int );
73   int             append( const int, const QString& );
74   int             append( QAction*, const QString& );
75
76   int             prepend( const int, const int );
77   int             prepend( QAction*, const int );
78   int             prepend( const int, const QString& );
79   int             prepend( QAction*, const QString& );
80
81   virtual bool    isVisible( const int, const int ) const;
82   virtual void    setVisible( const int, const int, const bool );
83
84   void            show( const int );
85   void            hide( const int );
86   bool            isShown( const int ) const;
87   void            setShown( const int, const bool );
88
89   void            remove( const int, const int );
90   void            remove( const int, const QString& );
91
92   QToolBar*       toolBar( const int ) const;
93   QToolBar*       toolBar( const QString& ) const;
94   
95   bool            hasToolBar( const int ) const;
96   bool            hasToolBar( const QString& ) const;
97
98   virtual bool    load( const QString&, QtxActionMgr::Reader& );
99
100 protected slots:
101   void            onToolBarDestroyed();
102
103 protected:
104   int             find( QToolBar* ) const;  
105   int             find( const QString& ) const;
106   QToolBar*       find( const QString&, QMainWindow* ) const;
107
108   virtual void    internalUpdate();
109   void            updateToolBar( const int );
110
111 private:
112   void            simplifySeparators( QToolBar* );
113
114 private:
115   typedef struct { NodeList nodes; QToolBar* toolBar; } ToolBarInfo;
116   typedef QMap<int, ToolBarInfo>                        ToolBarMap;
117
118 private:
119   ToolBarMap      myToolBars;
120   QMainWindow*    myMainWindow;
121 };
122
123 class QtxActionToolMgr::ToolCreator : public QtxActionMgr::Creator
124 {
125 public:
126   ToolCreator( QtxActionMgr::Reader*, QtxActionToolMgr* );
127   virtual ~ToolCreator();
128
129   virtual int append( const QString&, const bool,
130                       const ItemAttributes&, const int );
131
132 private:
133   QtxActionToolMgr* myMgr;
134 };
135
136 #endif