Salome HOME
First integration of Salome On Demand
[modules/gui.git] / src / LightApp / LightApp_ModuleAction.h
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : LightApp_ModuleAction.h
21 // Author : Sergey TELKOV, Vadim SANDLER
22 //
23 #ifndef LIGHTAPP_MODULEACTION_H
24 #define LIGHTAPP_MODULEACTION_H
25
26 #include "LightApp.h"
27
28 #include <QtxAction.h>
29
30 #ifdef WIN32
31 #pragma warning ( disable:4251 )
32 #endif
33
34 class QtxComboBox;
35 class QtxResourceMgr;
36 class QSignalMapper;
37
38 class LIGHTAPP_EXPORT LightApp_ModuleAction : public QtxAction
39 {
40   Q_OBJECT
41
42 private:
43   class ActionSet;
44   class ComboAction;
45   class ActivateEvent;
46
47 public:
48   typedef enum { Buttons   = 0x01,
49                  List      = 0x02,
50                  AddRemove = 0x04,
51                  All       = Buttons | List | AddRemove
52   } Mode;
53
54 public:
55   LightApp_ModuleAction( QtxResourceMgr*, QObject* = 0 );
56   virtual ~LightApp_ModuleAction();
57
58   int              count() const;
59   QStringList      modules() const;
60
61   QIcon            moduleIcon( const QString& ) const;
62   void             setModuleIcon( const QString&, const QIcon& );
63
64   QAction*         moduleAction( const QString& ) const;
65
66   void             insertModule( const QString&, const QIcon&, const int = -1 );
67   void             insertModule( const QString&, const QIcon&, bool, const int = -1 );
68   void             removeModule( const QString& );
69   void             insertExtension(const QString&);
70   void             removeExtension(const QString&);
71   void             updateExtActions();
72
73   QString          activeModule() const;
74
75   void             setMode( const Mode& );
76   void             setModeEnabled( const Mode&, bool );
77   bool             isModeEnabled( const Mode& ) const;
78
79 public slots:
80   void             setActiveModule( const QString& );
81
82
83 protected:
84   virtual void     addedTo( QWidget* );
85   virtual void     removedFrom( QWidget* );
86
87   virtual bool     event( QEvent* );
88
89 signals:
90   void             moduleActivated( const QString& );
91   void             adding();
92   void             removing( const QString& );
93   void             showExtInfo();
94
95 private:
96   void             update();
97   void             update( QtxComboBox* );
98
99   QAction*         active() const;
100   void             activate( int, bool = true );
101
102 private slots:
103   void             onChanged();
104   void             onTriggered( int );
105   void             onComboActivated( int );
106
107 private:
108   ComboAction*     myCombo;
109   QtxAction*       myAdd;
110   QtxAction*       myRemove;
111   QtxAction*       myInfo;
112   ActionSet*       mySet;
113   QAction*         mySeparator;
114   int              myMode;
115   QSignalMapper*   myMapper;
116 };
117
118 class LightApp_ModuleAction::ComboAction : public QtxAction
119 {
120   Q_OBJECT
121
122 public:
123   ComboAction( QObject* parent );
124
125   QList<QtxComboBox*> widgets() const;
126
127 signals:
128   void                activatedId( int );
129
130 protected:
131   virtual QWidget*    createWidget( QWidget* );
132 };
133
134 #endif // LIGHTAPP_MODULEACTION_H