Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / SalomeApp / SalomeApp_ListView.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  SALOME SalomeApp
20 //
21 //  File   : SalomeApp_ListView.h
22 //  Author : Vadim SANDLER
23 //  Module : SALOME
24
25 #ifndef SALOMEAPP_LISTVIEW_H
26 #define SALOMEAPP_LISTVIEW_H
27
28 #include <QtxListView.h>
29
30 #include <qlist.h>
31 #include <qstring.h>
32 #include <qpixmap.h>
33 #include <qlineedit.h>
34 #include <qcombobox.h>
35
36 //VRV: porting on Qt 3.0.5
37 #if QT_VERSION >= 0x030005
38 #include <qtoolbutton.h> 
39 #endif
40 //VRV: porting on Qt 3.0.5
41
42 #include <TColStd_ListOfInteger.hxx>
43 #include <TColStd_ListOfReal.hxx>
44
45 #include <SUIT_PopupClient.h>
46
47 // enumeration for ListView updating mode
48 enum UpdateType {
49   utCancel        = -1,           // cancel updating
50   utNone          =  0,           // needs no any update
51   utUpdateItem,                   // update one item
52   utUpdateParent,                 // update parent item too
53   utUpdateViewer,                 // update all viewer
54   utUpdateAll                     // strong update
55 };
56
57 class SalomeApp_ListViewItem;
58 class SalomeApp_EntityEdit;
59
60 /*!
61   \class SalomeApp_ListView
62   parent class for Data Viewer and Properties Viewer
63 */
64 class SalomeApp_ListView : public QtxListView , public SUIT_PopupClient  {
65   
66   Q_OBJECT
67     
68 public:
69 // constructor  
70   SalomeApp_ListView(QWidget *parent);
71 // destructor  
72   virtual ~SalomeApp_ListView();
73
74 // updates list viewer
75   virtual void updateViewer();
76 // updtes currently selected item(s)
77   virtual void updateSelected();
78
79 // fills popup with items
80   virtual QString popupClientType() const;
81   virtual void    contextMenuPopup( QPopupMenu* );
82
83 // setting editing of items availbale/not available
84   void enableEditing(bool theFlag);
85 // says if editing is enabled
86   bool isEnableEditing();
87 // accepts user input by calling finishEditing(true)
88   void accept();
89
90 // clears view
91   void clear();
92
93 // event filter
94   bool eventFilter(QObject* object, QEvent* event) ;
95
96 // gets current tooltip for list view
97 // returns valid rect in success
98   QRect tip(QPoint aPos, QString& aText, QRect& dspRect, QFont& dspFnt) const;
99
100 protected:
101 // handler for resize event
102   void resizeEvent(QResizeEvent* e);
103 // handler for paint event
104   void viewportPaintEvent(QPaintEvent* e);
105 // finishes editing of entity
106   virtual UpdateType finishEditing(bool ok);
107
108 // returns true if mouse events are enabled
109   bool isMouseEnabled();
110 // enables/disables mouse events (excluding MouseMove)
111   void enableMouse(bool enable);
112   
113 protected slots:
114 // called when selection changed in list
115   virtual void onSelectionChanged();
116 // called when user finishes in editing of item
117   void onEditOk();
118 // called when user cancels item editing
119   void onEditCancel();
120 // called when columns sizes are changed
121   void onHeaderSizeChange(int, int, int);
122
123 protected:
124   SalomeApp_EntityEdit*   myEdit;
125   SalomeApp_ListViewItem* myEditedItem;
126   bool                    myEditingEnabled;
127   bool                    myMouseEnabled;
128 };
129
130
131 class SalomeApp_EditBox: public QLineEdit
132 {
133   Q_OBJECT
134
135 public:
136   SalomeApp_EditBox(QWidget* parent);
137  
138 protected:
139   void keyPressEvent(QKeyEvent* e);
140   
141 signals:
142   void escapePressed();
143 };
144
145 class SalomeApp_ComboBox: public QComboBox 
146 {
147   Q_OBJECT
148
149 public:
150   SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
151
152   int findItem(const QString& theText);
153   void insertItem(const QString& theValue, int theIndex = -1);
154   void insertList(const QStringList& theList);
155   void insertItem(const int theValue);
156   void insertList(const TColStd_ListOfInteger& theList);
157   void insertItem(const double theValue);
158   void insertList(const TColStd_ListOfReal& theList);
159 };
160
161 class SalomeApp_EntityEdit : public QWidget 
162 {
163   Q_OBJECT
164
165 public:
166   // enum for edit control type
167   enum {
168     etLineEdit,           // simple edit box
169     etComboBox,           // non-editable combo box
170     etComboEdit           // editable combo box
171   };
172   // enum for value type
173   enum {
174     vtString,             // string
175     vtInteger,            // integer value
176     vtDouble              // double value
177   };
178   // enum for insertion order
179   enum {
180     atBottom,
181     atTop,
182     atBeforeCurrent,
183     atAfterCurrent
184   };
185   // enum for edit box buttons (Apply = Cancel)
186   enum {
187     btApply  = 0x0001,
188     btCancel = 0x0002
189   };
190
191 public:
192   SalomeApp_EntityEdit( QWidget* parent, 
193                         int      controlType = etLineEdit, 
194                         int      valueType   = vtString,
195                         bool     butApply    = false, 
196                         bool     butCancel   = false);
197   ~SalomeApp_EntityEdit();
198
199   void finishEditing();
200   void clear();
201   QString getText();
202   void setText(const QString& theText );
203   void insertItem( const QString& theValue, 
204                    bool           theSetCurrent = false,
205                    int            theOrder = atBottom );
206   void insertList( const QStringList& theList, 
207                    const int          theCurrent = -1 );
208   void insertItem( const int theValue, 
209                    bool  theSetCurrent = false );
210   void insertList( const TColStd_ListOfInteger& theList, 
211                    const int                    theCurrent = -1 );
212   void insertItem( const double theValue, 
213                    bool         theSetCurrent = false );
214   void insertList( const TColStd_ListOfReal& theList, 
215                    const int                 theCurrent = -1 );
216   QWidget* getControl();
217   void setFocus();
218   void setValidator(const QValidator*);
219   void showButtons(bool show);
220   void setDuplicatesEnabled(bool enabled);
221
222 protected:
223   void keyPressEvent ( QKeyEvent * e);
224
225 private slots:
226   void onComboActivated(const QString&);
227   void onTextChanged(const QString&);
228   void onApply();
229   void onCancel();
230 signals:
231   void returnPressed();
232   void escapePressed();
233
234 private:
235   // Widgets
236   SalomeApp_EditBox*   myEdit;
237   SalomeApp_ComboBox*  myCombo;
238   QToolButton*         myApplyBtn;
239   QToolButton*         myCancelBtn;
240   QString              myString;
241 };
242
243 class SalomeApp_ListViewItem : public QListViewItem
244 {
245 public:
246   SalomeApp_ListViewItem( SalomeApp_ListView* );
247   SalomeApp_ListViewItem( SalomeApp_ListView*, 
248                           SalomeApp_ListViewItem* );
249   SalomeApp_ListViewItem( SalomeApp_ListView*,
250                           const QString&,
251                           const bool = false );
252   SalomeApp_ListViewItem( SalomeApp_ListView*,
253                           const QString& theName,
254                           const QString& theValue, 
255                           const bool = false );
256   SalomeApp_ListViewItem( SalomeApp_ListViewItem* theParent,
257                           const QString&,
258                           const bool = false );
259   SalomeApp_ListViewItem( SalomeApp_ListView*,
260                           SalomeApp_ListViewItem*,
261                           const QString&,
262                           const bool = false );
263   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
264                           SalomeApp_ListViewItem*,
265                           const QString&,
266                           const bool = false);
267   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
268                           const QString& theName,
269                           const QString& theValue, 
270                           const bool = false);
271   SalomeApp_ListViewItem( SalomeApp_ListView*,
272                           SalomeApp_ListViewItem*,
273                           const QString& theName,
274                           const QString& theValue, 
275                           const bool = false);
276   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
277                           SalomeApp_ListViewItem*,
278                           const QString&,
279                           const QString&, 
280                           const bool = false);
281   ~SalomeApp_ListViewItem();
282
283   QString            fullName();
284   void               openAllLevels();
285   virtual void       updateAllLevels();
286   bool               isEditable() const;
287   void               setEditable(bool theEditable);
288
289   // returns true if entitiy is accepted after editing
290   bool               isAccepted() const;
291   // set entity accepted or not after editing
292   void               setAccepted(bool theAccepted);
293
294   // returns name of entity (as default it is text in first column)
295   virtual QString    getName() const;
296   // sets name of entity (as default it is text in first column)
297   virtual UpdateType setName(const QString& theName);
298
299   // returns value of entity (as default it is text in second column)
300   virtual QString    getValue() const;
301   // sets value of entity (as default it is text in second column)
302   virtual UpdateType setValue(const QString& theValue);
303
304   // creates control for editing and fills it with values
305   SalomeApp_EntityEdit*    startEditing();
306   // fills widget with initial values (list or single value)
307   virtual void       fillWidgetWithValues(SalomeApp_EntityEdit* theWidget);
308   // finishes editing of entity
309   virtual UpdateType finishEditing(SalomeApp_EntityEdit* theWidget);
310
311   // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
312   virtual int        getEditingType();
313   // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
314   virtual void       setEditingType(const int);
315   // returns edited column
316   virtual int        getEditedColumn();
317   // returns type of edited value (string, int, double)
318   virtual int        getValueType();
319   // sets type of edited value (string, int, double)
320   virtual void       setValueType(const int);
321
322   // gets user type 
323   virtual int        getUserType();
324   // sets user type 
325   virtual void       setUserType(const int);
326
327   // returns buttons for editing widget
328   virtual int        getButtons();
329   // sets  buttons for editing widget
330   virtual void       setButtons(const int);
331   // returns text for tooltip
332   QString            tipText();
333   // calculates rectangle which should contain items tip
334   QRect              tipRect();
335   // calculates rect of item text in viewport coordinates
336   QRect              textRect(const int column) const;
337   // calculates full rect of item data in viewport coordinates
338   QRect              itemRect(const int column) const;
339
340 protected:
341   // initialization
342   void               init();
343
344 private:
345   bool myEditable;
346   bool myAccepted;
347   int  myEditingType;
348   int  myValueType;
349   int  myButtons;
350   int  myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
351 };
352
353
354 #endif