Salome HOME
1048e8b4c496a24e0ebc1d6bf84da2f1e459a988
[modules/gui.git] / src / LightApp / LightApp_ModuleAction.h
1 // Copyright (C) 2007-2020  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
36 class LIGHTAPP_EXPORT LightApp_ModuleAction : public QtxAction
37 {
38   Q_OBJECT
39
40 private:
41   class ActionSet;
42   class ComboAction;
43   class ActivateEvent;
44
45 public:
46   enum { None = 0x00, Buttons = 0x01, ComboItem = 0x02, All = Buttons | ComboItem };
47
48 public:
49   LightApp_ModuleAction( const QString&, QObject* = 0 );
50   LightApp_ModuleAction( const QString&, const QIcon&, QObject* = 0 );
51   virtual ~LightApp_ModuleAction();
52
53   int              count() const;
54   QStringList      modules() const;
55
56   QIcon            moduleIcon( const QString& ) const;
57   void             setModuleIcon( const QString&, const QIcon& );
58
59   QAction*         moduleAction( const QString& ) const;
60
61   void             insertModule( const QString&, const QIcon&, const int = -1 );
62   void             removeModule( const QString& );
63
64   QString          activeModule() const;
65   void             setActiveModule( const QString& );
66
67   void             setMode( const int );
68   int              mode() const;
69
70 protected:
71   virtual void     addedTo( QWidget* );
72   virtual void     removedFrom( QWidget* );
73
74   virtual bool     event( QEvent* );
75
76 signals:
77   void             moduleActivated( const QString& );
78
79 private:
80   void             init();
81
82   void             update();
83   void             update( QtxComboBox* );
84
85   QAction*         active() const;
86   void             activate( int, bool = true );
87
88 private slots:
89   void             onChanged();
90   void             onTriggered( int );
91   void             onComboActivated( int );
92
93 private:
94   ComboAction*     myCombo;
95   ActionSet*       mySet;
96   int              myMode;
97 };
98
99 class LightApp_ModuleAction::ComboAction : public QtxAction
100 {
101   Q_OBJECT
102
103 public:
104   ComboAction( QObject* parent );
105
106   QList<QtxComboBox*> widgets() const;
107
108 signals:
109   void                activatedId( int );
110
111 protected:
112   virtual QWidget*    createWidget( QWidget* );
113 };
114
115 #endif // LIGHTAPP_MODULEACTION_H