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