1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 // File: QtxActionMenuMgr.h
20 // Author: Alexander SOLOVYEV, Sergey TELKOV
22 #ifndef QTXACTIONMENUMGR_H
23 #define QTXACTIONMENUMGR_H
26 #include "QtxActionMgr.h"
29 #include <qstringlist.h>
35 #pragma warning( disable:4251 )
39 \class QtxActionMenuMgr
40 Allows to use set of action to automatically build main menu.
41 With help of methods insert/append/remove it is possible to
42 describe whole structure of menu. Method hide allows
43 to temporary remove some items from menu, method show allows to
45 Actions can be grouped with help of group identifictor.
46 Inside popup or menu bar items have order by increasing group id.
47 This manager is able to attune menu: to remove excess separators,
48 to remove empty popup menu etc.
50 class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr
56 typedef QPtrList<MenuNode> NodeList;
57 typedef QPtrListIterator<MenuNode> NodeListIterator;
61 Represents a menu item inside main menu structure.
62 For internal purposes only
67 MenuNode() : parent( 0 ), visible( true ) { children.setAutoDelete( true ); };
68 MenuNode( MenuNode* p ) : parent( p ), visible( true ) { children.setAutoDelete( true ); };
84 QtxActionMenuMgr( QMainWindow* );
85 QtxActionMenuMgr( QWidget*, QObject* );
86 virtual ~QtxActionMenuMgr();
88 virtual bool isVisible( const int, const int ) const;
89 virtual void setVisible( const int, const int, const bool );
91 int insert( const int, const QString&, const int, const int = -1 );
92 int insert( QAction*, const QString&, const int, const int = -1 );
94 int insert( const int, const QStringList&, const int, const int = -1 );
95 int insert( QAction*, const QStringList&, const int, const int = -1 );
97 virtual int insert( const int, const int, const int, const int = -1 );
98 int insert( QAction*, const int, const int, const int = -1 );
100 int insert( const QString&, const QString&, const int, const int = -1, const int = -1, const bool = false );
101 int insert( const QString&, const QStringList&, const int, const int = -1, const int = -1, const bool = false );
102 virtual int insert( const QString&, const int, const int, const int = -1, const int = -1, const bool = false );
104 int append( const int, const int, const int );
105 int append( QAction*, const int, const int );
106 int append( const QString&, const int, const int, const int = -1, const bool = false );
108 int prepend( const int, const int, const int );
109 int prepend( QAction*, const int, const int );
110 int prepend( const QString&, const int, const int, const int = -1, const bool = false );
112 void remove( const int );
113 void remove( const int, const int, const int = -1 );
115 void show( const int );
116 void hide( const int );
118 bool isShown( const int ) const;
119 void setShown( const int, const bool );
121 virtual bool load( const QString&, QtxActionMgr::Reader& );
123 bool containsMenu( const QString&, const int ) const;
124 bool containsMenu( const int, const int ) const;
128 void onDestroyed( QObject* );
129 void onHighlighted( int );
132 void menuHighlighted( int, int );
135 void setWidget( QWidget* );
136 MenuNode* find( const int, const int, const bool = true ) const;
137 MenuNode* find( const int, MenuNode* = 0, const bool = true ) const;
138 bool find( const int, NodeList&, MenuNode* = 0 ) const;
139 MenuNode* find( const QString&, const int, const bool = true ) const;
140 MenuNode* find( const QString&, MenuNode* = 0, const bool = true ) const;
141 bool find( const QString&, NodeList&, MenuNode* = 0 ) const;
142 int findId( const int, const int = -1 ) const;
144 void removeMenu( const int, MenuNode* );
146 QAction* itemAction( const int ) const;
147 MenuAction* menuAction( const int ) const;
149 void updateMenu( MenuNode* = 0, const bool = true, const bool = true );
150 virtual void internalUpdate();
153 bool checkWidget( QWidget* ) const;
154 QWidget* menuWidget( MenuNode* ) const;
155 void simplifySeparators( QWidget* );
156 QString clearTitle( const QString& ) const;
157 int createMenu( const QStringList&, const int );
160 typedef QMap<int, MenuAction*> MenuMap;
169 \class QtxActionMenuMgr::MenuCreator
170 Allows to create automatically main menu by data read from file
172 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
175 MenuCreator( QtxActionMgr::Reader*, QtxActionMenuMgr* );
176 virtual ~MenuCreator();
178 virtual int append( const QString&, const bool,
179 const ItemAttributes&, const int );
182 QtxActionMenuMgr* myMgr;