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