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