Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxActionMgr.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      QtxActionMgr.h
23 // Author:    Alexander SOLOVYOV, Sergey TELKOV
24 //
25 #ifndef QTXACTIONMGR_H
26 #define QTXACTIONMGR_H
27
28 #include "Qtx.h"
29
30 #include <QMap>
31 #include <QObject>
32 #include <QPointer>
33
34 class QTimer;
35 class QAction;
36 class QDomNode;
37
38 #ifdef WIN32
39 #pragma warning( disable:4251 )
40 #endif
41
42
43 class QTX_EXPORT QtxActionMgr : public QObject
44 {
45   Q_OBJECT 
46
47   class SeparatorAction;
48
49 public:
50   class Reader;
51   class XMLReader;
52
53 protected:
54   class Creator;
55
56 public:
57   QtxActionMgr( QObject* parent );
58   virtual ~QtxActionMgr();
59
60   virtual int      registerAction( QAction*, const int = -1 );
61   virtual void     unRegisterAction( const int );
62
63   QAction*         action( const int ) const;
64   int              actionId( const QAction* ) const;
65   bool             contains( const int ) const;
66
67   int              count() const;
68   bool             isEmpty() const;
69   QIntList         idList() const;
70
71   bool             isUpdatesEnabled() const;
72   virtual void     setUpdatesEnabled( const bool );
73
74   virtual bool     isVisible( const int, const int ) const;
75   virtual void     setVisible( const int, const int, const bool );
76
77   void             update();
78
79   virtual bool     isEnabled( const int ) const;
80   virtual void     setEnabled( const int, const bool );
81
82   static QAction*  separator( const bool = false );
83
84 protected:
85   virtual void     internalUpdate();
86   int              generateId() const;
87
88   void             triggerUpdate();
89   virtual void     updateContent();
90
91 private slots:
92   void             onUpdateContent();
93
94 private:
95   typedef QPointer<QAction>    ActionPtr; //!< Action guarded pointer
96   typedef QMap<int, ActionPtr> ActionMap; //!< Actions map
97
98 private:
99   bool             myUpdate;     //!< update flag
100   ActionMap        myActions;    //!< actions map
101   QTimer*          myUpdTimer;   //!< update timer
102 };
103
104
105 QTX_EXPORT typedef QMap<QString, QString> ItemAttributes; //!< attributes map
106
107 class QTX_EXPORT QtxActionMgr::Creator
108 {
109 public:
110   Creator( QtxActionMgr::Reader* );
111   virtual ~Creator();
112
113   Reader* reader() const;
114
115   virtual int    append( const QString&, const bool,
116                          const ItemAttributes&, const int ) = 0;
117   virtual void   connect( QAction* ) const;
118
119   virtual bool   loadPixmap( const QString&, QPixmap& ) const;
120
121 protected:
122   static int     intValue( const ItemAttributes&, const QString&, const int );
123   static QString strValue( const ItemAttributes&, const QString&,
124                            const QString& = QString() );
125 private:
126   QtxActionMgr::Reader*  myReader;  //!< actions reader
127 };
128
129 class QTX_EXPORT QtxActionMgr::Reader
130 {
131 public:
132   Reader();
133   virtual ~Reader();
134
135   QStringList    options() const;
136   QString        option( const QString&, const QString& = QString() ) const;
137   void           setOption( const QString&, const QString& );
138
139   virtual bool   read( const QString&, Creator& ) const = 0;
140
141 private:
142   QMap< QString, QString > myOptions;  //!< options map
143 };
144
145 class QTX_EXPORT QtxActionMgr::XMLReader : public Reader
146 {
147 public:
148   XMLReader( const QString&, const QString&, const QString& );
149   virtual ~XMLReader();
150
151   virtual bool   read( const QString&, Creator& ) const;
152
153 protected:
154   virtual void   read( const QDomNode&, const int, Creator& ) const;
155   virtual bool   isNodeSimilar( const QDomNode&, const QString& ) const;
156 };
157
158
159 #endif