Salome HOME
basic implementation of images operations support
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ObjSelector.cxx
1
2 #include <HYDROGUI_ObjSelector.h>
3 #include <HYDROGUI_Module.h>
4 #include <LightApp_Application.h>
5 #include <LightApp_SelectionMgr.h>
6 #include <LightApp_GVSelector.h>
7 #include <GraphicsView_Object.h>
8 #include <QLayout>
9 #include <QToolButton>
10 #include <QLineEdit>
11
12 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent )
13 : QAbstractButton( theParent ), myModule( theModule )
14 {
15   QHBoxLayout* aLayout = new QHBoxLayout( this );
16   myBtn = new QToolButton( this );
17   myBtn->setCheckable( true );
18   myBtn->setChecked( false );
19   myObjName = new QLineEdit( this );
20   myObjName->setReadOnly( true );
21   aLayout->addWidget( myBtn, 0 );
22   aLayout->addWidget( myObjName, 1 );
23
24   SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
25
26   connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
27   connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
28 }
29
30 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
31 {
32 }
33
34 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
35 {
36 }
37
38 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
39 {
40   return false;
41 }
42
43 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
44 {
45   if( !isChecked )
46     return;
47
48   QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
49   foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
50     if( aSelector != this )
51       aSelector->myBtn->setChecked( false );
52
53   if( isChecked )
54     OnSelectionChanged();
55 }
56
57 void HYDROGUI_ObjSelector::OnSelectionChanged()
58 {
59   if( !myBtn->isChecked() )
60     return;
61
62   SUIT_SelectionMgr* aSelMgr = myModule->getApp()->selectionMgr();
63   SUIT_DataOwnerPtrList anOwners;
64   aSelMgr->selected( anOwners );
65
66   QString anObjName;
67   foreach( SUIT_DataOwner* anOwner, anOwners )
68   {
69     LightApp_GVDataOwner* aGrDOwner = dynamic_cast<LightApp_GVDataOwner*>( anOwner );
70     if( aGrDOwner )
71     {
72       anObjName = aGrDOwner->object()->getName();
73       break;
74     }
75   }
76   myObjName->setText( anObjName );
77 }
78
79 QString HYDROGUI_ObjSelector::GetName() const
80 {
81   return myObjName->text();
82 }