Salome HOME
IPAL9008
[modules/gui.git] / src / SalomeApp / SalomeApp_ListView.h
1 //  SALOME SalomeApp
2 //
3 //  Copyright (C) 2005  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SalomeApp_ListView.h
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #ifndef SALOMEAPP_LISTVIEW_H
13 #define SALOMEAPP_LISTVIEW_H
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 <TColStd_ListOfInteger.hxx>
29 #include <TColStd_ListOfReal.hxx>
30
31 #include <SUIT_PopupClient.h>
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 SalomeApp_ListViewItem;
44 class SalomeApp_EntityEdit;
45
46 //================================================================
47 // Class        : SalomeApp_ListView
48 // Description  : parent class for Data Viewer and Properties Viewer
49 //================================================================
50 class SalomeApp_ListView : public QListView , public SUIT_PopupClient  {
51   
52   Q_OBJECT
53     
54 public:
55 // constructor  
56   SalomeApp_ListView(QWidget *parent);
57 // destructor  
58   virtual ~SalomeApp_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   virtual QString popupClientType() const;
67   virtual void    contextMenuPopup( QPopupMenu* );
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 resize event
88   void resizeEvent(QResizeEvent* e);
89 // handler for paint event
90   void viewportPaintEvent(QPaintEvent* e);
91 // finishes editing of entity
92   virtual UpdateType finishEditing(bool ok);
93
94 // returns true if mouse events are enabled
95   bool isMouseEnabled();
96 // enables/disables mouse events (excluding MouseMove)
97   void enableMouse(bool enable);
98   
99 protected slots:
100 // called when selection changed in list
101   virtual void onSelectionChanged();
102 // called when user finishes in editing of item
103   void onEditOk();
104 // called when user cancels item editing
105   void onEditCancel();
106 // called when columns sizes are changed
107   void onHeaderSizeChange(int, int, int);
108
109 protected:
110   SalomeApp_EntityEdit*   myEdit;
111   SalomeApp_ListViewItem* myEditedItem;
112   bool                    myEditingEnabled;
113   bool                    myMouseEnabled;
114 };
115
116
117 class SalomeApp_EditBox: public QLineEdit
118 {
119   Q_OBJECT
120
121 public:
122   SalomeApp_EditBox(QWidget* parent);
123  
124 protected:
125   void keyPressEvent(QKeyEvent* e);
126   
127 signals:
128   void escapePressed();
129 };
130
131 class SalomeApp_ComboBox: public QComboBox 
132 {
133   Q_OBJECT
134
135 public:
136   SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
137
138   int findItem(const QString& theText);
139   void insertItem(const QString& theValue, int theIndex = -1);
140   void insertList(const QStringList& theList);
141   void insertItem(const int theValue);
142   void insertList(const TColStd_ListOfInteger& theList);
143   void insertItem(const double theValue);
144   void insertList(const TColStd_ListOfReal& theList);
145 };
146
147 class SalomeApp_EntityEdit : public QWidget 
148 {
149   Q_OBJECT
150
151 public:
152   // enum for edit control type
153   enum {
154     etLineEdit,           // simple edit box
155     etComboBox,           // non-editable combo box
156     etComboEdit           // editable combo box
157   };
158   // enum for value type
159   enum {
160     vtString,             // string
161     vtInteger,            // integer value
162     vtDouble              // double value
163   };
164   // enum for insertion order
165   enum {
166     atBottom,
167     atTop,
168     atBeforeCurrent,
169     atAfterCurrent
170   };
171   // enum for edit box buttons (Apply = Cancel)
172   enum {
173     btApply  = 0x0001,
174     btCancel = 0x0002
175   };
176
177 public:
178   SalomeApp_EntityEdit( QWidget* parent, 
179                         int      controlType = etLineEdit, 
180                         int      valueType   = vtString,
181                         bool     butApply    = false, 
182                         bool     butCancel   = false);
183   ~SalomeApp_EntityEdit();
184
185   void finishEditing();
186   void clear();
187   QString getText();
188   void setText(const QString& theText );
189   void insertItem( const QString& theValue, 
190                    bool           theSetCurrent = false,
191                    int            theOrder = atBottom );
192   void insertList( const QStringList& theList, 
193                    const int          theCurrent = -1 );
194   void insertItem( const int theValue, 
195                    bool  theSetCurrent = false );
196   void insertList( const TColStd_ListOfInteger& theList, 
197                    const int                    theCurrent = -1 );
198   void insertItem( const double theValue, 
199                    bool         theSetCurrent = false );
200   void insertList( const TColStd_ListOfReal& theList, 
201                    const int                 theCurrent = -1 );
202   QWidget* getControl();
203   void setFocus();
204   void setValidator(const QValidator*);
205   void showButtons(bool show);
206   void setDuplicatesEnabled(bool enabled);
207
208 protected:
209   void keyPressEvent ( QKeyEvent * e);
210
211 private slots:
212   void onComboActivated(const QString&);
213   void onTextChanged(const QString&);
214   void onApply();
215   void onCancel();
216 signals:
217   void returnPressed();
218   void escapePressed();
219
220 private:
221   // Widgets
222   SalomeApp_EditBox*   myEdit;
223   SalomeApp_ComboBox*  myCombo;
224   QToolButton*         myApplyBtn;
225   QToolButton*         myCancelBtn;
226   QString              myString;
227 };
228
229 class SalomeApp_ListViewItem : public QListViewItem
230 {
231 public:
232   SalomeApp_ListViewItem( SalomeApp_ListView* );
233   SalomeApp_ListViewItem( SalomeApp_ListView*, 
234                           SalomeApp_ListViewItem* );
235   SalomeApp_ListViewItem( SalomeApp_ListView*,
236                           const QString&,
237                           const bool = false );
238   SalomeApp_ListViewItem( SalomeApp_ListView*,
239                           const QString& theName,
240                           const QString& theValue, 
241                           const bool = false );
242   SalomeApp_ListViewItem( SalomeApp_ListViewItem* theParent,
243                           const QString&,
244                           const bool = false );
245   SalomeApp_ListViewItem( SalomeApp_ListView*,
246                           SalomeApp_ListViewItem*,
247                           const QString&,
248                           const bool = false );
249   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
250                           SalomeApp_ListViewItem*,
251                           const QString&,
252                           const bool = false);
253   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
254                           const QString& theName,
255                           const QString& theValue, 
256                           const bool = false);
257   SalomeApp_ListViewItem( SalomeApp_ListView*,
258                           SalomeApp_ListViewItem*,
259                           const QString& theName,
260                           const QString& theValue, 
261                           const bool = false);
262   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
263                           SalomeApp_ListViewItem*,
264                           const QString&,
265                           const QString&, 
266                           const bool = false);
267   ~SalomeApp_ListViewItem();
268
269   QString            fullName();
270   void               openAllLevels();
271   virtual void       updateAllLevels();
272   bool               isEditable() const;
273   void               setEditable(bool theEditable);
274
275   // returns true if entitiy is accepted after editing
276   bool               isAccepted() const;
277   // set entity accepted or not after editing
278   void               setAccepted(bool theAccepted);
279
280   // returns name of entity (as default it is text in first column)
281   virtual QString    getName() const;
282   // sets name of entity (as default it is text in first column)
283   virtual UpdateType setName(const QString& theName);
284
285   // returns value of entity (as default it is text in second column)
286   virtual QString    getValue() const;
287   // sets value of entity (as default it is text in second column)
288   virtual UpdateType setValue(const QString& theValue);
289
290   // creates control for editing and fills it with values
291   SalomeApp_EntityEdit*    startEditing();
292   // fills widget with initial values (list or single value)
293   virtual void       fillWidgetWithValues(SalomeApp_EntityEdit* theWidget);
294   // finishes editing of entity
295   virtual UpdateType finishEditing(SalomeApp_EntityEdit* theWidget);
296
297   // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
298   virtual int        getEditingType();
299   // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
300   virtual void       setEditingType(const int);
301   // returns edited column
302   virtual int        getEditedColumn();
303   // returns type of edited value (string, int, double)
304   virtual int        getValueType();
305   // sets type of edited value (string, int, double)
306   virtual void       setValueType(const int);
307
308   // gets user type 
309   virtual int        getUserType();
310   // sets user type 
311   virtual void       setUserType(const int);
312
313   // returns buttons for editing widget
314   virtual int        getButtons();
315   // sets  buttons for editing widget
316   virtual void       setButtons(const int);
317   // returns text for tooltip
318   QString            tipText();
319   // calculates rectangle which should contain items tip
320   QRect              tipRect();
321   // calculates rect of item text in viewport coordinates
322   QRect              textRect(const int column) const;
323   // calculates full rect of item data in viewport coordinates
324   QRect              itemRect(const int column) const;
325
326 protected:
327   // initialization
328   void               init();
329
330 private:
331   bool myEditable;
332   bool myAccepted;
333   int  myEditingType;
334   int  myValueType;
335   int  myButtons;
336   int  myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
337 };
338
339
340 #endif