Salome HOME
Copyrights update
[modules/gui.git] / src / Qtx / QtxActionMenuMgr.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:      QtxActionMenuMgr.h
20 // Author:    Alexander SOLOVYEV, Sergey TELKOV
21
22 #ifndef QTXACTIONMENUMGR_H
23 #define QTXACTIONMENUMGR_H
24
25 #include "Qtx.h"
26 #include "QtxActionMgr.h"
27
28 #include <qptrlist.h>
29 #include <qstringlist.h>
30
31 class QPopupMenu;
32 class QMainWindow;
33
34 #ifdef WIN32
35 #pragma warning( disable:4251 )
36 #endif
37
38 class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr
39 {
40   Q_OBJECT
41
42   class MenuNode;
43
44   typedef QPtrList<MenuNode>         NodeList;
45   typedef QPtrListIterator<MenuNode> NodeListIterator;
46
47   class MenuNode
48   {
49   public:
50     MenuNode() : parent( 0 ), visible( true ) { children.setAutoDelete( true ); };
51     MenuNode( MenuNode* p ) : parent( p ), visible( true ) { children.setAutoDelete( true ); };
52
53     int       id;
54     int       group;
55     MenuNode* parent;
56     bool      visible;
57     NodeList  children;
58   };
59
60   class MenuAction;
61
62 protected:
63   class MenuCreator;
64
65 public:
66   QtxActionMenuMgr( QMainWindow* );
67   QtxActionMenuMgr( QWidget*, QObject* );
68   virtual ~QtxActionMenuMgr();
69
70   virtual bool isVisible( const int, const int ) const;
71   virtual void setVisible( const int, const int, const bool );
72
73   int          insert( const int, const QString&, const int, const int = -1 );
74   int          insert( QAction*, const QString&, const int, const int = -1 );
75
76   int          insert( const int, const QStringList&, const int, const int = -1 );
77   int          insert( QAction*, const QStringList&, const int, const int = -1 );
78
79   virtual int  insert( const int, const int, const int, const int = -1 );
80   int          insert( QAction*, const int, const int, const int = -1 );
81
82   int          insert( const QString&, const QString&, const int, const int = -1 );
83   int          insert( const QString&, const QStringList&, const int, const int = -1 );
84   virtual int  insert( const QString&, const int, const int, const int = -1 );
85
86   int          append( const int, const int, const int );
87   int          append( QAction*, const int, const int );
88   int          append( const QString&, const int, const int );
89
90   int          prepend( const int, const int, const int );
91   int          prepend( QAction*, const int, const int );
92   int          prepend( const QString&, const int, const int );
93
94   void         remove( const int );
95   void         remove( const int, const int, const int = -1 );
96
97   void         show( const int );
98   void         hide( const int );
99
100   bool         isShown( const int ) const;
101   void         setShown( const int, const bool );
102
103   virtual bool load( const QString&, QtxActionMgr::Reader& );
104
105 private slots:
106   void         onDestroyed( QObject* );
107
108 protected:
109   void         setWidget( QWidget* );
110   MenuNode*    find( const int, const int ) const;
111   MenuNode*    find( const int, MenuNode* = 0 ) const;
112   bool         find( const int, NodeList&, MenuNode* = 0 ) const;
113
114   void         removeMenu( const int, MenuNode* );
115
116   QAction*     itemAction( const int ) const;
117   MenuAction*  menuAction( const int ) const;
118
119   void         updateMenu( MenuNode* = 0, const bool = true, const bool = true );
120   virtual void internalUpdate();  
121
122 private:
123   bool         checkWidget( QWidget* ) const;
124   QWidget*     menuWidget( MenuNode* ) const;
125   void         simplifySeparators( QWidget* );
126   QString      clearTitle( const QString& ) const;
127   int          createMenu( const QStringList&, const int );
128
129 private:
130   typedef QMap<int, MenuAction*> MenuMap;
131
132 private:
133   MenuNode     myRoot;
134   QWidget*     myMenu;
135   MenuMap      myMenus;
136 };
137
138 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
139 {
140 public:
141   MenuCreator( QtxActionMgr::Reader*, QtxActionMenuMgr* );
142   virtual ~MenuCreator();
143
144   virtual int append( const QString&, const bool,
145                       const ItemAttributes&, const int );
146
147 private:
148   QtxActionMenuMgr* myMgr;
149 };
150
151
152 #endif