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