Salome HOME
f06ff9d3b6c4a6526954a2e0b7c29a7f9544eb97
[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       idx;
55     int       group;
56     MenuNode* parent;
57     bool      visible;
58     NodeList  children;
59   };
60
61   class MenuAction;
62
63 protected:
64   class MenuCreator;
65
66 public:
67   QtxActionMenuMgr( QMainWindow* );
68   QtxActionMenuMgr( QWidget*, QObject* );
69   virtual ~QtxActionMenuMgr();
70
71   virtual bool isVisible( const int, const int ) const;
72   virtual void setVisible( const int, const int, const bool );
73
74   int          insert( const int, const QString&, const int, const int = -1 );
75   int          insert( QAction*, const QString&, const int, const int = -1 );
76
77   int          insert( const int, const QStringList&, const int, const int = -1 );
78   int          insert( QAction*, const QStringList&, const int, const int = -1 );
79
80   virtual int  insert( const int, const int, const int, const int = -1 );
81   int          insert( QAction*, const int, const int, const int = -1 );
82
83   int          insert( const QString&, const QString&, const int, const int = -1, const int = -1, const bool = false );
84   int          insert( const QString&, const QStringList&, const int, const int = -1, const int = -1, const bool = false );
85   virtual int  insert( const QString&, const int, const int, const int = -1, const int = -1, const bool = false );
86
87   int          append( const int, const int, const int );
88   int          append( QAction*, const int, const int );
89   int          append( const QString&, const int, const int, const int = -1, const bool = false );
90
91   int          prepend( const int, const int, const int );
92   int          prepend( QAction*, const int, const int );
93   int          prepend( const QString&, const int, const int, const int = -1, const bool = false );
94
95   void         remove( const int );
96   void         remove( const int, const int, const int = -1 );
97
98   void         show( const int );
99   void         hide( const int );
100
101   bool         isShown( const int ) const;
102   void         setShown( const int, const bool );
103
104   virtual bool load( const QString&, QtxActionMgr::Reader& );
105
106   bool         containsMenu( const QString&, const int ) const;
107   bool         containsMenu( const int, const int ) const;
108
109
110 private slots:
111   void         onDestroyed( QObject* );
112   void         onHighlighted( int );
113
114 signals:
115   void         menuHighlighted( int, int );
116
117 protected:
118   void         setWidget( QWidget* );
119   MenuNode*    find( const int, const int, const bool = true ) const;
120   MenuNode*    find( const int, MenuNode* = 0, const bool = true ) const;
121   bool         find( const int, NodeList&, MenuNode* = 0 ) const;
122   MenuNode*    find( const QString&, const int, const bool = true ) const;
123   MenuNode*    find( const QString&, MenuNode* = 0, const bool = true ) const;
124   bool         find( const QString&, NodeList&, MenuNode* = 0 ) const;
125   int          findId( const int, const int = -1 ) const;
126
127   void         removeMenu( const int, MenuNode* );
128
129   QAction*     itemAction( const int ) const;
130   MenuAction*  menuAction( const int ) const;
131
132   void         updateMenu( MenuNode* = 0, const bool = true, const bool = true );
133   virtual void internalUpdate();  
134
135 private:
136   bool         checkWidget( QWidget* ) const;
137   QWidget*     menuWidget( MenuNode* ) const;
138   void         simplifySeparators( QWidget* );
139   QString      clearTitle( const QString& ) const;
140   int          createMenu( const QStringList&, const int );
141
142 private:
143   typedef QMap<int, MenuAction*> MenuMap;
144
145 private:
146   MenuNode     myRoot;
147   QWidget*     myMenu;
148   MenuMap      myMenus;
149 };
150
151 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
152 {
153 public:
154   MenuCreator( QtxActionMgr::Reader*, QtxActionMenuMgr* );
155   virtual ~MenuCreator();
156
157   virtual int append( const QString&, const bool,
158                       const ItemAttributes&, const int );
159
160 private:
161   QtxActionMenuMgr* myMgr;
162 };
163
164
165 #endif