Salome HOME
Updated copyright comment
[modules/gui.git] / src / Qtx / QtxActionMenuMgr.h
index 89b81aa89a8b770a44973cfe756e902656a0d99d..c5cd1f3e5f909e90fa71c2da27b666013ad294a0 100644 (file)
@@ -1,35 +1,39 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// File:      QtxActionMenuMgr.h
-// Author:    Alexander SOLOVYEV, Sergey TELKOV
 
+// File:      QtxActionMenuMgr.h
+// Author:    Alexander SOLOVYOV, Sergey TELKOV
+//
 #ifndef QTXACTIONMENUMGR_H
 #define QTXACTIONMENUMGR_H
 
 #include "Qtx.h"
 #include "QtxActionMgr.h"
 
-#include <qptrlist.h>
-#include <qstringlist.h>
+#include <QList>
 
-class QPopupMenu;
+class QMenu;
 class QMainWindow;
+class QStringList;
 
 #ifdef WIN32
 #pragma warning( disable:4251 )
@@ -41,23 +45,7 @@ class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr
 
   class MenuNode;
 
-  typedef QPtrList<MenuNode>         NodeList;
-  typedef QPtrListIterator<MenuNode> NodeListIterator;
-
-  class MenuNode
-  {
-  public:
-    MenuNode() : parent( 0 ), visible( true ) { children.setAutoDelete( true ); };
-    MenuNode( MenuNode* p ) : parent( p ), visible( true ) { children.setAutoDelete( true ); };
-
-    int       id;
-    int       group;
-    MenuNode* parent;
-    bool      visible;
-    NodeList  children;
-  };
-
-  class MenuAction;
+  typedef QList<MenuNode*> NodeList;  //!< menu nodes list
 
 protected:
   class MenuCreator;
@@ -67,6 +55,8 @@ public:
   QtxActionMenuMgr( QWidget*, QObject* );
   virtual ~QtxActionMenuMgr();
 
+  QWidget*     menuWidget() const;
+
   virtual bool isVisible( const int, const int ) const;
   virtual void setVisible( const int, const int, const bool );
 
@@ -79,17 +69,17 @@ public:
   virtual int  insert( const int, const int, const int, const int = -1 );
   int          insert( QAction*, const int, const int, const int = -1 );
 
-  int          insert( const QString&, const QString&, const int, const int = -1 );
-  int          insert( const QString&, const QStringList&, const int, const int = -1 );
-  virtual int  insert( const QString&, const int, const int, const int = -1 );
+  int          insert( const QString&, const QString&, const int, const int = -1, const int = -1 );
+  int          insert( const QString&, const QStringList&, const int, const int = -1, const int = -1 );
+  virtual int  insert( const QString&, const int, const int, const int = -1, const int = -1 , QMenu* = 0);
 
   int          append( const int, const int, const int );
   int          append( QAction*, const int, const int );
-  int          append( const QString&, const int, const int );
+  int          append( const QString&, const int, const int, const int = -1 );
 
   int          prepend( const int, const int, const int );
   int          prepend( QAction*, const int, const int );
-  int          prepend( const QString&, const int, const int );
+  int          prepend( const QString&, const int, const int, const int = -1 );
 
   void         remove( const int );
   void         remove( const int, const int, const int = -1 );
@@ -100,39 +90,68 @@ public:
   bool         isShown( const int ) const;
   void         setShown( const int, const bool );
 
+  virtual void change( const int, const QString& );
+
   virtual bool load( const QString&, QtxActionMgr::Reader& );
 
+  bool         containsMenu( const QString&, const int, const bool = false ) const;
+  bool         containsMenu( const int, const int, const bool = false ) const;
+
+  QMenu*       findMenu( const int ) const;
+  QMenu*       findMenu( const QString&, const int, const bool = false ) const;
+
+  bool         isEmptyEnabled( const int ) const;
+  void         setEmptyEnabled( const int, const bool );
+
 private slots:
+  void         onAboutToShow();
+  void         onAboutToHide();
   void         onDestroyed( QObject* );
 
+signals:
+  void         menuAboutToShow( QMenu* );
+  void         menuAboutToHide( QMenu* );
+
 protected:
-  void         setWidget( QWidget* );
-  MenuNode*    find( const int, const int ) const;
-  MenuNode*    find( const int, MenuNode* = 0 ) const;
+  void         setMenuWidget( QWidget* );
+
+  MenuNode*    find( const int, const int, const bool = true ) const;
+  MenuNode*    find( const int, MenuNode* = 0, const bool = true ) const;
   bool         find( const int, NodeList&, MenuNode* = 0 ) const;
+  MenuNode*    find( const QString&, const int, const bool = true ) const;
+  MenuNode*    find( const QString&, MenuNode* = 0, const bool = true ) const;
+  bool         find( const QString&, NodeList&, MenuNode* = 0 ) const;
+  int          findId( const int, const int = -1 ) const;
 
   void         removeMenu( const int, MenuNode* );
 
   QAction*     itemAction( const int ) const;
-  MenuAction*  menuAction( const int ) const;
+  QAction*     menuAction( const int ) const;
+  int          menuActionId( QAction* ) const;
 
   void         updateMenu( MenuNode* = 0, const bool = true, const bool = true );
-  virtual void internalUpdate();  
+  virtual void internalUpdate();
+  virtual void updateContent();
+  virtual void actionChanged( int );
 
 private:
+  bool         ownAction( QAction*, MenuNode* ) const;
   bool         checkWidget( QWidget* ) const;
   QWidget*     menuWidget( MenuNode* ) const;
   void         simplifySeparators( QWidget* );
   QString      clearTitle( const QString& ) const;
   int          createMenu( const QStringList&, const int );
 
-private:
-  typedef QMap<int, MenuAction*> MenuMap;
+  void         triggerUpdate( const int, const bool rec = true );
 
 private:
-  MenuNode     myRoot;
-  QWidget*     myMenu;
-  MenuMap      myMenus;
+  typedef QMap<int, QAction*> MenuMap;     //!< actions map
+  
+private:
+  MenuNode*       myRoot;        //!< root menu node
+  QWidget*        myMenu;        //!< menu widget
+  MenuMap         myMenus;       //!< actions map
+  QMap<int, bool> myUpdateIds;   //!< list of actions ID being updated
 };
 
 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
@@ -145,7 +164,7 @@ public:
                       const ItemAttributes&, const int );
 
 private:
-  QtxActionMenuMgr* myMgr;
+  QtxActionMenuMgr* myMgr;       //!< menu manager
 };