Salome HOME
Copyrights update
[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
30 class QAction;
31 class QDomNode;
32
33
34 #ifdef WIN32
35 #pragma warning( disable:4251 )
36 #endif
37
38 class QTX_EXPORT QtxActionMgr : public QObject
39 {
40   Q_OBJECT 
41
42   class SeparatorAction;
43
44 public:
45   class Reader;
46   class XMLReader;
47
48 protected:
49   class Creator;
50
51 public:
52   QtxActionMgr( QObject* parent );
53   virtual ~QtxActionMgr();
54
55   virtual int      registerAction( QAction*, const int = -1 );
56   virtual void     unRegisterAction( const int );
57
58   QAction*         action( const int ) const;
59   int              actionId( const QAction* ) const;
60   bool             contains( const int ) const;
61
62   int              count() const;
63   bool             isEmpty() const;
64   void             idList( QIntList& ) const;
65
66   bool             isUpdatesEnabled() const;
67   virtual void     setUpdatesEnabled( const bool );
68
69   virtual bool     isVisible( const int, const int ) const;
70   virtual void     setVisible( const int, const int, const bool );
71
72   void             update();
73
74   virtual bool     isEnabled( const int ) const;
75   virtual void     setEnabled( const int, const bool );
76
77   static QAction*  separator( const bool = false );
78
79 protected:
80   virtual void     internalUpdate();
81   int              generateId() const;
82
83 private:
84   typedef QMap<int, QAction*>  ActionMap;
85
86 private:
87   bool             myUpdate;
88   ActionMap        myActions;
89 };
90
91
92 QTX_EXPORT typedef QMap<QString, QString> ItemAttributes;
93
94 class QtxActionMgr::Creator
95 {
96 public:
97   Creator( QtxActionMgr::Reader* );
98   virtual ~Creator();
99
100   Reader* reader() const;
101
102   virtual int append( const QString&, const bool,
103                       const ItemAttributes&, const int ) = 0;
104   virtual void connect( QAction* ) const;
105
106   virtual bool loadPixmap( const QString&, QPixmap& ) const;
107
108 protected:
109   static int     intValue( const ItemAttributes&, const QString&, const int );
110   static QString strValue( const ItemAttributes&, const QString&,
111                                       const QString& = QString::null );
112 private:
113   QtxActionMgr::Reader*  myReader;
114 };
115
116 class QtxActionMgr::Reader
117 {
118 public:
119   QTX_EXPORT Reader();
120   QTX_EXPORT virtual ~Reader();
121
122   QTX_EXPORT QStringList  options() const;
123   QTX_EXPORT QString      option( const QString&, const QString& = QString::null ) const;
124   QTX_EXPORT void         setOption( const QString&, const QString& );
125
126   QTX_EXPORT virtual bool read( const QString&, Creator& ) const = 0;
127
128 private:
129   QMap< QString, QString > myOptions;
130 };
131
132 class QtxActionMgr::XMLReader : public Reader
133 {
134 public:
135   QTX_EXPORT XMLReader( const QString&, const QString&, const QString& );
136   QTX_EXPORT virtual ~XMLReader();
137
138   QTX_EXPORT virtual bool read( const QString&, Creator& ) const;
139
140 protected:
141   QTX_EXPORT virtual void read( const QDomNode&, const int, Creator& ) const;
142   QTX_EXPORT virtual bool isNodeSimilar( const QDomNode&, const QString& ) const;
143 };
144
145
146 #endif