Salome HOME
Update comments
[modules/gui.git] / src / SalomeApp / SalomeApp_ListView.cxx
1 //  SALOME SalomeApp
2 //
3 //  Copyright (C) 2005  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SalomeApp_ListView.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #include "SalomeApp_ListView.h"
13 #include "SalomeApp_Application.h"
14
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_Session.h"
17
18 #include <qheader.h>
19 #include <qvalidator.h>
20 #include <qapplication.h>
21 #include <qtoolbutton.h>
22
23 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <TColStd_ListIteratorOfListOfReal.hxx>
25
26 #include "utilities.h"
27
28 using namespace std;
29
30 //////////////////////////////////////////////////////////////////////
31 // SalomeApp_ListView class implementation
32 //////////////////////////////////////////////////////////////////////
33
34 //================================================================
35 // Function : computeEditGeometry
36 /*! Purpose  : static function - used for resizing editing widget*/
37 //================================================================
38 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
39                          SalomeApp_EntityEdit*   theWidget)
40 {
41   if (!theItem)
42     return;
43   QListView* aListView = theItem->listView();
44   int anEditColumn = theItem->getEditedColumn();
45   if (anEditColumn < 0)
46     return;
47
48   int aX = 0, aY = 0, aW = 0, aH = 0;
49
50   QRect aRect = aListView->itemRect(theItem);
51   aListView->contentsToViewport(aListView->header()->sectionPos(anEditColumn), 0, aX, aY);
52   if (aX < 0)
53     aX = 0; // THIS CAN BE REMOVED
54   QSize aSize = theWidget->getControl()->sizeHint();
55   aH = QMAX(aSize.height() , aRect.height() );
56   aY = aRect.y() - ((aH - aRect.height()) / 2);
57   //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
58   aW = aListView->viewport()->width() - aX;
59   if (aW < 0)
60     aW = 0;
61   theWidget->setGeometry(aX, aY, aW, aH);
62 }
63
64 //================================================================
65 // Function : SalomeApp_ListView::SalomeApp_ListView
66 /*! Purpose  : constructor*/
67 //================================================================
68 SalomeApp_ListView::SalomeApp_ListView( QWidget* parent )
69 : QtxListView( parent )
70 {
71   myMouseEnabled = true;
72   myEditingEnabled = false;
73   setSelectionMode(Single);
74   setSorting(-1);
75   setRootIsDecorated(false);
76   setAllColumnsShowFocus(false);
77 //  header()->setClickEnabled(false);
78   header()->setMovingEnabled(false);
79
80   myEditedItem = 0;
81   myEdit = 0;
82
83   viewport()->installEventFilter(this);
84
85   connect(this, SIGNAL(selectionChanged()),
86           this, SLOT(onSelectionChanged()));
87   connect(header(), SIGNAL(sizeChange(int, int, int)),
88           this,     SLOT(onHeaderSizeChange(int, int, int)));
89 }
90
91 //================================================================
92 // Function : SalomeApp_ListView::~SalomeApp_ListView
93 /*! Purpose  : destructor*/
94 //================================================================
95 SalomeApp_ListView::~SalomeApp_ListView()
96 {
97   if (myEdit) {
98     delete myEdit;
99   }
100   myEdit = 0;
101   myEditedItem = 0;
102 }
103
104 //================================================================
105 // Function : SalomeApp_ListView::updateViewer
106 /*! Purpose  : updates all data viewer*/
107 //================================================================
108 void SalomeApp_ListView::updateViewer()
109 {
110   // temporary disconnecting selection changed SIGNAL
111   blockSignals(true);
112   SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)firstChild();
113   if (aRoot)
114     aRoot->updateAllLevels();
115   updateContents();
116   // connecting again selection changed SIGNAL
117   blockSignals(false);
118   emit selectionChanged();
119 }
120
121 //================================================================
122 // Function : SalomeApp_ListView::updateSelected
123 /*! Purpose  : updates currently selected item(s)*/
124 //================================================================
125 void SalomeApp_ListView::updateSelected()
126 {
127   // temporary disconnecting selection changed SIGNAL
128   blockSignals(true);
129   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)selectedItem();
130   if (aChild)
131     aChild->updateAllLevels();
132   updateContents();
133   // connecting again selection changed SIGNAL
134   blockSignals(false);
135   emit selectionChanged();
136 }
137
138 //================================================================
139 // Function : SalomeApp_ListView::popupClientType
140 /*! Purpose  : returns popup client type*/
141 //================================================================
142 QString SalomeApp_ListView::popupClientType() const
143 {
144   return "SalomeApp_ListView";
145 }
146
147 //================================================================
148 // Function : SalomeApp_ListView::contextMenuPopup
149 /*! Purpose  : fills popup menu with items*/
150 //================================================================
151 void SalomeApp_ListView::contextMenuPopup( QPopupMenu* aPopup )
152 {
153   if (aPopup) {
154     // add items here...
155   }
156 }
157
158 //================================================================
159 // Function : SalomeApp_ListView::clear
160 /*! Purpose  : clears view*/
161 //================================================================
162 void SalomeApp_ListView::clear()
163 {
164   if (myEdit) {
165     delete myEdit;
166     myEdit = 0;
167     myEditedItem = 0;
168   }
169   QListView::clear();
170 }
171
172 //================================================================
173 // Function : SalomeApp_ListView::isMouseEnabled
174 /*! Purpose  : returms true if mouse events are enabled*/
175 //================================================================
176 bool SalomeApp_ListView::isMouseEnabled()
177 {
178   return myMouseEnabled;
179 }
180
181 //================================================================
182 // Function : SalomeApp_ListView::enableMouse
183 // Purpose  : enabled/disables mouse events (excluding MouseMove)
184 //================================================================
185 void SalomeApp_ListView::enableMouse(bool enable)
186 {
187   myMouseEnabled = enable;
188 }
189
190 //================================================================
191 // Function : SalomeApp_ListView::eventFilter
192 /*! Purpose  : event filter*/
193 //================================================================
194 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
195 {
196   if (object == viewport() &&
197        (event->type() == QEvent::MouseButtonPress   ||
198         event->type() == QEvent::MouseButtonRelease ||
199         event->type() == QEvent::MouseButtonDblClick)  &&
200       !isMouseEnabled())
201     return true;
202   else
203     return QListView::eventFilter(object, event);
204 }
205
206 //================================================================
207 // Function : SalomeApp_ListView::enableEditing
208 /*! Purpose  : setting editing of items availbale/not available*/
209 //================================================================
210 void SalomeApp_ListView::enableEditing(bool theFlag)
211 {
212   myEditingEnabled = theFlag;
213   if (!myEditingEnabled) {
214     if (myEdit) {
215       delete myEdit;
216       myEdit = 0;
217       myEditedItem = 0;
218     }
219   }
220 }
221
222 //================================================================
223 // Function : SalomeApp_ListView::isEnableEditing
224 /*! Purpose  : says if editing is enabled*/
225 //================================================================
226 bool SalomeApp_ListView::isEnableEditing()
227 {
228   return myEditingEnabled;
229 }
230
231 //================================================================
232 // Function : SalomeApp_ListView::accept
233 /*! Purpose  : calls finishEditing(true)...*/
234 //================================================================
235 void SalomeApp_ListView::accept()
236 {
237   finishEditing(true);
238 }
239
240 //================================================================
241 // Function : QAD_ListView::onSelectionChanged
242 /*! Purpose  : slot, called when selection changed in List Viewer*/
243 //================================================================
244 void SalomeApp_ListView::onSelectionChanged()
245 {
246   if (myEdit) {
247     finishEditing(true);
248     delete myEdit;
249     myEdit = 0;
250     if (myEditedItem && !myEditedItem->isAccepted()) {
251       delete myEditedItem;
252       updateContents();
253     }
254     myEditedItem = 0;
255   }
256   // editing is allowed in Single Selection Mode only
257   if (selectionMode() != Single || !isEnableEditing())
258     return;
259   SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)selectedItem();
260   if (anItem) {
261     if (!anItem->isEditable())
262       return;
263     myEdit = anItem->startEditing();
264     if (myEdit) {
265       connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
266       connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
267       myEditedItem = anItem;
268       myEdit->show();
269       myEdit->setFocus();
270     }
271   }
272 }
273
274 //================================================================
275 // Function : SalomeApp_ListView::resizeEvent
276 /*! Purpose  : called when Data Viewer is resized*/
277 //================================================================
278 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
279 {
280   QListView::resizeEvent(e);
281   int aW = columnWidth(columns()-1);
282   int aX = header()->sectionPos(columns()-1);
283   if (aW < width() - frameWidth() * 2 - aX - 1)
284     setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
285   updateContents();
286 }
287
288 //================================================================
289 // Function : SalomeApp_ListView::onHeaderSizeChange
290 /*! Purpose  : slot, called when columns sizes are changed*/
291 //================================================================
292 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
293 {
294   int aW = columnWidth(columns()-1);
295   int aX = header()->sectionPos(columns()-1);
296   if (aW < width() - frameWidth() * 2 - aX - 1)
297     setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
298 }
299
300 //================================================================
301 // Function : SalomeApp_ListView::viewportPaintEvent
302 /*! Purpose  : handler for paint event*/
303 //================================================================
304 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
305 {
306   QListView::viewportPaintEvent(e);
307   if (myEditedItem && myEdit) {
308     computeEditGeometry(myEditedItem, myEdit);
309   }
310 }
311
312 //================================================================
313 // Function : SalomeApp_ListView::onEditOk
314 /*! Purpose  : called when user finishes in editing of item*/
315 //================================================================
316 void SalomeApp_ListView::onEditOk()
317 {
318   finishEditing(true);
319 }
320
321 //================================================================
322 // Function : SalomeApp_ListView::onEditCancel
323 /*! Purpose  : called when user cancels item editing*/
324 //================================================================
325 void SalomeApp_ListView::onEditCancel()
326 {
327   finishEditing(false);
328 }
329
330 //================================================================
331 // Function : SalomeApp_ListView::finishEditing
332 /*! Purpose  : finishes editing of entity*/
333 //================================================================
334 UpdateType SalomeApp_ListView::finishEditing(bool ok)
335 {
336   UpdateType aNeedsUpdate = utCancel;
337   if (myEditedItem && myEdit)
338   {
339     disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
340     disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
341     myEditedItem->setAccepted(true);
342     if (ok) {
343       aNeedsUpdate = myEditedItem->finishEditing(myEdit);
344       if (aNeedsUpdate == utCancel) {
345         // something to do here on Cancel...
346       }
347       else {
348         // something to do here on OK...
349       }
350       // updating contents
351       switch (aNeedsUpdate) {
352       case utUpdateItem:
353         {
354           if (myEditedItem)
355             myEditedItem->updateAllLevels();
356           break;
357         }
358       case utUpdateParent:
359         {
360           if (myEditedItem) {
361             SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
362             if (aParent)
363               aParent->updateAllLevels();
364             else
365               myEditedItem->updateAllLevels();
366           }
367           break;
368         }
369       case utUpdateViewer:
370         {
371           updateViewer();
372           break;
373         }
374       case utUpdateAll:
375         {
376           // doing the same as for utUpdateViewer here
377           // descendants can add extra processing
378           updateViewer();
379           break;
380         }
381       default:
382         break;
383       }
384     }
385   }
386
387   // hide <myEdit> widget
388   if (myEdit) {
389     myEdit->hide();
390   }
391
392   return aNeedsUpdate;
393 }
394
395 //================================================================
396 // Function : SalomeApp_ListView::tip
397 /*! Purpose  : gets current tooltip for list view
398  * \retval valid rect in success
399  */
400 //================================================================
401 QRect SalomeApp_ListView::tip(QPoint aPos,
402                         QString& aText,
403                         QRect& dspRect,
404                         QFont& dspFnt) const
405 {
406   QRect result( -1, -1, -1, -1 );
407   SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
408   if ( aItem ) {
409     for (int i = 0; i < columns(); i++) {
410       QRect aItemRect = aItem->itemRect(i);
411       QRect aTextRect = aItem->textRect(i);
412       if ( !aItem->text(i).isEmpty() &&
413            ( aItemRect.width()  > header()->sectionSize(i) ||
414              aTextRect.left()   < 0 ||
415              aTextRect.top()    < 0 ||
416              aTextRect.right()  > viewport()->width() ||
417              aTextRect.bottom() > viewport()->height() ) ) {
418         // calculating tip data
419         aText   = aItem->tipText();
420         dspRect = aItem->tipRect();
421         dspFnt  = font();
422         if (dspRect.isValid()) {
423           result  = QRect(QPoint(0, aItemRect.top()),
424                           QSize(viewport()->width(), aItemRect.height()));
425         }
426       }
427     }
428   }
429   return result;
430 }
431
432 //////////////////////////////////////////////////////////////////////
433 // SalomeApp_ListViewItem Class Implementation
434 //////////////////////////////////////////////////////////////////////
435
436 //================================================================
437 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
438 /*! Purpose  : constructor*/
439 //================================================================
440 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
441 QListViewItem( parent )
442 {
443   init();
444 }
445
446 //================================================================
447 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
448 /*! Purpose  : constructor*/
449 //================================================================
450 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent,
451                                    SalomeApp_ListViewItem* after) :
452 QListViewItem( parent, after )
453 {
454   init();
455 }
456
457 //================================================================
458 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
459 /*! Purpose  : constructor*/
460 //================================================================
461 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent,
462                                    const QString&    theName,
463                                    const bool        theEditable) :
464 QListViewItem(parent, theName)
465 {
466   init();
467   setEditable(theEditable);
468 }
469
470 //================================================================
471 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
472 /*! Purpose  : constructor*/
473 //================================================================
474 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent,
475                                    const QString&    theName,
476                                    const QString&    theValue,
477                                    const bool        theEditable) :
478 QListViewItem(parent, theName, theValue)
479 {
480   init();
481   setEditable(theEditable);
482 }
483
484 //================================================================
485 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
486 /*! Purpose  : constructor*/
487 //================================================================
488 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
489                                    const QString&    theName,
490                                    const bool        theEditable) :
491 QListViewItem(parent, theName)
492 {
493   init();
494   setEditable(theEditable);
495 }
496
497 //================================================================
498 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
499 /*! Purpose  : constructor*/
500 //================================================================
501 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
502                                    SalomeApp_ListViewItem* after,
503                                    const QString&    theName,
504                                    const bool        theEditable) :
505 QListViewItem(parent, after, theName)
506 {
507   init();
508   setEditable(theEditable);
509 }
510
511 //================================================================
512 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
513 /*! Purpose  : constructor*/
514 //================================================================
515 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent,
516                                    SalomeApp_ListViewItem* after,
517                                    const QString&    theName,
518                                    const bool        theEditable) :
519 QListViewItem(parent, after, theName)
520 {
521   init();
522   setEditable(theEditable);
523 }
524
525
526 //================================================================
527 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
528 /*! Purpose  : constructor*/
529 //================================================================
530 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
531                                    const QString&    theName,
532                                    const QString&    theValue,
533                                    const bool        theEditable) :
534 QListViewItem(parent, theName, theValue)
535 {
536   init();
537   setEditable(theEditable);
538 }
539
540
541 //================================================================
542 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
543 /*! Purpose  : constructor*/
544 //================================================================
545 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
546                                    SalomeApp_ListViewItem* after,
547                                    const QString&    theName,
548                                    const QString&    theValue,
549                                    const bool        theEditable) :
550 QListViewItem(parent, after, theName, theValue)
551 {
552   init();
553   setEditable(theEditable);
554 }
555
556 //================================================================
557 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
558 /*! Purpose  : constructor*/
559 //================================================================
560 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent,
561                                    SalomeApp_ListViewItem* after,
562                                    const QString&    theName,
563                                    const QString&    theValue,
564                                    const bool        theEditable) :
565 QListViewItem(parent, after, theName, theValue)
566 {
567   init();
568   setEditable(theEditable);
569 }
570
571 //================================================================
572 // Function : SalomeApp_ListViewItem::~SalomeApp_ListViewItem
573 /*! Purpose  : destructor*/
574 //================================================================
575 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
576 {
577 }
578
579 //================================================================
580 // Function : SalomeApp_ListViewItem::init
581 /*! Purpose  : initialization*/
582 //================================================================
583 void SalomeApp_ListViewItem::init()
584 {
585   myEditable    = false;
586   myAccepted    = true;
587   myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
588   myValueType   = (int)SalomeApp_EntityEdit::vtString;
589   myButtons     = 0;
590   myUserType    = -1;
591 }
592
593 //================================================================
594 // Function : SalomeApp_ListViewItem::getName
595 /*! Purpose  : as default returns text in the first column*/
596 //================================================================
597 QString SalomeApp_ListViewItem::getName() const
598 {
599   return ( listView()->columns() > 0 ) ? text(0) : QString("");
600 }
601
602 //================================================================
603 // Function : SalomeApp_ListViewItem::setName
604 /*! Purpose  : as default sets text in the first column*/
605 //================================================================
606 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
607 {
608   UpdateType aNeedsUpdate = utCancel;
609   if (listView()->columns() > 0) {
610     setText(0, theName);
611     aNeedsUpdate = utNone;
612   }
613   return aNeedsUpdate;
614 }
615
616 //================================================================
617 // Function : SalomeApp_ListViewItem::getValue
618 /*! Purpose  : as default returns text in the second column*/
619 //================================================================
620 QString SalomeApp_ListViewItem::getValue() const
621 {
622   return ( listView()->columns() > 1 ) ? text(1) : QString("");
623 }
624
625 //================================================================
626 // Function : SalomeApp_ListViewItem::setValue
627 /*! Purpose  : as default sets text in the second column*/
628 //================================================================
629 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
630 {
631   UpdateType aNeedsUpdate = utCancel;
632   if (listView()->columns() > 1) {
633     setText(1, theValue);
634     aNeedsUpdate = utNone;
635   }
636   return aNeedsUpdate;
637 }
638
639 //================================================================
640 // Function : SalomeApp_ListViewItem::fullName
641 /*! Purpose  : returns full path to the entity from the root*/
642 //================================================================
643 QString SalomeApp_ListViewItem::fullName()
644 {
645   QString aFullName = getName();
646   SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
647   while(aParent != NULL) {
648     aFullName = aParent->getName() + QString(".") + aFullName;
649     aParent = (SalomeApp_ListViewItem*)(aParent->parent());
650   }
651   return aFullName;
652 }
653
654 //================================================================
655 // Function : SalomeApp_ListViewItem::openAllLevels
656 /*! Purpose  : expands all entities beginning from this level*/
657 //================================================================
658 void SalomeApp_ListViewItem::openAllLevels()
659 {
660   setOpen(true);
661   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
662   while( aChild ) {
663     aChild->openAllLevels();
664     aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
665   }
666 }
667
668 //================================================================
669 // Function : SalomeApp_ListViewItem::updateAllLevels
670 /*! Purpose  : update all entites beginning from this level*/
671 //================================================================
672 void SalomeApp_ListViewItem::updateAllLevels()
673 {
674   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
675   while( aChild ) {
676     aChild->updateAllLevels();
677     aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
678   }
679 }
680
681 //================================================================
682 // Function : SalomeApp_EditBox::isEditable
683 /*! Purpose  : return true if entity is editable*/
684 //================================================================
685 bool SalomeApp_ListViewItem::isEditable() const
686 {
687   return myEditable;
688 }
689
690 //================================================================
691 // Function : SalomeApp_ListViewItem::setEditable
692 /*! Purpose  : sets editable flag fo the entity*/
693 //================================================================
694 void SalomeApp_ListViewItem::setEditable(bool theEditable)
695 {
696   myEditable = theEditable;
697 }
698
699 //================================================================
700 // Function : SalomeApp_ListViewItem::isAccepted
701 /*! Purpose  : returns true if entitiy is accepted after editing*/
702 //================================================================
703 bool SalomeApp_ListViewItem::isAccepted() const
704 {
705   return myAccepted;
706 }
707
708 //================================================================
709 // Function : SalomeApp_ListViewItem::setAccepted
710 /*! Purpose  : set entitiy accepted or not after editing*/
711 //================================================================
712 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
713 {
714   myAccepted = theAccepted;
715 }
716
717 //================================================================
718 // Function : SalomeApp_ListViewItem::getEditingType
719 /*! Purpose  : 
720  * \retval type of edit control (default is edit box)
721  *     \li 0 - edit box
722  *     \li 1 - combo box
723  *     \li 2 - editable combo box
724  */
725 //================================================================
726 int SalomeApp_ListViewItem::getEditingType()
727 {
728   return myEditingType;
729 }
730
731 //================================================================
732 // Function : SalomeApp_ListViewItem::setEditingType
733 /*! Purpose  : 
734  * \retval type of edit control (negative value means none)
735  *     \li 0 - edit box
736  *     \li 1 - combo box
737  *     \li 2 - editable combo box
738  */
739 //================================================================
740 void SalomeApp_ListViewItem::setEditingType(const int type)
741 {
742   myEditingType = type;
743 }
744
745 //================================================================
746 // Function : SalomeApp_ListViewItem::getEditedColumn
747 // Purpose  : 
748 /*! \retval edited column, default is last column
749  *   negative value means there are no editable columns
750  */
751 //================================================================
752 int SalomeApp_ListViewItem::getEditedColumn()
753 {
754   return listView()->columns()-1;
755 }
756
757 //================================================================
758 // Function : SalomeApp_ListViewItem::getValueType
759 // Purpose  : 
760 /*!\retval type of edited value (string, int, double)
761  * default is string
762  */
763 //================================================================
764 int SalomeApp_ListViewItem::getValueType()
765 {
766   return myValueType;
767 }
768
769 //================================================================
770 // Function : SalomeApp_ListViewItem::setValueType
771 /*! Purpose  : sets type of edited value*/
772 //================================================================
773 void SalomeApp_ListViewItem::setValueType(const int valueType)
774 {
775   myValueType = valueType;
776 }
777
778 //================================================================
779 // Function : SalomeApp_ListViewItem::getUserType
780 /*! Purpose  : sets type of edited value*/
781 //================================================================
782 int SalomeApp_ListViewItem::getUserType()
783 {
784   return myUserType;
785 }
786
787 //================================================================
788 // Function : SalomeApp_ListViewItem::setUserType
789 /*! Purpose  : sets type of edited value*/
790 //================================================================
791 void SalomeApp_ListViewItem::setUserType(const int userType)
792 {
793   myUserType = userType;
794 }
795
796 //================================================================
797 // Function : SalomeApp_ListViewItem::getButtons
798 /*! Purpose  : returns buttons for editing widget (Apply (V), Cancel (X))
799  * default is both buttons
800  */
801 //================================================================
802 int SalomeApp_ListViewItem::getButtons()
803 {
804   return myButtons;
805 }
806
807 //================================================================
808 // Function : SalomeApp_ListViewItem::getButtons
809 /*! Purpose  : sets buttons for editing widget (Apply (V), Cancel (X))*/
810 //================================================================
811 void SalomeApp_ListViewItem::setButtons(const int buttons)
812 {
813   myButtons = buttons;
814 }
815
816 //================================================================
817 // Function : SalomeApp_ListViewItem::startEditing
818 /*! Purpose  : creates control for editing and fills it with values*/
819 //================================================================
820 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
821 {
822   SalomeApp_EntityEdit* aWidget = 0;
823   QListView* aListView = listView();
824   if (aListView) {
825     if (!isEditable())
826       return 0;
827     int anEditType   = getEditingType();
828     int aValueType   = getValueType();
829     int aButtons     = getButtons();
830     int anEditColumn = getEditedColumn();
831     if (anEditColumn < 0 || anEditType < 0)
832       return 0;
833     aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
834                                  anEditType,
835                                  aValueType,
836                                  aButtons & SalomeApp_EntityEdit::btApply,
837                                  aButtons & SalomeApp_EntityEdit::btCancel);
838     computeEditGeometry(this, aWidget);
839
840     fillWidgetWithValues(aWidget);
841   }
842   return aWidget;
843 }
844
845 //================================================================
846 // Function : SalomeApp_ListViewItem::fillWidgetWithValues
847 /*! Purpose  : fills widget with initial values (list or single value)*/
848 //================================================================
849 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
850 {
851   int anEditColumn = getEditedColumn();
852   if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
853     theWidget->insertItem(text(anEditColumn), true);
854 }
855
856 //================================================================
857 // Function : SalomeApp_ListViewItem::finishEditing
858 /*! Purpose  : finishes editing of entity*/
859 //================================================================
860 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
861 {
862   UpdateType aNeedsUpdate = utCancel;
863   try {
864     if (theWidget) {
865       int anEditColumn = getEditedColumn();
866       switch (anEditColumn) {
867       case 0:
868         aNeedsUpdate = setName(theWidget->getText());
869         break;
870       case 1:
871         aNeedsUpdate = setValue(theWidget->getText());
872         break;
873       default:
874         break;
875       }
876     }
877   }
878   catch (...) {
879     MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
880   }
881   return aNeedsUpdate;
882 }
883
884 //================================================================
885 // Function : SalomeApp_ListViewItem::tipRect
886 /*! Purpose  : calculates rectangle which should contain item's tip*/
887 //================================================================
888 QRect SalomeApp_ListViewItem::tipRect()
889 {
890   QRect aRect = QRect(-1, -1, -1, -1);
891   QRect aItemRect = listView()->itemRect(this);
892   if ( !aItemRect.isValid() )
893     return aItemRect;
894
895   QString aTip = tipText();
896   if (!aTip.isEmpty()) {
897     QRect aRect0 = textRect(0);
898     QFont aFont(listView()->font());
899     QFontMetrics fm(aFont);
900     int iw = fm.width(aTip);
901     aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
902                          aRect0.y()),
903                   QSize (iw,
904                          aRect0.height()));
905   }
906   return aRect;
907 }
908
909 //================================================================
910 // Function : SalomeApp_ListViewItem::tipText
911 /*! Purpose  : returns text for tooltip*/
912 //================================================================
913 QString SalomeApp_ListViewItem::tipText()
914 {
915   QString aText = getName();
916   if (!getValue().isEmpty())
917     aText += QString(" : ") + getValue();
918   return aText;
919 }
920
921 //================================================================
922 // Function : SalomeApp_ListViewItem::textRect
923 /*! Purpose  : calculates rect of item text in viewport coordinates*/
924 //================================================================
925 QRect SalomeApp_ListViewItem::textRect(const int column) const
926 {
927   QRect aItemRect = listView()->itemRect( this );
928   if ( !aItemRect.isValid() )
929     return aItemRect;
930
931   QFont aFont(listView()->font());
932   QFontMetrics fm(aFont);
933
934   int decorWidth  = ( listView()->rootIsDecorated() ) ?
935                     ( listView()->treeStepSize() * (depth() + 1) ) :
936                     ( listView()->treeStepSize() *  depth() );
937   int pixmapWidth = ( pixmap(column) ) ?
938                       pixmap(column)->width() +  listView()->itemMargin() * 2 :
939                       listView()->itemMargin();
940   int prevWidth = 0;
941   for (int i = 0; i < column; i++)
942     prevWidth += listView()->header()->sectionSize(i);
943   int ix = prevWidth   +
944            pixmapWidth +
945            ((column == 0) ? decorWidth : 0);
946   int iy = aItemRect.y();
947   int iw = fm.width(text(column));
948   int ih = aItemRect.height();
949   if (pixmap(column)) {
950     iy += listView()->itemMargin();
951     ih -= listView()->itemMargin() * 2;
952   }
953   ix -= listView()->contentsX();
954
955   QRect theResult(QPoint(ix, iy), QSize(iw, ih));
956   return theResult;
957 }
958
959 //================================================================
960 // Function : SalomeApp_ListViewItem::itemRect
961 /*! Purpose  : calculates rect of item data in viewport coordinates*/
962 //================================================================
963 QRect SalomeApp_ListViewItem::itemRect(const int column) const
964 {
965   QRect aItemRect = listView()->itemRect( this );
966   if ( !aItemRect.isValid() )
967     return aItemRect;
968
969   QFont aFont(listView()->font());
970   QFontMetrics fm(aFont);
971
972   int decorWidth  = ( listView()->rootIsDecorated() ) ?
973                     ( listView()->treeStepSize() * (depth() + 1) ) :
974                     ( listView()->treeStepSize() *  depth() );
975   int pixmapWidth = ( pixmap(column) ) ?
976                       pixmap(column)->width() +  listView()->itemMargin() * 2 :
977                       0;
978   int prevWidth = 0;
979   for (int i = 0; i < column; i++)
980     prevWidth += listView()->header()->sectionSize(i);
981   int ix = prevWidth;
982   int iy = aItemRect.y();
983   int iw = pixmapWidth +
984            listView()->itemMargin() * 2 +
985            ((column == 0) ? decorWidth : 0) +
986            fm.width(text(column));
987   int ih = aItemRect.height();
988   ix -= listView()->contentsX();
989
990   QRect theResult(QPoint(ix, iy), QSize(iw, ih));
991   return theResult;
992 }
993
994 //////////////////////////////////////////////////////////////////////
995 // SalomeApp_EditBox class implementation
996 //////////////////////////////////////////////////////////////////////
997
998 //================================================================
999 // Function : SalomeApp_EditBox::SalomeApp_EditBox
1000 /*! Purpose  : constructor*/
1001 //================================================================
1002 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
1003 QLineEdit(parent)
1004 {
1005 }
1006
1007 //================================================================
1008 // Function : SalomeApp_EditBox::keyPressEvent
1009 /*! Purpose  : event filter for key pressing*/
1010 //================================================================
1011 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
1012 {
1013   if ( e->key() == Key_Escape )
1014     emit escapePressed();
1015   else
1016     QLineEdit::keyPressEvent( e );
1017   e->accept();
1018 }
1019
1020 //////////////////////////////////////////////////////////////////////
1021 // SalomeApp_ComboBox class implementation
1022 //////////////////////////////////////////////////////////////////////
1023
1024 //================================================================
1025 // Function : SalomeApp_ComboBox::SalomeApp_ComboBox
1026 /*! Purpose  : constructor*/
1027 //================================================================
1028 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
1029 QComboBox(rw, parent, name)
1030 {
1031 }
1032
1033 //================================================================
1034 // Function : SalomeApp_ComboBox::findItem
1035 /*! Purpose  : searches item in list and returns its index*/
1036 //================================================================
1037 int SalomeApp_ComboBox::findItem(const QString& theText)
1038 {
1039   for (int i = 0; i < count(); i++)
1040     if (text(i) == theText)
1041       return i;
1042   return -1;
1043 }
1044
1045 //================================================================
1046 // Function : SalomeApp_ComboBox::insertItem
1047 /*! Purpose  : adds item in combo box*/
1048 //================================================================
1049 void SalomeApp_ComboBox::insertItem(const QString& theValue,
1050                               int            theIndex)
1051 {
1052   if (duplicatesEnabled() || findItem(theValue) < 0)
1053     QComboBox::insertItem(theValue, theIndex);
1054 }
1055
1056 //================================================================
1057 // Function : SalomeApp_ComboBox::insertList
1058 /*! Purpose  : adds list of items in combo box*/
1059 //================================================================
1060 void SalomeApp_ComboBox::insertList(const QStringList& theList)
1061 {
1062   for (unsigned i = 0; i < theList.count(); i++)
1063     insertItem(theList[i]);
1064 }
1065
1066 //================================================================
1067 // Function : SalomeApp_ComboBox::insertItem
1068 /*! Purpose  : adds item in combo box*/
1069 //================================================================
1070 void SalomeApp_ComboBox::insertItem(const int theValue)
1071 {
1072   int aNum;
1073   bool bOk;
1074   for (int i = 0; i < count(); i++) {
1075     aNum = text(i).toInt(&bOk);
1076     if (bOk) {
1077       if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1078         insertItem(QString::number(theValue), i);
1079         return;
1080       }
1081     }
1082   }
1083   insertItem(QString::number(theValue));
1084 }
1085
1086 //================================================================
1087 // Function : SalomeApp_ComboBox::insertList
1088 /*! Purpose  : adds list of items in combo box*/
1089 //================================================================
1090 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
1091 {
1092   for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1093     insertItem(aIter.Value());
1094 }
1095
1096 //================================================================
1097 // Function : SalomeApp_ComboBox::insertItem
1098 /*! Purpose  : adds item in combo box*/
1099 //================================================================
1100 void SalomeApp_ComboBox::insertItem(const double theValue)
1101 {
1102   double aNum;
1103   bool bOk;
1104   for (int i = 0; i < count(); i++) {
1105     aNum = text(i).toDouble(&bOk);
1106     if (bOk) {
1107       if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1108         insertItem(QString::number(theValue), i);
1109         return;
1110       }
1111     }
1112   }
1113   insertItem(QString::number(theValue));
1114 }
1115
1116 //================================================================
1117 // Function : SalomeApp_ComboBox::insertList
1118 /*! Purpose  : adds list of items in combo box*/
1119 //================================================================
1120 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1121 {
1122   for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1123     insertItem(aIter.Value());
1124 }
1125
1126 //////////////////////////////////////////////////////////////////////
1127 // SalomeApp_EntityEdit class implementation
1128 //////////////////////////////////////////////////////////////////////
1129
1130 #include <qlayout.h>
1131
1132 #define MIN_COMBO_WIDTH     1
1133 #define MIN_EDIT_WIDTH      1
1134
1135 //================================================================
1136 // Function : SalomeApp_EntityEdit::SalomeApp_EntityEdit
1137 /*! Purpose  : constructor*/
1138 //================================================================
1139 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1140                                int      controlType,
1141                                int      valueType,
1142                                bool     butApply,
1143                                bool     butCancel) :
1144 QWidget(parent),
1145 myEdit(0),
1146 myCombo(0),
1147 myApplyBtn(0),
1148 myCancelBtn(0)
1149 {
1150   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1151   SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1152
1153   QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1154   aTopLayout->setAlignment( Qt::AlignTop );
1155   aTopLayout->setSpacing( 0 );
1156   aTopLayout->setMargin( 1 );
1157   if (controlType != etLineEdit &&
1158       controlType != etComboBox &&
1159       controlType != etComboEdit)
1160     controlType = etLineEdit;
1161   if (controlType == etComboBox || controlType == etComboEdit) {
1162     // this is an editable combo box
1163     myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1164     myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1165     myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1166                                        QSizePolicy::Fixed));
1167     // no insertions
1168     myCombo->setInsertionPolicy(QComboBox::NoInsertion);
1169     // no duplicates enabled by default
1170     myCombo->setDuplicatesEnabled(false);
1171     aTopLayout->addWidget(myCombo);
1172     // connect signals
1173     connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1174     connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1175   }
1176   else {
1177     // and this is an edit box
1178     myEdit = new SalomeApp_EditBox(this);
1179     myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1180     myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1181                                       QSizePolicy::Fixed));
1182     aTopLayout->addWidget(myEdit);
1183     connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1184     connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1185     connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1186   }
1187   if (valueType != vtString &&
1188       valueType != vtInteger &&
1189       valueType != vtDouble)
1190     valueType = vtString;
1191   if (valueType == vtInteger)
1192     setValidator(new QIntValidator(this));
1193   else if (valueType == vtDouble)
1194     setValidator(new QDoubleValidator(this));
1195   if (butApply) {
1196     // Apply button (V)
1197     myApplyBtn = new QToolButton(this);
1198
1199     QPixmap anIcon;
1200     if( mgr )
1201       anIcon = mgr->loadPixmap( "STD", tr( "ICON_APPLY" ), false );
1202
1203     myApplyBtn->setPixmap(anIcon);
1204     myApplyBtn->setEnabled(false);
1205     myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1206     myApplyBtn->setMinimumSize(16, 16);
1207     myApplyBtn->setMaximumSize(16, 20);
1208     aTopLayout->addWidget(myApplyBtn);
1209     connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1210   }
1211   if (butCancel) {
1212     // Cancel button (X)
1213     myCancelBtn = new QToolButton(this);
1214     QPixmap anIcon;
1215     if( mgr )
1216       anIcon = mgr->loadPixmap( "STD", tr( "ICON_CANCEL" ), false );
1217     myCancelBtn->setPixmap(anIcon);
1218     myCancelBtn->setEnabled(false);
1219     myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1220     myCancelBtn->setMinimumSize(16, 16);
1221     myCancelBtn->setMaximumSize(16, 20);
1222     aTopLayout->addWidget(myCancelBtn);
1223     connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1224   }
1225 }
1226
1227 //================================================================
1228 // Function : SalomeApp_EntityEdit::~SalomeApp_EntityEdit
1229 /*! Purpose  : destructor*/
1230 //================================================================
1231 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1232 {
1233 }
1234
1235 //================================================================
1236 // Function : SalomeApp_EntityEdit::clear
1237 /*! Purpose  : clears edit/combo box*/
1238 //================================================================
1239 void SalomeApp_EntityEdit::clear()
1240 {
1241   if (myEdit)
1242     myEdit->clear();
1243   if (myCombo)
1244     myCombo->clear();
1245 }
1246
1247 //================================================================
1248 // Function : SalomeApp_EntityEdit::getText
1249 /*! Purpose  : returns current text in edit box or combo box*/
1250 //================================================================
1251 QString SalomeApp_EntityEdit::getText()
1252 {
1253   if (myEdit)
1254     return myEdit->text();
1255   else if (myCombo)
1256     return myCombo->currentText();
1257   else
1258     return "";
1259 }
1260
1261 //================================================================
1262 // Function : SalomeApp_EntityEdit::setText
1263 /*! Purpose  : sets text*/
1264 //================================================================
1265 void SalomeApp_EntityEdit::setText(const QString& theText)
1266 {
1267   myString = theText;
1268   if (myEdit)
1269     myEdit->setText(theText);
1270   if (myCombo) {
1271     int aFound = myCombo->findItem(theText);
1272     if (aFound >= 0) {
1273       myCombo->setCurrentItem(aFound);
1274       onTextChanged(theText);
1275     }
1276   }
1277 }
1278
1279 //================================================================
1280 // Function : SalomeApp_EntityEdit::insertItem
1281 /*! Purpose  : adds item in combo box,
1282  *            sets it current if theSetCurrent is true
1283  */
1284 //================================================================
1285 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1286                                 bool           theSetCurrent,
1287                                 int            theOrder)
1288 {
1289   if (myCombo) {
1290     int aIndexAt = -1;
1291     if (theOrder == atTop)
1292       aIndexAt = 0;
1293     else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1294       aIndexAt = myCombo->currentItem();
1295     else if (theOrder == atAfterCurrent &&
1296              myCombo->count() > 0 &&
1297              myCombo->currentItem() < myCombo->count()-1)
1298       aIndexAt = myCombo->currentItem() + 1;
1299     myCombo->insertItem(theValue, aIndexAt);
1300   }
1301   if (theSetCurrent)
1302     setText(theValue);
1303 }
1304
1305 //================================================================
1306 // Function : SalomeApp_EntityEdit::insertList
1307 /*! Purpose  : adds items in combo box,
1308  *            sets item theCurrent as current
1309  */
1310 //================================================================
1311 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1312                                 const int          theCurrent)
1313 {
1314   if (myCombo)
1315     myCombo->insertList(theList);
1316   if (theCurrent >= 0 && theCurrent < (int)theList.count())
1317     setText(theList[theCurrent]);
1318 }
1319
1320 //================================================================
1321 // Function : SalomeApp_EntityEdit::insertItem
1322 /*! Purpose  : adds item in combo box,
1323  *            sets it current if theSetCurrent is true
1324  */
1325 //================================================================
1326 void SalomeApp_EntityEdit::insertItem(const int theValue,
1327                                 bool      theSetCurrent)
1328 {
1329   if (myCombo) {
1330     myCombo->insertItem(theValue);
1331   }
1332   if (theSetCurrent)
1333     setText(QString::number(theValue));
1334 }
1335
1336 //================================================================
1337 // Function : SalomeApp_EntityEdit::insertList
1338 /*! Purpose  : adds items in combo box,
1339  *            sets item theCurrent as current
1340  */
1341 //================================================================
1342 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1343                                 const int                    theCurrent)
1344 {
1345   if (myCombo)
1346     myCombo->insertList(theList);
1347
1348   TColStd_ListIteratorOfListOfInteger aIter(theList);
1349   for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1350     if (theCurrent == i) {
1351       setText(QString::number(aIter.Value()));
1352       break;
1353     }
1354   }
1355 }
1356
1357 //================================================================
1358 // Function : SalomeApp_EntityEdit::insertItem
1359 // Purpose  : adds item in combo box,
1360 //            sets it current if theSetCurrent is true
1361 //================================================================
1362 void SalomeApp_EntityEdit::insertItem(const double theValue,
1363                                 bool         theSetCurrent)
1364 {
1365   if (myCombo) {
1366     myCombo->insertItem(theValue);
1367   }
1368   if (theSetCurrent)
1369     setText(QString::number(theValue));
1370 }
1371
1372 //================================================================
1373 // Function : SalomeApp_EntityEdit::insertList
1374 /*! Purpose  : adds items in combo box,
1375  *            sets item theCurrent as current
1376  */
1377 //================================================================
1378 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1379                                 const int                 theCurrent)
1380 {
1381   if (myCombo)
1382     myCombo->insertList(theList);
1383
1384   TColStd_ListIteratorOfListOfReal aIter(theList);
1385   for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1386     if (theCurrent == i) {
1387       setText(QString::number(aIter.Value()));
1388       break;
1389     }
1390   }
1391 }
1392
1393 //================================================================
1394 // Function : SalomeApp_EntityEdit::getControl
1395 /*! Purpose  : gets actual widget*/
1396 //================================================================
1397 QWidget* SalomeApp_EntityEdit::getControl()
1398 {
1399   if (myEdit)
1400     return myEdit;
1401   else if (myCombo)
1402     return myCombo;
1403   else
1404     return 0;
1405 }
1406
1407 //================================================================
1408 // Function : SalomeApp_EntityEdit::setFocus
1409 /*! Purpose  : redirect focus to corresponding widget*/
1410 //================================================================
1411 void SalomeApp_EntityEdit::setFocus()
1412 {
1413   if (myEdit) {
1414     myEdit->setFocus();
1415     //myEdit->selectAll();
1416   }
1417   else if (myCombo && myCombo->editable()) {
1418     myCombo->setFocus();
1419     //myCombo->lineEdit()->selectAll();
1420   }
1421 }
1422
1423 //================================================================
1424 // Function : SalomeApp_EntityEdit::setValidator
1425 /*! Purpose  : sets validator for the control*/
1426 //================================================================
1427 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1428 {
1429   if (myEdit)
1430     myEdit->setValidator(theValidator);
1431   if (myCombo)
1432     myCombo->setValidator(theValidator);
1433 }
1434
1435 //================================================================
1436 // Function : SalomeApp_EntityEdit::keyPressEvent
1437 /*! Purpose  : event filter for KeyPress event*/
1438 //================================================================
1439 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1440 {
1441   if ( (e->key() == Key_Enter ||
1442         e->key() == Key_Return ) )
1443     onApply();
1444   else if (e->key() == Key_Escape)
1445     onCancel();
1446 }
1447
1448 //================================================================
1449 // Function : SalomeApp_EntityEdit::onComboActivated
1450 /*! Purpose  : called when item activated in combo box*/
1451 //================================================================
1452 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1453 {
1454   onTextChanged(theText);
1455 }
1456
1457 //================================================================
1458 // Function : SalomeApp_EntityEdit::onTextChanged
1459 /*! Purpose  : slot, called when text changed in line edit*/
1460 //================================================================
1461 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1462 {
1463   if (myApplyBtn)
1464     myApplyBtn->setEnabled(!(theText == myString));
1465   if (myCancelBtn)
1466     myCancelBtn->setEnabled(!(theText == myString));
1467 }
1468
1469 //================================================================
1470 // Function : SalomeApp_EntityEdit::onCancel
1471 /*! Purpose  : slot, called when user presses Cancel button*/
1472 //================================================================
1473 void SalomeApp_EntityEdit::onCancel()
1474 {
1475   setText(myString);
1476   if (myApplyBtn)
1477     myApplyBtn->setEnabled(false);
1478   if (myCancelBtn)
1479     myCancelBtn->setEnabled(false);
1480   emit escapePressed();
1481 }
1482
1483 //================================================================
1484 // Function : SalomeApp_EntityEdit::onApply
1485 /*! Purpose  : slot, called when user presses Apply button*/
1486 //================================================================
1487 void SalomeApp_EntityEdit::onApply()
1488 {
1489   myString = getText();
1490   if (myApplyBtn)
1491     myApplyBtn->setEnabled(false);
1492   if (myCancelBtn)
1493     myCancelBtn->setEnabled(false);
1494   emit returnPressed();
1495 }
1496
1497 //================================================================
1498 // Function : SalomeApp_EntityEdit::showButtons
1499 /*! Purpose  : shows/hides buttons*/
1500 //================================================================
1501 void SalomeApp_EntityEdit::showButtons(bool show)
1502 {
1503   if (myApplyBtn)
1504     show ? myApplyBtn->show()  : myApplyBtn->hide();
1505   if (myCancelBtn)
1506     show ? myCancelBtn->show() : myCancelBtn->hide();
1507 }
1508
1509 //================================================================
1510 // Function : SalomeApp_EntityEdit::setDuplicatesEnabled
1511 /*! Purpose  : enables/disables data duplication (for combo box)*/
1512 //================================================================
1513 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1514 {
1515   if (myCombo)
1516     myCombo->setDuplicatesEnabled(enabled);
1517 }