Back to index

salome-gui  6.5.0
QtxActionMenuMgr.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      QtxActionMenuMgr.h
00024 // Author:    Alexander SOLOVYOV, Sergey TELKOV
00025 //
00026 #ifndef QTXACTIONMENUMGR_H
00027 #define QTXACTIONMENUMGR_H
00028 
00029 #include "Qtx.h"
00030 #include "QtxActionMgr.h"
00031 
00032 #include <QList>
00033 
00034 class QMenu;
00035 class QMainWindow;
00036 class QStringList;
00037 
00038 #ifdef WIN32
00039 #pragma warning( disable:4251 )
00040 #endif
00041 
00042 class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr
00043 {
00044   Q_OBJECT
00045 
00046   class MenuNode;
00047 
00048   typedef QList<MenuNode*> NodeList;  
00049 
00050 protected:
00051   class MenuCreator;
00052 
00053 public:
00054   QtxActionMenuMgr( QMainWindow* );
00055   QtxActionMenuMgr( QWidget*, QObject* );
00056   virtual ~QtxActionMenuMgr();
00057 
00058   QWidget*     menuWidget() const;
00059 
00060   virtual bool isVisible( const int, const int ) const;
00061   virtual void setVisible( const int, const int, const bool );
00062 
00063   int          insert( const int, const QString&, const int, const int = -1 );
00064   int          insert( QAction*, const QString&, const int, const int = -1 );
00065 
00066   int          insert( const int, const QStringList&, const int, const int = -1 );
00067   int          insert( QAction*, const QStringList&, const int, const int = -1 );
00068 
00069   virtual int  insert( const int, const int, const int, const int = -1 );
00070   int          insert( QAction*, const int, const int, const int = -1 );
00071 
00072   int          insert( const QString&, const QString&, const int, const int = -1, const int = -1 );
00073   int          insert( const QString&, const QStringList&, const int, const int = -1, const int = -1 );
00074   virtual int  insert( const QString&, const int, const int, const int = -1, const int = -1 );
00075 
00076   int          append( const int, const int, const int );
00077   int          append( QAction*, const int, const int );
00078   int          append( const QString&, const int, const int, const int = -1 );
00079 
00080   int          prepend( const int, const int, const int );
00081   int          prepend( QAction*, const int, const int );
00082   int          prepend( const QString&, const int, const int, const int = -1 );
00083 
00084   void         remove( const int );
00085   void         remove( const int, const int, const int = -1 );
00086 
00087   void         show( const int );
00088   void         hide( const int );
00089 
00090   bool         isShown( const int ) const;
00091   void         setShown( const int, const bool );
00092 
00093   virtual void change( const int, const QString& );
00094 
00095   virtual bool load( const QString&, QtxActionMgr::Reader& );
00096 
00097   bool         containsMenu( const QString&, const int, const bool = false ) const;
00098   bool         containsMenu( const int, const int, const bool = false ) const;
00099 
00100   QMenu*       findMenu( const int ) const;
00101   QMenu*       findMenu( const QString&, const int, const bool = false ) const;
00102 
00103   bool         isEmptyEnabled( const int ) const;
00104   void         setEmptyEnabled( const int, const bool );
00105 
00106 private slots:
00107   void         onAboutToShow();
00108   void         onAboutToHide();
00109   void         onDestroyed( QObject* );
00110 
00111 signals:
00112   void         menuAboutToShow( QMenu* );
00113   void         menuAboutToHide( QMenu* );
00114 
00115 protected:
00116   void         setMenuWidget( QWidget* );
00117 
00118   MenuNode*    find( const int, const int, const bool = true ) const;
00119   MenuNode*    find( const int, MenuNode* = 0, const bool = true ) const;
00120   bool         find( const int, NodeList&, MenuNode* = 0 ) const;
00121   MenuNode*    find( const QString&, const int, const bool = true ) const;
00122   MenuNode*    find( const QString&, MenuNode* = 0, const bool = true ) const;
00123   bool         find( const QString&, NodeList&, MenuNode* = 0 ) const;
00124   int          findId( const int, const int = -1 ) const;
00125 
00126   void         removeMenu( const int, MenuNode* );
00127 
00128   QAction*     itemAction( const int ) const;
00129   QAction*     menuAction( const int ) const;
00130   int          menuActionId( QAction* ) const;
00131 
00132   void         updateMenu( MenuNode* = 0, const bool = true, const bool = true );
00133   virtual void internalUpdate();
00134   virtual void updateContent();
00135 
00136 private:
00137   bool         ownAction( QAction*, MenuNode* ) const;
00138   bool         checkWidget( QWidget* ) const;
00139   QWidget*     menuWidget( MenuNode* ) const;
00140   void         simplifySeparators( QWidget* );
00141   QString      clearTitle( const QString& ) const;
00142   int          createMenu( const QStringList&, const int );
00143 
00144   void         triggerUpdate( const int, const bool rec = true );
00145 
00146 private:
00147   typedef QMap<int, QAction*> MenuMap;     
00148   
00149 private:
00150   MenuNode*       myRoot;        
00151   QWidget*        myMenu;        
00152   MenuMap         myMenus;       
00153   QMap<int, bool> myUpdateIds;   
00154 };
00155 
00156 class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator
00157 {
00158 public:
00159   MenuCreator( QtxActionMgr::Reader*, QtxActionMenuMgr* );
00160   virtual ~MenuCreator();
00161 
00162   virtual int append( const QString&, const bool,
00163                       const ItemAttributes&, const int );
00164 
00165 private:
00166   QtxActionMenuMgr* myMgr;       
00167 };
00168 
00169 
00170 #endif