X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FQtx%2FQtxActionMenuMgr.h;h=fd5126de98c2deb250120d53047d377cc1246ad7;hb=389efae83b99d654509671e60af3eecf11b8278e;hp=bdbe139a4b646414f5eef6e0f457b4697a46be29;hpb=399155730966dfc225fbb24f66204b05664385f2;p=modules%2Fgui.git diff --git a/src/Qtx/QtxActionMenuMgr.h b/src/Qtx/QtxActionMenuMgr.h index bdbe139a4..fd5126de9 100644 --- a/src/Qtx/QtxActionMenuMgr.h +++ b/src/Qtx/QtxActionMenuMgr.h @@ -1,81 +1,51 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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/ 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 -#include +#include -class QPopupMenu; +class QMenu; class QMainWindow; +class QStringList; #ifdef WIN32 #pragma warning( disable:4251 ) #endif -/*! - \class QtxActionMenuMgr - Allows to use set of action to automatically build main menu. - With help of methods insert/append/remove it is possible to - describe whole structure of menu. Method hide allows - to temporary remove some items from menu, method show allows to - recreate them. - Actions can be grouped with help of group identifictor. - Inside popup or menu bar items have order by increasing group id. - This manager is able to attune menu: to remove excess separators, - to remove empty popup menu etc. -*/ class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr { Q_OBJECT class MenuNode; - typedef QPtrList NodeList; - typedef QPtrListIterator NodeListIterator; - - /*! - \class MenuNode - Represents a menu item inside main menu structure. - For internal purposes only - */ - class MenuNode - { - public: - MenuNode() : parent( 0 ), visible( true ) { children.setAutoDelete( true ); }; - MenuNode( MenuNode* p ) : parent( p ), visible( true ) { children.setAutoDelete( true ); }; - - int id; - int idx; - int group; - MenuNode* parent; - bool visible; - NodeList children; - }; - - class MenuAction; + typedef QList NodeList; //!< menu nodes list protected: class MenuCreator; @@ -85,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 ); @@ -97,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, const int = -1, const bool = false ); - int insert( const QString&, const QStringList&, const int, const int = -1, const int = -1, const bool = false ); - virtual int insert( const QString&, const int, const int, const int = -1, const int = -1, const bool = false ); + 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, const int = -1, const bool = false ); + 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, const int = -1, const bool = false ); + int prepend( const QString&, const int, const int, const int = -1 ); void remove( const int ); void remove( const int, const int, const int = -1 ); @@ -118,21 +90,31 @@ 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 containsMenu( const int, const int ) const; + 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* ); - void onHighlighted( int ); signals: - void menuHighlighted( int, int ); + void menuAboutToShow( QMenu* ); + void menuAboutToHide( QMenu* ); protected: - void setWidget( QWidget* ); + 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; @@ -144,31 +126,33 @@ protected: 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(); 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 MenuMap; + void triggerUpdate( const int, const bool rec = true ); private: - MenuNode myRoot; - QWidget* myMenu; - MenuMap myMenus; + typedef QMap MenuMap; //!< actions map + +private: + MenuNode* myRoot; //!< root menu node + QWidget* myMenu; //!< menu widget + MenuMap myMenus; //!< actions map + QMap myUpdateIds; //!< list of actions ID being updated }; -/*! - \class QtxActionMenuMgr::MenuCreator - Allows to create automatically main menu by data read from file -*/ class QtxActionMenuMgr::MenuCreator : public QtxActionMgr::Creator { public: @@ -179,7 +163,7 @@ public: const ItemAttributes&, const int ); private: - QtxActionMenuMgr* myMgr; + QtxActionMenuMgr* myMgr; //!< menu manager };