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