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