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