1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : QAD_ListView.h
8 // Author : Vadim SANDLER
12 #if !defined(_QAD_ListView_HeaderFile)
13 #define _QAD_ListView_HeaderFile
15 #include <qlistview.h>
19 #include <qlineedit.h>
20 #include <qcombobox.h>
22 //VRV: porting on Qt 3.0.5
23 #if QT_VERSION >= 0x030005
24 #include <qtoolbutton.h>
26 //VRV: porting on Qt 3.0.5
28 #include "QAD_Popup.h"
30 #include <TColStd_ListOfInteger.hxx>
31 #include <TColStd_ListOfReal.hxx>
33 // enumeration for ListView updating mode
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
43 class QAD_ListViewItem;
46 //================================================================
47 // Class : QAD_ListView
48 // Description : parent class for Data Viewer and Properties Viewer
49 //================================================================
50 class QAD_ListView : public QListView , public QAD_PopupServer {
56 QAD_ListView(QWidget *parent);
58 virtual ~QAD_ListView();
60 // updates list viewer
61 virtual void updateViewer();
62 // updtes currently selected item(s)
63 virtual void updateSelected();
65 // fills popup with items
68 void deletePopupMenu();
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 mouse button release event (execute popup menu)
89 void contentsMouseReleaseEvent(QMouseEvent* e);
90 // handler for resize event
91 void resizeEvent(QResizeEvent* e);
92 // handler for paint event
93 void viewportPaintEvent(QPaintEvent* e);
94 // finishes editing of entity
95 virtual UpdateType finishEditing(bool ok);
97 // returns true if mouse events are enabled
98 bool isMouseEnabled();
99 // enables/disables mouse events (excluding MouseMove)
100 void enableMouse(bool enable);
103 // called when selection changed in list
104 virtual void onSelectionChanged();
105 // called when user finishes in editing of item
107 // called when user cancels item editing
109 // called when columns sizes are changed
110 void onHeaderSizeChange(int, int, int);
113 QAD_EntityEdit* myEdit;
114 QAD_ListViewItem* myEditedItem;
115 bool myEditingEnabled;
120 //================================================================
121 // Class : QAD_ListViewItem
122 // Purpose : List Viewer entity
123 //================================================================
124 class QAD_ListViewItem : public QListViewItem {
128 QAD_ListViewItem(QAD_ListView* parent);
130 QAD_ListViewItem(QAD_ListView* parent,
131 QAD_ListViewItem* after);
133 QAD_ListViewItem(QAD_ListView* parent,
134 const QString theName,
135 const bool theEditable = false);
137 QAD_ListViewItem(QAD_ListView* parent,
138 const QString theName,
139 const QString theValue,
140 const bool theEditable = false);
142 QAD_ListViewItem(QAD_ListViewItem* parent,
143 const QString theName,
144 const bool theEditable = false);
146 QAD_ListViewItem(QAD_ListView* parent,
147 QAD_ListViewItem* after,
148 const QString theName,
149 const bool theEditable = false);
151 QAD_ListViewItem(QAD_ListViewItem* parent,
152 QAD_ListViewItem* after,
153 const QString theName,
154 const bool theEditable = false);
156 QAD_ListViewItem(QAD_ListViewItem* parent,
157 const QString theName,
158 const QString theValue,
159 const bool theEditable = false);
161 QAD_ListViewItem(QAD_ListView* parent,
162 QAD_ListViewItem* after,
163 const QString theName,
164 const QString theValue,
165 const bool theEditable = false);
167 QAD_ListViewItem(QAD_ListViewItem* parent,
168 QAD_ListViewItem* after,
169 const QString theName,
170 const QString theValue,
171 const bool theEditable = false);
175 // returns full path to the entity (full name)
178 // expands all entities beginning from this level
179 void openAllLevels();
180 // updates all entites beginning from this level
181 virtual void updateAllLevels();
183 // returns true if entity can be edited
184 bool isEditable() const;
185 // set entity as editable/uneditable
186 void setEditable(bool theEditable);
188 // returns true if entitiy is accepted after editing
189 bool isAccepted() const;
190 // set entity accepted or not after editing
191 void setAccepted(bool theAccepted);
193 // returns name of entity (as default it is text in first column)
194 virtual QString getName() const;
195 // sets name of entity (as default it is text in first column)
196 virtual UpdateType setName(const QString theName);
198 // returns value of entity (as default it is text in second column)
199 virtual QString getValue() const;
200 // sets value of entity (as default it is text in second column)
201 virtual UpdateType setValue(const QString theValue);
203 // creates control for editing and fills it with values
204 QAD_EntityEdit* startEditing();
205 // fills widget with initial values (list or single value)
206 virtual void fillWidgetWithValues(QAD_EntityEdit* theWidget);
207 // finishes editing of entity
208 virtual UpdateType finishEditing(QAD_EntityEdit* theWidget);
210 // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
211 virtual int getEditingType();
212 // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
213 virtual void setEditingType(const int);
214 // returns edited column
215 virtual int getEditedColumn();
216 // returns type of edited value (string, int, double)
217 virtual int getValueType();
218 // sets type of edited value (string, int, double)
219 virtual void setValueType(const int);
222 virtual int getUserType();
224 virtual void setUserType(const int);
226 // returns buttons for editing widget
227 virtual int getButtons();
228 // sets buttons for editing widget
229 virtual void setButtons(const int);
230 // returns text for tooltip
232 // calculates rectangle which should contain items tip
234 // calculates rect of item text in viewport coordinates
235 QRect textRect(const int column) const;
236 // calculates full rect of item data in viewport coordinates
237 QRect itemRect(const int column) const;
249 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
253 //================================================================
254 // Class : QAD_EditBox
255 // Description : edit box for list entity editing
256 //================================================================
257 class QAD_EditBox: public QLineEdit {
263 QAD_EditBox(QWidget* parent);
266 // event filter (for KeyPress event)
267 void keyPressEvent(QKeyEvent* e);
270 void escapePressed();
275 //================================================================
276 // Class : QAD_ComboBox
277 // Description : combo box for list entity editing
278 //================================================================
279 class QAD_ComboBox: public QComboBox {
285 QAD_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
287 // searches item in list and returns its index
288 int findItem(const QString theText);
289 // adds item in combo box
290 void insertItem(const QString& theValue, int theIndex = -1);
291 // adds list of items in combo box
292 void insertList(const QStringList& theList);
293 // adds item in combo box
294 void insertItem(const int theValue);
295 // adds list of items in combo box
296 void insertList(const TColStd_ListOfInteger& theList);
297 // adds item in combo box
298 void insertItem(const double theValue);
299 // adds list of items in combo box
300 void insertList(const TColStd_ListOfReal& theList);
305 //================================================================
306 // Class : QAD_EntityEdit
307 // Description : edit control for QAD List View
308 //================================================================
309 class QAD_EntityEdit : public QWidget {
314 // enum for edit control type
316 etLineEdit, // simple edit box
317 etComboBox, // non-editable combo box
318 etComboEdit // editable combo box
320 // enum for value type
323 vtInteger, // integer value
324 vtDouble // double value
326 // enum for insertion order
333 // enum for edit box buttons (Apply = Cancel)
340 QAD_EntityEdit(QWidget* parent,
341 int controlType = etLineEdit,
342 int valueType = vtString,
343 bool butApply = false,
344 bool butCancel = false);
349 void finishEditing();
350 // clears edit/combo box
352 // returns current text in edit box or combo box
355 void setText(const QString& theText);
356 // adds item in combo box
357 void insertItem(const QString& theValue,
358 bool theSetCurrent = false,
359 int theOrder = atBottom);
360 // adds list of items in combo box
361 void insertList(const QStringList& theList,
362 const int theCurrent = -1);
363 // adds item in combo box
364 void insertItem(const int theValue,
365 bool theSetCurrent = false);
366 // adds list of items in combo box
367 void insertList(const TColStd_ListOfInteger& theList,
368 const int theCurrent = -1);
369 // adds item in combo box
370 void insertItem(const double theValue,
371 bool theSetCurrent = false);
372 // adds list of items in combo box
373 void insertList(const TColStd_ListOfReal& theList,
374 const int theCurrent = -1);
375 // gets actual widget
376 QWidget* getControl();
377 // redirect focus to corresponding widget
379 // sets validator for the control
380 void setValidator(const QValidator*);
381 // shows/hides buttons
382 void showButtons(bool show);
383 // enables/disables data duplication (for combo box)
384 void setDuplicatesEnabled(bool enabled);
387 // event filter for KeyPress event
388 void keyPressEvent ( QKeyEvent * e);
391 // called when item activated in combo box
392 void onComboActivated(const QString&);
393 // called when text changed in control
394 void onTextChanged(const QString&);
395 // called when user presses Apply button
397 // called when user presses Cancel button
401 void returnPressed();
402 void escapePressed();
407 QAD_ComboBox* myCombo;
408 QToolButton* myApplyBtn;
409 QToolButton* myCancelBtn;