Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxActionMenuMgr.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:      QtxActionMenuMgr.h
23 // Author:    Alexander SOLOVYOV, Sergey TELKOV
24 //
25 #ifndef QTXACTIONMENUMGR_H
26 #define QTXACTIONMENUMGR_H
27
28 #include "Qtx.h"
29 #include "QtxActionMgr.h"
30
31 #include <QList>
32
33 class QMenu;
34 class QMainWindow;
35 class QStringList;
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr
42 {
43   Q_OBJECT
44
45   class MenuNode;
46
47   typedef QList<MenuNode*> NodeList;  //!< menu nodes list
48
49 protected:
50   class MenuCreator;
51
52 public:
53   QtxActionMenuMgr( QMainWindow* );
54   QtxActionMenuMgr( QWidget*, QObject* );
55   virtual ~QtxActionMenuMgr();
56
57   QWidget*     menuWidget() const;
58
59   virtual bool isVisible( const int, const int ) const;
60   virtual void setVisible( const int, const int, const bool );
61
62   int          insert( const int, const QString&, const int, const int = -1 );
63   int          insert( QAction*, const QString&, const int, const int = -1 );
64
65   int          insert( const int, const QStringList&, const int, const int = -1 );
66   int          insert( QAction*, const QStringList&, const int, const int = -1 );
67
68   virtual int  insert( const int, const int, const int, const int = -1 );
69   int          insert( QAction*, const int, const int, const int = -1 );
70
71   int          insert( const QString&, const QString&, const int, const int = -1, const int = -1 );
72   int          insert( const QString&, const QStringList&, const int, const int = -1, const int = -1 );
73   virtual int  insert( const QString&, const int, const int, const int = -1, const int = -1 );
74
75   int          append( const int, const int, const int );
76   int          append( QAction*, const int, const int );
77   int          append( const QString&, const int, const int, const int = -1 );
78
79   int          prepend( const int, const int, const int );
80   int          prepend( QAction*, const int, const int );
81   int          prepend( const QString&, const int, const int, const int = -1 );
82
83   void         remove( const int );
84   void         remove( const int, const int, const int = -1 );
85
86   void         show( const int );
87   void         hide( const int );
88
89   bool         isShown( const int ) const;
90   void         setShown( const int, const bool );
91
92   virtual void change( const int, const QString& );
93
94   virtual bool load( const QString&, QtxActionMgr::Reader& );
95
96   bool         containsMenu( const QString&, const int, const bool = false ) const;
97   bool         containsMenu( const int, const int, const bool = false ) const;
98
99   QMenu*       findMenu( const int ) const;
100   QMenu*       findMenu( const QString&, const int, const bool = false ) const;
101
102   bool         isEmptyEnabled( const int ) const;
103   void         setEmptyEnabled( const int, const bool );
104
105 private slots:
106   void         onAboutToShow();
107   void         onAboutToHide();
108   void         onDestroyed( QObject* );
109
110 signals:
111   void         menuAboutToShow( QMenu* );
112   void         menuAboutToHide( QMenu* );
113
114 protected:
115   void         setMenuWidget( QWidget* );
116
117   MenuNode*    find( const int, const int, const bool = true ) const;
118   MenuNode*    find( const int, MenuNode* = 0, const bool = true ) const;
119   bool         find( const int, NodeList&, MenuNode* = 0 ) const;
120   MenuNode*    find( const QString&, const int, const bool = true ) const;
121   MenuNode*    find( const QString&, MenuNode* = 0, const bool = true ) const;
122   bool         find( const QString&, NodeList&, MenuNode* = 0 ) const;
123   int          findId( const int, const int = -1 ) const;
124
125   void         removeMenu( const int, MenuNode* );
126
127   QAction*     itemAction( const int ) const;
128   QAction*     menuAction( const int ) const;
129   int          menuActionId( QAction* ) const;
130
131   void         updateMenu( MenuNode* = 0, const bool = true, const bool = true );
132   virtual void internalUpdate();
133   virtual void updateContent();
134
135 private:
136   bool         ownAction( QAction*, MenuNode* ) const;
137   bool         checkWidget( QWidget* ) const;
138   QWidget*     menuWidget( MenuNode* ) const;
139   void         simplifySeparators( QWidget* );
140   QString      clearTitle( const QString& ) const;
141   int          createMenu( const QStringList&, const int );
142
143   void         triggerUpdate( const int, const bool rec = true );
144
145 private:
146   typedef QMap<int, QAction*> MenuMap;     //!< actions map
147   
148 private:
149   MenuNode*       myRoot;        //!< root menu node
150   QWidget*        myMenu;        //!< menu widget
151   MenuMap         myMenus;       //!< actions map
152   QMap<int, bool> myUpdateIds;   //!< list of actions ID being updated
153 };
154
155 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
156 {
157 public:
158   MenuCreator( QtxActionMgr::Reader*, QtxActionMenuMgr* );
159   virtual ~MenuCreator();
160
161   virtual int append( const QString&, const bool,
162                       const ItemAttributes&, const int );
163
164 private:
165   QtxActionMenuMgr* myMgr;       //!< menu manager
166 };
167
168
169 #endif