3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SalomeApp_ListView.h
8 // Author : Vadim SANDLER
12 #ifndef SALOMEAPP_LISTVIEW_H
13 #define SALOMEAPP_LISTVIEW_H
15 #include <QtxListView.h>
20 #include <qlineedit.h>
21 #include <qcombobox.h>
23 //VRV: porting on Qt 3.0.5
24 #if QT_VERSION >= 0x030005
25 #include <qtoolbutton.h>
27 //VRV: porting on Qt 3.0.5
29 #include <TColStd_ListOfInteger.hxx>
30 #include <TColStd_ListOfReal.hxx>
32 #include <SUIT_PopupClient.h>
34 // enumeration for ListView updating mode
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
44 class SalomeApp_ListViewItem;
45 class SalomeApp_EntityEdit;
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 {
57 SalomeApp_ListView(QWidget *parent);
59 virtual ~SalomeApp_ListView();
61 // updates list viewer
62 virtual void updateViewer();
63 // updtes currently selected item(s)
64 virtual void updateSelected();
66 // fills popup with items
67 virtual QString popupClientType() const;
68 virtual void contextMenuPopup( QPopupMenu* );
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)
81 bool eventFilter(QObject* object, QEvent* event) ;
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;
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);
95 // returns true if mouse events are enabled
96 bool isMouseEnabled();
97 // enables/disables mouse events (excluding MouseMove)
98 void enableMouse(bool enable);
101 // called when selection changed in list
102 virtual void onSelectionChanged();
103 // called when user finishes in editing of item
105 // called when user cancels item editing
107 // called when columns sizes are changed
108 void onHeaderSizeChange(int, int, int);
111 SalomeApp_EntityEdit* myEdit;
112 SalomeApp_ListViewItem* myEditedItem;
113 bool myEditingEnabled;
118 class SalomeApp_EditBox: public QLineEdit
123 SalomeApp_EditBox(QWidget* parent);
126 void keyPressEvent(QKeyEvent* e);
129 void escapePressed();
132 class SalomeApp_ComboBox: public QComboBox
137 SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
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);
148 class SalomeApp_EntityEdit : public QWidget
153 // enum for edit control type
155 etLineEdit, // simple edit box
156 etComboBox, // non-editable combo box
157 etComboEdit // editable combo box
159 // enum for value type
162 vtInteger, // integer value
163 vtDouble // double value
165 // enum for insertion order
172 // enum for edit box buttons (Apply = Cancel)
179 SalomeApp_EntityEdit( QWidget* parent,
180 int controlType = etLineEdit,
181 int valueType = vtString,
182 bool butApply = false,
183 bool butCancel = false);
184 ~SalomeApp_EntityEdit();
186 void finishEditing();
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();
205 void setValidator(const QValidator*);
206 void showButtons(bool show);
207 void setDuplicatesEnabled(bool enabled);
210 void keyPressEvent ( QKeyEvent * e);
213 void onComboActivated(const QString&);
214 void onTextChanged(const QString&);
218 void returnPressed();
219 void escapePressed();
223 SalomeApp_EditBox* myEdit;
224 SalomeApp_ComboBox* myCombo;
225 QToolButton* myApplyBtn;
226 QToolButton* myCancelBtn;
230 class SalomeApp_ListViewItem : public QListViewItem
233 SalomeApp_ListViewItem( SalomeApp_ListView* );
234 SalomeApp_ListViewItem( SalomeApp_ListView*,
235 SalomeApp_ListViewItem* );
236 SalomeApp_ListViewItem( SalomeApp_ListView*,
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,
245 const bool = false );
246 SalomeApp_ListViewItem( SalomeApp_ListView*,
247 SalomeApp_ListViewItem*,
249 const bool = false );
250 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
251 SalomeApp_ListViewItem*,
254 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
255 const QString& theName,
256 const QString& theValue,
258 SalomeApp_ListViewItem( SalomeApp_ListView*,
259 SalomeApp_ListViewItem*,
260 const QString& theName,
261 const QString& theValue,
263 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
264 SalomeApp_ListViewItem*,
268 ~SalomeApp_ListViewItem();
271 void openAllLevels();
272 virtual void updateAllLevels();
273 bool isEditable() const;
274 void setEditable(bool theEditable);
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);
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);
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);
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);
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);
310 virtual int getUserType();
312 virtual void setUserType(const int);
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
320 // calculates rectangle which should contain items tip
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;
337 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()