00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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