Salome HOME
acc92746eb9e36ad9ef8c0321e14d79c1138f65a
[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
70   QString          activeModule() const;
71
72   void             setMode( const Mode& );
73   void             setModeEnabled( const Mode&, bool );
74   bool             isModeEnabled( const Mode& ) const;
75
76 public slots:
77   void             setActiveModule( const QString& );
78
79
80 protected:
81   virtual void     addedTo( QWidget* );
82   virtual void     removedFrom( QWidget* );
83
84   virtual bool     event( QEvent* );
85
86 signals:
87   void             moduleActivated( const QString& );
88   void             adding();
89   void             removing( const QString& );
90
91 private:
92   void             update();
93   void             update( QtxComboBox* );
94
95   QAction*         active() const;
96   void             activate( int, bool = true );
97
98 private slots:
99   void             onChanged();
100   void             onTriggered( int );
101   void             onComboActivated( int );
102
103 private:
104   ComboAction*     myCombo;
105   QtxAction*       myAdd;
106   QtxAction*       myRemove;
107   ActionSet*       mySet;
108   QAction*         mySeparator;
109   int              myMode;
110   QSignalMapper*   myMapper;
111 };
112
113 class LightApp_ModuleAction::ComboAction : public QtxAction
114 {
115   Q_OBJECT
116
117 public:
118   ComboAction( QObject* parent );
119
120   QList<QtxComboBox*> widgets() const;
121
122 signals:
123   void                activatedId( int );
124
125 protected:
126   virtual QWidget*    createWidget( QWidget* );
127 };
128
129 #endif // LIGHTAPP_MODULEACTION_H