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