Salome HOME
60fc342c04f3828b4bab0ab2d5715c31fe21e78e
[modules/gui.git] / src / Qtx / QtxActionMgr.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxActionMgr.h
20 // Author:    Alexander SOLOVYEV, Sergey TELKOV
21
22 #ifndef QTXACTIONMGR_H
23 #define QTXACTIONMGR_H
24
25 #include "Qtx.h"
26
27 #include <qmap.h>
28 #include <qobject.h>
29 #include <qguardedptr.h>
30
31 class QAction;
32 class QDomNode;
33
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 class QTX_EXPORT QtxActionMgr : public QObject
40 {
41   Q_OBJECT 
42
43   class SeparatorAction;
44
45 public:
46   class Reader;
47   class XMLReader;
48
49 protected:
50   class Creator;
51
52 public:
53   QtxActionMgr( QObject* parent );
54   virtual ~QtxActionMgr();
55
56   virtual int      registerAction( QAction*, const int = -1 );
57   virtual void     unRegisterAction( const int );
58
59   QAction*         action( const int ) const;
60   int              actionId( const QAction* ) const;
61   bool             contains( const int ) const;
62
63   int              count() const;
64   bool             isEmpty() const;
65   void             idList( QIntList& ) const;
66
67   bool             isUpdatesEnabled() const;
68   virtual void     setUpdatesEnabled( const bool );
69
70   virtual bool     isVisible( const int, const int ) const;
71   virtual void     setVisible( const int, const int, const bool );
72
73   void             update();
74
75   virtual bool     isEnabled( const int ) const;
76   virtual void     setEnabled( const int, const bool );
77
78   static QAction*  separator( const bool = false );
79
80 protected:
81   virtual void     internalUpdate();
82   int              generateId() const;
83
84 private:
85   typedef QGuardedPtr<QAction> ActionPtr;
86   typedef QMap<int, ActionPtr> ActionMap;
87
88 private:
89   bool             myUpdate;
90   ActionMap        myActions;
91 };
92
93
94 QTX_EXPORT typedef QMap<QString, QString> ItemAttributes;
95
96 class QtxActionMgr::Creator
97 {
98 public:
99   Creator( QtxActionMgr::Reader* );
100   virtual ~Creator();
101
102   Reader* reader() const;
103
104   virtual int append( const QString&, const bool,
105                       const ItemAttributes&, const int ) = 0;
106   virtual void connect( QAction* ) const;
107
108   virtual bool loadPixmap( const QString&, QPixmap& ) const;
109
110 protected:
111   static int     intValue( const ItemAttributes&, const QString&, const int );
112   static QString strValue( const ItemAttributes&, const QString&,
113                                       const QString& = QString::null );
114 private:
115   QtxActionMgr::Reader*  myReader;
116 };
117
118 class QtxActionMgr::Reader
119 {
120 public:
121   QTX_EXPORT Reader();
122   QTX_EXPORT virtual ~Reader();
123
124   QTX_EXPORT QStringList  options() const;
125   QTX_EXPORT QString      option( const QString&, const QString& = QString::null ) const;
126   QTX_EXPORT void         setOption( const QString&, const QString& );
127
128   QTX_EXPORT virtual bool read( const QString&, Creator& ) const = 0;
129
130 private:
131   QMap< QString, QString > myOptions;
132 };
133
134 class QtxActionMgr::XMLReader : public Reader
135 {
136 public:
137   QTX_EXPORT XMLReader( const QString&, const QString&, const QString& );
138   QTX_EXPORT virtual ~XMLReader();
139
140   QTX_EXPORT virtual bool read( const QString&, Creator& ) const;
141
142 protected:
143   QTX_EXPORT virtual void read( const QDomNode&, const int, Creator& ) const;
144   QTX_EXPORT virtual bool isNodeSimilar( const QDomNode&, const QString& ) const;
145 };
146
147
148 #endif