1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SalomeApp_ListView.h
22 // Author : Vadim SANDLER
25 #ifndef SALOMEAPP_LISTVIEW_H
26 #define SALOMEAPP_LISTVIEW_H
28 #include <QtxListView.h>
33 #include <qlineedit.h>
34 #include <qcombobox.h>
36 //VRV: porting on Qt 3.0.5
37 #if QT_VERSION >= 0x030005
38 #include <qtoolbutton.h>
40 //VRV: porting on Qt 3.0.5
42 #include <TColStd_ListOfInteger.hxx>
43 #include <TColStd_ListOfReal.hxx>
45 #include <SUIT_PopupClient.h>
47 // enumeration for ListView updating mode
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
57 class SalomeApp_ListViewItem;
58 class SalomeApp_EntityEdit;
61 \class SalomeApp_ListView
62 parent class for Data Viewer and Properties Viewer
64 class SalomeApp_ListView : public QtxListView , public SUIT_PopupClient {
70 SalomeApp_ListView(QWidget *parent);
72 virtual ~SalomeApp_ListView();
74 // updates list viewer
75 virtual void updateViewer();
76 // updtes currently selected item(s)
77 virtual void updateSelected();
79 // fills popup with items
80 virtual QString popupClientType() const;
81 virtual void contextMenuPopup( QPopupMenu* );
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)
94 bool eventFilter(QObject* object, QEvent* event) ;
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;
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);
108 // returns true if mouse events are enabled
109 bool isMouseEnabled();
110 // enables/disables mouse events (excluding MouseMove)
111 void enableMouse(bool enable);
114 // called when selection changed in list
115 virtual void onSelectionChanged();
116 // called when user finishes in editing of item
118 // called when user cancels item editing
120 // called when columns sizes are changed
121 void onHeaderSizeChange(int, int, int);
124 SalomeApp_EntityEdit* myEdit;
125 SalomeApp_ListViewItem* myEditedItem;
126 bool myEditingEnabled;
131 class SalomeApp_EditBox: public QLineEdit
136 SalomeApp_EditBox(QWidget* parent);
139 void keyPressEvent(QKeyEvent* e);
142 void escapePressed();
145 class SalomeApp_ComboBox: public QComboBox
150 SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
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);
161 class SalomeApp_EntityEdit : public QWidget
166 // enum for edit control type
168 etLineEdit, // simple edit box
169 etComboBox, // non-editable combo box
170 etComboEdit // editable combo box
172 // enum for value type
175 vtInteger, // integer value
176 vtDouble // double value
178 // enum for insertion order
185 // enum for edit box buttons (Apply = Cancel)
192 SalomeApp_EntityEdit( QWidget* parent,
193 int controlType = etLineEdit,
194 int valueType = vtString,
195 bool butApply = false,
196 bool butCancel = false);
197 ~SalomeApp_EntityEdit();
199 void finishEditing();
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();
218 void setValidator(const QValidator*);
219 void showButtons(bool show);
220 void setDuplicatesEnabled(bool enabled);
223 void keyPressEvent ( QKeyEvent * e);
226 void onComboActivated(const QString&);
227 void onTextChanged(const QString&);
231 void returnPressed();
232 void escapePressed();
236 SalomeApp_EditBox* myEdit;
237 SalomeApp_ComboBox* myCombo;
238 QToolButton* myApplyBtn;
239 QToolButton* myCancelBtn;
243 class SalomeApp_ListViewItem : public QListViewItem
246 SalomeApp_ListViewItem( SalomeApp_ListView* );
247 SalomeApp_ListViewItem( SalomeApp_ListView*,
248 SalomeApp_ListViewItem* );
249 SalomeApp_ListViewItem( SalomeApp_ListView*,
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,
258 const bool = false );
259 SalomeApp_ListViewItem( SalomeApp_ListView*,
260 SalomeApp_ListViewItem*,
262 const bool = false );
263 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
264 SalomeApp_ListViewItem*,
267 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
268 const QString& theName,
269 const QString& theValue,
271 SalomeApp_ListViewItem( SalomeApp_ListView*,
272 SalomeApp_ListViewItem*,
273 const QString& theName,
274 const QString& theValue,
276 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
277 SalomeApp_ListViewItem*,
281 ~SalomeApp_ListViewItem();
284 void openAllLevels();
285 virtual void updateAllLevels();
286 bool isEditable() const;
287 void setEditable(bool theEditable);
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);
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);
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);
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);
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);
323 virtual int getUserType();
325 virtual void setUserType(const int);
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
333 // calculates rectangle which should contain items tip
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;
350 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()