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