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