Salome HOME
Copyrights update
[modules/gui.git] / src / Qtx / QtxPopupMgr.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
20 #ifndef __QTX_POPUP_MGR_HEADER__
21 #define __QTX_POPUP_MGR_HEADER__
22
23 #include "Qtx.h"
24 #include "QtxActionMenuMgr.h"
25 #include "QtxParser.h"
26 #include "QtxStdOperations.h"
27
28 #include <qmap.h>
29
30 class QtxListOfOperations;
31
32 //================================================================
33 // Class    : 
34 // Purpose  : 
35 //================================================================
36 class QTX_EXPORT QtxPopupMgr : public QtxActionMenuMgr
37 {
38     Q_OBJECT
39
40 public:
41     class QTX_EXPORT Selection
42     {
43     public:
44         virtual int      count() const = 0;
45         virtual QtxValue param( const int, const QString& ) const = 0;
46               virtual QtxValue globalParam( const QString& ) const;
47
48               virtual QChar   equality() const;
49               virtual QString selCountParam() const;
50
51               static QChar    defEquality();
52               static QString  defSelCountParam();
53     };
54
55 protected:
56     class Operations : public QtxStrings
57     {
58     public:
59         Operations( QtxPopupMgr* );
60         virtual ~Operations();
61
62         virtual int   prior( const QString&, bool isBin ) const;
63         virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const;
64
65         void clear();
66
67     private:
68         QtxPopupMgr*               myPopupMgr;
69         QtxParser*                 myParser;
70         QMap< QString, QtxValue >  myValues;
71     };
72
73     friend class Operations;
74
75 protected:
76   class PopupCreator;
77
78 public:
79     QtxPopupMgr( QPopupMenu*, QObject* = 0 );
80     virtual ~QtxPopupMgr();
81
82     virtual int  registerAction( QAction*,
83                                  const QString& visible,
84                                  const QString& toggle = QString::null,
85                                  const int = -1 );
86     virtual void unRegisterAction( const int );
87
88     virtual bool isVisible( const int actId, const int place ) const;
89
90     bool    hasRule( QAction*, bool visibility ) const;
91     bool    hasRule( const int, bool visibility ) const;
92     void    setRule( QAction*, const QString&, bool visibility );
93     void    setRule( const int, const QString&, bool visibility );
94     void    updatePopup( QPopupMenu*, Selection* );
95
96     //return name of parameter corresponding to selected objects count
97     //it will be set automatically
98
99     virtual bool load( const QString&, QtxActionMgr::Reader& );
100
101 protected:
102     typedef QMap< QAction*, QtxParser* > RulesMap;
103
104 protected:
105     virtual bool      isSatisfied( QAction*, bool visibility ) const;
106             void      setParams( QtxParser*, QStringList& ) const;
107             RulesMap& map( bool visibility ) const;
108
109     void createOperations();
110
111 private:
112     RulesMap             myVisibility, myToggle;
113     Selection*           myCurrentSelection;
114     QtxListOfOperations* myOperations;
115 };
116
117
118
119 class QtxPopupMgr::PopupCreator : public QtxActionMgr::Creator
120 {
121 public:
122   PopupCreator( QtxActionMgr::Reader*, QtxPopupMgr* );
123   virtual ~PopupCreator();
124
125   virtual int append( const QString&, const bool,
126                       const ItemAttributes&, const int );
127
128   virtual QString visibleRule( const ItemAttributes& ) const;
129   virtual QString toggleRule( const ItemAttributes& ) const;
130
131 private:
132   QtxPopupMgr* myMgr;
133 };
134
135
136 #endif