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