Salome HOME
ENV: Windows porting
[modules/gui.git] / src / SalomeApp / SalomeApp_Dialog.h
1 // File:      SalomeApp_Dialog.h
2 // Author:    Alexander SOLOVYOV
3
4 #ifndef SALOMEAPP_DIALOG_H
5 #define SALOMEAPP_DIALOG_H
6
7 #include <QtxDialog.h>
8
9 #include <qvaluelist.h>
10 #include <qmap.h>
11 #include <qpixmap.h>
12
13 class QLineEdit;
14 class QButton;
15 class QLabel;
16
17 class SUIT_ResourceMgr;
18
19 /*
20   Class       : SalomeApp_Dialog
21   Description : Base class for all SALOME dialogs
22 */
23 class SalomeApp_Dialog : public QtxDialog
24 {
25   Q_OBJECT
26   
27 public:
28   typedef QValueList<int>        TypesList;
29   typedef QMap<int,QStringList>  SelectedObjects;
30   
31   enum ObjectWg
32   {
33     Label   = 0x00000001,
34     Btn     = 0x00000002,
35     Control = 0x00000004
36   };
37   
38   typedef enum
39   {
40     OneName,           //<! only one object can be selected and it's name is shown
41     OneNameOrCount,    //<! if one object is selected, it's name is shown otherwise 
42                        // "<count> <type>" is shown
43     ListOfNames,       //! list of all names is shown
44     Count              //! In every case "<count> <type>" is shown
45     
46   } NameIndication;
47   //! The enumeration describing how names of selected objects will be shown in line edit
48   //! For more details see above
49
50 public:
51   SalomeApp_Dialog( QWidget* = 0, const char* = 0, bool = false,
52                     bool = false, const int = Standard, WFlags = 0 );
53   virtual ~SalomeApp_Dialog();
54   
55   virtual void    show();
56
57   //! Check if buttons is exclusive (as radiobuttons)
58   bool isExclusive() const;
59   
60   //! Set exclusive state  
61   void setExclusive( const bool );
62
63   //! Check if operation according to dialog will be resumed automatically when mouse enter the dialog
64   bool isAutoResumed() const;
65
66   //! Set auto resumed state
67   void setAutoResumed( const bool );
68
69   //! Show widgets corresponding to id
70   void showObject( const int );
71
72   //! Hide widgets corresponding to id
73   void hideObject( const int );
74
75   //! Change the shown state of widgets corresponding to id  
76   void setObjectShown( const int, const bool );
77
78   //! Check the shown state
79   bool isObjectShown( const int ) const;
80
81   //! Change the enabled state of widgets corresponding to id
82   void setObjectEnabled( const int, const bool );
83
84   //! Check the enabled state
85   bool isObjectEnabled( const int ) const;
86   
87   //! Get widget of object (see ObjectWg enumeration)
88   QWidget* objectWg( const int theId, const int theWgId ) const;
89   
90   //! Pass to all active widgets name, type and id of selected object          
91   void selectObject( const QString&, const int, const QString&, const bool = true );
92
93   /*!
94       Pass to all active widgets list of names, types and ids of selected objects
95       Every active widget filters list and accept only objects with possible types
96   */
97   void selectObject( const QStringList&, const TypesList&, const QStringList&, const bool = true );
98   
99   //! Get text of object's control
100   QString objectText( const int ) const;
101   
102   //! Set text of object's control
103   void setObjectText( const int, const QString& );
104
105   //! Select in certain widget avoiding check if there is active widget
106   void selectObject( const int, const QString&, const int, const QString&, const bool = true );
107   void selectObject( const int, const QStringList&, const TypesList&, const QStringList&, const bool = true );
108   
109   //! Check if certain widget has selection  
110   bool hasSelection( const int ) const;
111
112   //! Clear selection in widgets. If parameter is -1, then selection in all widgets will be cleared
113   void clearSelection( const int = -1 );
114
115   //! Get ids list of object selected in certain widget
116   void selectedObject( const int, QStringList& ) const;
117   
118   //! Get ids list of object selected in certain widget
119   QString selectedObject( const int ) const;
120
121   //! Get map "widget id -> ids list"
122   void objectSelection( SelectedObjects& ) const;
123   
124   //! Activate object selection button
125   void activateObject( const int );
126
127   //! Set all object selection buttons to inactive state
128   void deactivateAll();
129   
130 signals:
131   //! selection in certain widget is changed
132   void selectionChanged ( int );
133
134   //! selection in certain widget is on
135   void objectActivated  ( int );
136
137   //! selection in certain widget is off  
138   void objectDeactivated( int );
139
140   /*
141      text representation of selection is changed
142      it is emitted only if "read only" state of line edit is false
143   */
144   void objectChanged( int, const QStringList& );
145                                                    
146 protected:
147   //! Finds and returns resource manager
148   SUIT_ResourceMgr* resMgr() const;
149   
150   /*! Create label, button and line edit for object selection
151    *  If passed id is negative, then id will be calculated automatically (first free id)
152    *  Returns the same id (if id>=0) or calculated
153   */
154   int  createObject    ( const QString&, QWidget*, const int = -1 );
155
156   //! Set pixmap as icon for all selection buttons
157   void setObjectPixmap ( const QPixmap& );
158
159   //! Load pixmap with section, name using resource manager and set as icon for all selection buttons
160   void setObjectPixmap ( const QString&, const QString& );
161
162   //! Change label
163   void renameObject    ( const int, const QString& );
164
165   //! Set possible types for certain id. The list of arguments must be finished by negative integer
166   void setObjectType   ( const int, const int, ... );
167
168   //! Set list as possible types for object selection
169   void setObjectType   ( const int, const TypesList& );
170
171   /*!
172       Add types to list of possible types
173       The list of arguments must be finished by negative integer
174   */
175   void addObjectType   ( const int, const int, const int, ... );
176
177   //! Add types to list of possible types
178   void addObjectType   ( const int, const TypesList& );
179
180   //! Add type to list of possible types
181   void addObjectType   ( const int, const int );
182
183   //! Clear list of possible types (it means, that all types are welcome)  
184   void removeObjectType( const int );
185
186   //! Remove types in list from list of possible types
187   void removeObjectType( const int, const TypesList& );
188
189   //! Remove a type from list of possible types
190   void removeObjectType( const int, const int );
191   
192   //! Check if list of possible types contains this one
193   bool hasObjectType   ( const int, const int ) const;
194
195   //! Return list of possible types
196   void objectTypes     ( const int, TypesList& ) const;
197   
198   //!Change and get type name for indicating in selection widget
199   QString& typeName( const int );
200   const QString& typeName( const int ) const;
201   
202   //! Create string contains selection list by list of names, list of types and current name indication state
203   virtual QString selectionDescription( const QStringList&, const TypesList&, const NameIndication ) const;
204   
205   //! Create string by pattern "<count> <type>" for current list of types
206   virtual QString countOfTypes( const TypesList& ) const;
207
208   //! Get and set name indication for certain widget
209   NameIndication nameIndication( const int ) const;
210   void           setNameIndication( const int, const NameIndication );
211
212   //! Check using name indication if multiple selection in possible
213   bool           multipleSelection( const int ) const;
214
215   //! Set the "read only" state of object selection line edit
216   //! The "read only" will be false only if name indication is ListOfNames
217   void           setReadOnly( const int, const bool );
218
219   //! Check the "read only" state of object selection line edit
220   bool           isReadOnly( const int ) const;
221   
222 private slots:
223   //! emits if the object selection button changes state
224   void onToggled( bool );
225
226   //! text in some line edit is changed
227   void onTextChanged( const QString& );
228
229 private:
230   /*!
231      If buttons are exclusive, set to "off" all buttons except one with id
232      If id=-1, then all buttons, except first with "on" state, will be set to "off"
233   */
234   void    updateButtons( const int = -1 );
235
236   /*!
237       Filter types and update selection string in line edit
238       If bool is true, then signal is emitted
239   */
240   void    updateObject( const int, bool = true );
241
242   //! Remove from list not possible types and remove from names and ids lists the corresponding items
243   void    filterTypes( const int, QStringList&, TypesList&, QStringList& ) const;
244   
245 private:
246   typedef struct
247   {
248     QLineEdit*      myEdit;
249     QButton*        myBtn;
250     QLabel*         myLabel;
251     QStringList     myNames, myIds;
252     TypesList       myTypes, myPossibleTypes;
253     NameIndication  myNI;
254     
255   } Object;
256   
257   typedef QMap<int, Object> ObjectMap;
258   
259 private:
260   ObjectMap           myObjects;
261   QMap<int,QString>   myTypeNames;
262   bool                myIsExclusive, myIsBusy;
263   QPixmap             myPixmap;
264 };
265
266 #endif