Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / SALOMEGUI / QAD_ListView.h
1 //  File      : QAD_ListView.h
2 //  Created   : 24/10/2002
3 //  Descr     : List view for editing of properties
4
5 //  Author    : Vadim SANDLER
6 //  Project   : SALOME Pro
7 //  Module    : SALOMEGUI 
8 //  Copyright : Open CASCADE
9 //  $Header$
10
11 #if !defined(_QAD_ListView_HeaderFile)
12 #define _QAD_ListView_HeaderFile
13
14 #include <qlistview.h>
15 #include <qlist.h>
16 #include <qstring.h>
17 #include <qpixmap.h>
18 #include <qlineedit.h>
19 #include <qcombobox.h>
20
21 //VRV: porting on Qt 3.0.5
22 #if QT_VERSION >= 0x030005
23 #include <qtoolbutton.h> 
24 #endif
25 //VRV: porting on Qt 3.0.5
26
27 #include "QAD_Popup.h"
28
29 #include <TColStd_ListOfInteger.hxx>
30 #include <TColStd_ListOfReal.hxx>
31
32 // enumeration for ListView updating mode
33 enum UpdateType {
34   utCancel        = -1,           // cancel updating
35   utNone          =  0,           // needs no any update
36   utUpdateItem,                   // update one item
37   utUpdateParent,                 // update parent item too
38   utUpdateViewer,                 // update all viewer
39   utUpdateAll                     // strong update
40 };
41
42 class QAD_ListViewItem;
43 class QAD_EntityEdit;
44
45 //================================================================
46 // Class        : QAD_ListView
47 // Description  : parent class for Data Viewer and Properties Viewer
48 //================================================================
49 class QAD_ListView : public QListView , public QAD_PopupServer  {
50   
51   Q_OBJECT
52     
53 public:
54 // constructor  
55   QAD_ListView(QWidget *parent);
56 // destructor  
57   virtual ~QAD_ListView();
58
59 // updates list viewer
60   virtual void updateViewer();
61 // updtes currently selected item(s)
62   virtual void updateSelected();
63
64 // fills popup with items
65   void onCreatePopup();
66 // delete popup
67   void deletePopupMenu();
68
69 // setting editing of items availbale/not available
70   void enableEditing(bool theFlag);
71 // says if editing is enabled
72   bool isEnableEditing();
73 // accepts user input by calling finishEditing(true)
74   void accept();
75
76 // clears view
77   void clear();
78
79 // event filter
80   bool eventFilter(QObject* object, QEvent* event) ;
81
82 // gets current tooltip for list view
83 // returns valid rect in success
84   QRect tip(QPoint aPos, QString& aText, QRect& dspRect, QFont& dspFnt) const;
85
86 protected:
87 // handler for mouse button release event (execute popup menu)
88   void contentsMouseReleaseEvent(QMouseEvent* e);
89 // handler for resize event
90   void resizeEvent(QResizeEvent* e);
91 // handler for paint event
92   void viewportPaintEvent(QPaintEvent* e);
93 // finishes editing of entity
94   virtual UpdateType finishEditing(bool ok);
95
96 // returns true if mouse events are enabled
97   bool isMouseEnabled();
98 // enables/disables mouse events (excluding MouseMove)
99   void enableMouse(bool enable);
100   
101 protected slots:
102 // called when selection changed in list
103   virtual void onSelectionChanged();
104 // called when user finishes in editing of item
105   void onEditOk();
106 // called when user cancels item editing
107   void onEditCancel();
108 // called when columns sizes are changed
109   void onHeaderSizeChange(int, int, int);
110
111 protected:
112   QAD_EntityEdit*       myEdit;
113   QAD_ListViewItem*     myEditedItem;
114   bool                  myEditingEnabled;
115   bool                  myMouseEnabled;
116 };
117
118
119 //================================================================
120 // Class    : QAD_ListViewItem
121 // Purpose  : List Viewer entity
122 //================================================================
123 class QAD_ListViewItem : public QListViewItem {
124
125 public:
126 // constructor
127   QAD_ListViewItem(QAD_ListView*     parent);
128 // constructor
129   QAD_ListViewItem(QAD_ListView*     parent, 
130                    QAD_ListViewItem* after);
131 // constructor  
132   QAD_ListViewItem(QAD_ListView*     parent,
133                    const QString     theName,
134                    const bool        theEditable = false);
135 // constructor  
136   QAD_ListViewItem(QAD_ListView*     parent,
137                    const QString     theName,
138                    const QString     theValue, 
139                    const bool        theEditable = false);
140 // constructor
141   QAD_ListViewItem(QAD_ListViewItem* parent,
142                    const QString     theName,
143                    const bool        theEditable = false);
144 // constructor
145   QAD_ListViewItem(QAD_ListView*     parent,
146                    QAD_ListViewItem* after,
147                    const QString     theName,
148                    const bool        theEditable = false);
149 // constructor
150   QAD_ListViewItem(QAD_ListViewItem* parent,
151                    QAD_ListViewItem* after,
152                    const QString     theName,
153                    const bool        theEditable = false);
154 // constructor  
155   QAD_ListViewItem(QAD_ListViewItem* parent,
156                    const QString     theName,
157                    const QString     theValue, 
158                    const bool        theEditable = false);
159 // constructor  
160   QAD_ListViewItem(QAD_ListView*     parent,
161                    QAD_ListViewItem* after,
162                    const QString     theName,
163                    const QString     theValue, 
164                    const bool        theEditable = false);
165 // constructor  
166   QAD_ListViewItem(QAD_ListViewItem* parent,
167                    QAD_ListViewItem* after,
168                    const QString     theName,
169                    const QString     theValue, 
170                    const bool        theEditable = false);
171 // destructor
172   ~QAD_ListViewItem();
173
174 // returns full path to the entity (full name)
175   QString            fullName();
176   
177 // expands all entities beginning from this level
178   void               openAllLevels();
179 // updates all entites beginning from this level
180   virtual void       updateAllLevels();
181
182 // returns true if entity can be edited
183   bool               isEditable() const;
184 // set entity as editable/uneditable
185   void               setEditable(bool theEditable);
186
187 // returns true if entitiy is accepted after editing
188   bool               isAccepted() const;
189 // set entity accepted or not after editing
190   void               setAccepted(bool theAccepted);
191
192 // returns name of entity (as default it is text in first column)
193   virtual QString    getName() const;
194 // sets name of entity (as default it is text in first column)
195   virtual UpdateType setName(const QString theName);
196
197 // returns value of entity (as default it is text in second column)
198   virtual QString    getValue() const;
199 // sets value of entity (as default it is text in second column)
200   virtual UpdateType setValue(const QString theValue);
201
202 // creates control for editing and fills it with values
203   QAD_EntityEdit*    startEditing();
204 // fills widget with initial values (list or single value)
205   virtual void       fillWidgetWithValues(QAD_EntityEdit* theWidget);
206 // finishes editing of entity
207   virtual UpdateType finishEditing(QAD_EntityEdit* theWidget);
208
209 // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
210   virtual int        getEditingType();
211 // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
212   virtual void       setEditingType(const int);
213 // returns edited column
214   virtual int        getEditedColumn();
215 // returns type of edited value (string, int, double)
216   virtual int        getValueType();
217 // sets type of edited value (string, int, double)
218   virtual void       setValueType(const int);
219
220 // gets user type 
221   virtual int        getUserType();
222 // sets user type 
223   virtual void       setUserType(const int);
224
225 // returns buttons for editing widget
226   virtual int        getButtons();
227 // sets  buttons for editing widget
228   virtual void       setButtons(const int);
229 // returns text for tooltip
230   QString            tipText();
231 // calculates rectangle which should contain items tip
232   QRect              tipRect();
233 // calculates rect of item text in viewport coordinates
234   QRect              textRect(const int column) const;
235 // calculates full rect of item data in viewport coordinates
236   QRect              itemRect(const int column) const;
237
238 protected:
239 // initialization
240   void               init();
241
242 private:
243   bool myEditable;
244   bool myAccepted;
245   int  myEditingType;
246   int  myValueType;
247   int  myButtons;
248   int  myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
249 };
250
251
252 //================================================================
253 // Class        : QAD_EditBox
254 // Description  : edit box for list entity editing
255 //================================================================
256 class QAD_EditBox: public QLineEdit {
257
258   Q_OBJECT
259
260 public:
261 // constructor  
262   QAD_EditBox(QWidget* parent);
263   
264 protected:
265 // event filter (for KeyPress event)
266   void keyPressEvent(QKeyEvent* e);
267   
268 signals:
269   void escapePressed();
270
271 };
272
273
274 //================================================================
275 // Class        : QAD_ComboBox
276 // Description  : combo box for list entity editing
277 //================================================================
278 class QAD_ComboBox: public QComboBox {
279
280   Q_OBJECT
281
282 public:
283 // constructor
284   QAD_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
285
286 // searches item in list and returns its index
287   int findItem(const QString theText);
288 // adds item in combo box
289   void insertItem(const QString& theValue, int theIndex = -1);
290 // adds list of items in combo box
291   void insertList(const QStringList& theList);
292 // adds item in combo box
293   void insertItem(const int theValue);
294 // adds list of items in combo box
295   void insertList(const TColStd_ListOfInteger& theList);
296 // adds item in combo box
297   void insertItem(const double theValue);
298 // adds list of items in combo box
299   void insertList(const TColStd_ListOfReal& theList);
300   
301 };
302
303
304 //================================================================
305 // Class        : QAD_EntityEdit
306 // Description  : edit control for QAD List View
307 //================================================================
308 class QAD_EntityEdit : public QWidget {
309
310   Q_OBJECT
311   
312 public:
313 // enum for edit control type
314   enum {
315     etLineEdit,           // simple edit box
316     etComboBox,           // non-editable combo box
317     etComboEdit           // editable combo box
318   };
319 // enum for value type
320   enum {
321     vtString,             // string
322     vtInteger,            // integer value
323     vtDouble              // double value
324   };
325 // enum for insertion order
326   enum {
327     atBottom,
328     atTop,
329     atBeforeCurrent,
330     atAfterCurrent
331   };
332 // enum for edit box buttons (Apply = Cancel)
333   enum {
334     btApply  = 0x0001,
335     btCancel = 0x0002
336   };
337
338 // constructor
339   QAD_EntityEdit(QWidget* parent, 
340                      int      controlType = etLineEdit, 
341                      int      valueType   = vtString,
342                      bool     butApply    = false, 
343                      bool     butCancel   = false);
344 // destructor
345   ~QAD_EntityEdit();
346
347 // finishes editing
348   void finishEditing();
349 // clears edit/combo box
350   void clear();
351 // returns current text in edit box or combo box
352   QString getText();
353 // sets text
354   void setText(const QString& theText);
355 // adds item in combo box
356   void insertItem(const QString& theValue, 
357                   bool           theSetCurrent = false,
358                   int            theOrder = atBottom);
359 // adds list of items in combo box
360   void insertList(const QStringList& theList, 
361                   const int          theCurrent = -1);
362 // adds item in combo box
363   void insertItem(const int theValue, 
364                   bool  theSetCurrent = false);
365 // adds list of items in combo box
366   void insertList(const TColStd_ListOfInteger& theList, 
367                   const int                    theCurrent = -1);
368 // adds item in combo box
369   void insertItem(const double theValue, 
370                   bool         theSetCurrent = false);
371 // adds list of items in combo box
372   void insertList(const TColStd_ListOfReal& theList, 
373                   const int                 theCurrent = -1);
374 // gets actual widget
375   QWidget* getControl();
376 // redirect focus to corresponding widget
377   void setFocus();
378 // sets validator for the control
379   void setValidator(const QValidator*);
380 // shows/hides buttons
381   void showButtons(bool show);
382 // enables/disables data duplication (for combo box)
383   void setDuplicatesEnabled(bool enabled);
384
385 protected:
386 // event filter for KeyPress event
387   void keyPressEvent ( QKeyEvent * e);
388
389 private slots:
390 // called when item activated in combo box
391   void onComboActivated(const QString&);
392 // called when text changed in control
393   void onTextChanged(const QString&);
394 // called when user presses Apply button
395   void onApply();
396 // called when user presses Cancel button
397   void onCancel();
398
399 signals:
400   void returnPressed();
401   void escapePressed();
402
403 private:
404 // Widgets
405   QAD_EditBox*  myEdit;
406   QAD_ComboBox* myCombo;
407   QToolButton*      myApplyBtn;
408   QToolButton*      myCancelBtn;
409
410   QString           myString;
411
412 };
413
414
415 #endif