Salome HOME
1) Export Image operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ObjSelector.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ObjSelector.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28
29 #include <GraphicsView_Object.h>
30
31 #include <LightApp_Application.h>
32 #include <LightApp_GVSelector.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37
38 #include <QLayout>
39 #include <QLineEdit>
40 #include <QToolButton>
41
42 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent )
43 : QAbstractButton( theParent ), myModule( theModule )
44 {
45   QHBoxLayout* aLayout = new QHBoxLayout( this );
46   aLayout->setMargin( 0 );
47   aLayout->setSpacing( 5 );
48   myBtn = new QToolButton( this );
49   myBtn->setCheckable( true );
50   myBtn->setChecked( false );
51   myObjName = new QLineEdit( this );
52   myObjName->setReadOnly( true );
53   aLayout->addWidget( myBtn, 0 );
54   aLayout->addWidget( myObjName, 1 );
55
56   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
57   myBtn->setIcon( QIcon( aResMgr->loadPixmap( "HYDRO", tr( "SELECT_ICO" ) ) ) );
58
59   SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
60
61   connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
62   connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
63 }
64
65 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
66 {
67 }
68
69 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
70 {
71 }
72
73 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
74 {
75   return false;
76 }
77
78 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
79 {
80   if( !isChecked )
81     return;
82
83   QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
84   foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
85     if( aSelector != this )
86       aSelector->myBtn->setChecked( false );
87
88   if( isChecked )
89     OnSelectionChanged();
90 }
91
92 void HYDROGUI_ObjSelector::OnSelectionChanged()
93 {
94   if( !myBtn->isChecked() )
95     return;
96
97   QString anObjName;
98   Handle(HYDROData_Object) anObject = HYDROGUI_Tool::GetSelectedObject( myModule );
99   if( !anObject.IsNull() )
100     anObjName = anObject->GetName();
101
102   myObjName->setText( anObjName );
103 }
104
105 QString HYDROGUI_ObjSelector::GetName() const
106 {
107   return myObjName->text();
108 }
109
110 void HYDROGUI_ObjSelector::Clear()
111 {
112   myObjName->clear();
113   myBtn->setChecked( false );
114 }