]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxActionToolMgr.h
Salome HOME
dd6b19cf4ebc9c6cc63ff93155e3d1df6d442c94
[modules/gui.git] / src / Qtx / QtxActionToolMgr.h
1 //  Copyright (C) 2007-2008  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.
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 // File:      QtxActionToolMgr.h
23 // Author:    Alexander SOLOVYOV, Sergey TELKOV
24 //
25 #ifndef QTXACTIONTOOLMGR_H
26 #define QTXACTIONTOOLMGR_H
27
28 #include "Qtx.h"
29 #include "QtxActionMgr.h"
30
31 #include <QMap>
32 #include <QList>
33
34 class QToolBar;
35 class QMainWindow;
36 class QAction;
37
38 #ifdef WIN32
39 #pragma warning( disable:4251 )
40 #endif
41
42 class QTX_EXPORT QtxActionToolMgr : public QtxActionMgr
43 {
44   Q_OBJECT
45
46   class ToolNode
47   {
48   public:
49     ToolNode() : id( -1 ), visible( true ) {};
50     ToolNode( const int _id ) : id( _id ), visible( true ) {};
51
52     int       id;          //!< tool node ID
53     bool      visible;     //!< visibility status
54   };
55
56   typedef QList<ToolNode> NodeList;    //!< toolbar nodes list
57
58 protected:
59   class ToolCreator;
60
61 public:
62   QtxActionToolMgr( QMainWindow* );
63   virtual ~QtxActionToolMgr();
64
65   QMainWindow*    mainWindow() const;
66
67   int             createToolBar( const QString&, int = -1, QMainWindow* = 0 );
68   void            removeToolBar( const QString& );
69   void            removeToolBar( const int );
70
71   int             insert( const int, const int, const int = -1 );
72   int             insert( QAction*, const int, const int = -1 );
73   int             insert( const int, const QString&, const int = -1 );
74   int             insert( QAction*, const QString&, const int = -1 );
75
76   int             append( const int, const int );
77   int             append( QAction*, const int );
78   int             append( const int, const QString& );
79   int             append( QAction*, const QString& );
80
81   int             prepend( const int, const int );
82   int             prepend( QAction*, const int );
83   int             prepend( const int, const QString& );
84   int             prepend( QAction*, const QString& );
85
86   virtual bool    isVisible( const int, const int ) const;
87   virtual void    setVisible( const int, const int, const bool );
88
89   void            show( const int );
90   void            hide( const int );
91   bool            isShown( const int ) const;
92   void            setShown( const int, const bool );
93
94   void            remove( const int, const int );
95   void            remove( const int, const QString& );
96
97   QToolBar*       toolBar( const int ) const;
98   QToolBar*       toolBar( const QString& ) const;
99   
100   bool            hasToolBar( const int ) const;
101   bool            hasToolBar( const QString& ) const;
102
103   bool            containsAction( const int, const int = -1 ) const;
104
105   virtual bool    load( const QString&, QtxActionMgr::Reader& );
106
107   int             find( QToolBar* ) const;
108
109 protected slots:
110   void            onToolBarDestroyed();
111
112 protected:
113   int             find( const QString& ) const;
114   QToolBar*       find( const QString&, QMainWindow* ) const;
115
116   virtual void    internalUpdate();
117   void            updateToolBar( const int );
118
119   virtual void    updateContent();
120
121 private:
122   void            simplifySeparators( QToolBar* );
123   void            triggerUpdate( const int );
124
125 private:
126   typedef struct { NodeList nodes; QToolBar* toolBar; } ToolBarInfo;   //!< toolbar info
127   typedef QMap<int, ToolBarInfo>                        ToolBarMap;    //!< toolbars map
128
129 private:
130   ToolBarMap      myToolBars;      //!< toobars map
131   QMainWindow*    myMainWindow;    //!< parent main window
132   QMap<int,int>   myUpdateIds;     //!< list of actions ID being updated
133 };
134
135 class QtxActionToolMgr::ToolCreator : public QtxActionMgr::Creator
136 {
137 public:
138   ToolCreator( QtxActionMgr::Reader*, QtxActionToolMgr* );
139   virtual ~ToolCreator();
140
141   virtual int append( const QString&, const bool,
142                       const ItemAttributes&, const int );
143
144 private:
145   QtxActionToolMgr* myMgr;         //!< toolbar manager
146 };
147
148 #endif