2 // File : SMESHGUI_TransparencyDlg.cxx
3 // Created : Thu Jun 06 16:41:42 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_TransparencyDlg.h"
15 #include "VTKViewer_ViewFrame.h"
16 #include "VTKViewer_RenderWindowInteractor.h"
17 #include "QAD_RightFrame.h"
18 #include "SALOME_ListIteratorOfListIO.hxx"
23 #include <qpushbutton.h>
28 #include <qwhatsthis.h>
29 #include <qapplication.h>
30 #include <qgroupbox.h>
33 //=================================================================================
34 // class : SMESHGUI_TransparencyDlg()
37 //=================================================================================
38 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent,
40 SALOME_Selection* Sel,
43 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 setName( "SMESHGUI_TransparencyDlg" );
48 setCaption( tr( "SMESH_TRANSPARENCY_TITLE" ) );
49 setSizeGripEnabled( TRUE );
50 SMESHGUI_TransparencyDlgLayout = new QGridLayout( this );
51 SMESHGUI_TransparencyDlgLayout->setSpacing( 6 );
52 SMESHGUI_TransparencyDlgLayout->setMargin( 11 );
54 /*************************************************************************/
55 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
56 GroupButtons->setColumnLayout(0, Qt::Vertical );
57 GroupButtons->layout()->setSpacing( 0 );
58 GroupButtons->layout()->setMargin( 0 );
59 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
60 GroupButtonsLayout->setAlignment( Qt::AlignTop );
61 GroupButtonsLayout->setSpacing( 6 );
62 GroupButtonsLayout->setMargin( 11 );
64 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
65 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
66 buttonOk->setAutoDefault( TRUE );
67 buttonOk->setDefault( TRUE );
68 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
69 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
70 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
72 /*************************************************************************/
73 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
74 GroupC1->setColumnLayout(0, Qt::Vertical );
75 GroupC1->layout()->setSpacing( 0 );
76 GroupC1->layout()->setMargin( 0 );
77 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
78 GroupC1Layout->setAlignment( Qt::AlignTop );
79 GroupC1Layout->setSpacing( 6 );
80 GroupC1Layout->setMargin( 11 );
82 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
83 TextLabelOpaque->setText( tr( "SMESH_TRANSPARENCY_OPAQUE" ) );
84 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
85 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
86 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
88 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
89 TextLabelTransparent->setText( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ) );
90 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
91 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
93 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
94 Slider1->setMinimumSize( 300, 0 );
95 Slider1->setTickmarks( QSlider::Left );
96 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
98 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 );
99 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
101 /* Initialisations */
102 this->mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
105 /* First call valueChanged() method for initialisation */
106 /* The default value of transparency will change with the selection */
107 this->myFirstInit = true ;
108 // Slider1->setMaxValue( 10 );
109 // Slider1->setValue( 5 ) ;
112 this->ValueHasChanged( Slider1->value() ) ;
114 // signals and slots connections : after ValueHasChanged()
115 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116 connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( ValueHasChanged(int) ) );
118 /* Move widget on the botton right corner of main widget */
120 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
122 this->show() ; /* Displays this Dialog */
128 //=================================================================================
129 // function : ~SMESHGUI_TransparencyDlg()
131 //=================================================================================
132 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
134 // no need to delete child widgets, Qt does it all for us
138 //=======================================================================
139 // function : ClickOnOk()
141 //=======================================================================
142 void SMESHGUI_TransparencyDlg::ClickOnOk()
149 //=======================================================================
150 // function : ClickOnClose()
152 //=======================================================================
153 void SMESHGUI_TransparencyDlg::ClickOnClose()
160 //=================================================================================
161 // function : ValueHasChanged()
162 // purpose : Called when value of slider change
163 // : or the first time as initilisation
164 //=================================================================================
165 void SMESHGUI_TransparencyDlg::ValueHasChanged( int newValue )
168 if ( mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
169 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
170 SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
171 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject();
172 if( !FirstIOS.IsNull() ) {
173 /* The first time as initialisation */
174 if( this->myFirstInit ) {
175 this->myFirstInit = false ;
176 float transp = ( myRenderInter->GetTransparency(FirstIOS))*10.0 ;
177 this->Slider1->setValue( int(transp) ) ;
182 QApplication::setOverrideCursor( Qt::waitCursor );
183 for( ;It.More(); It.Next() ) {
184 Handle(SALOME_InteractiveObject) IOS = It.Value();
185 myRenderInter->SetTransparency( IOS, newValue/10.0 );
187 QApplication::restoreOverrideCursor();
189 QApplication::restoreOverrideCursor();