Salome HOME
NRI : Add QAD_Desktop.h.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_TransparencyDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_TransparencyDlg.cxx
3 //  Created   : Thu Jun 06 16:41:42 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11
12 #include "SMESHGUI_TransparencyDlg.h"
13 #include "SMESHGUI.h"
14
15 #include "VTKViewer_ViewFrame.h"
16 #include "VTKViewer_RenderWindowInteractor.h"
17 #include "QAD_RightFrame.h"
18 #include "SALOME_ListIteratorOfListIO.hxx"
19
20 // QT Includes
21 #include <qframe.h>
22 #include <qlabel.h>
23 #include <qpushbutton.h>
24 #include <qslider.h>
25 #include <qlayout.h>
26 #include <qvariant.h>
27 #include <qtooltip.h>
28 #include <qwhatsthis.h>
29 #include <qapplication.h>
30 #include <qgroupbox.h>
31
32
33 //=================================================================================
34 // class    : SMESHGUI_TransparencyDlg()
35 // purpose  : 
36 //
37 //=================================================================================
38 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent,
39                                                     const char* name,
40                                                     SALOME_Selection* Sel,
41                                                     bool modal,
42                                                     WFlags fl )
43   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 {
45   if ( !name )
46     setName( "SMESHGUI_TransparencyDlg" );
47   resize( 152, 107 ); 
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 );
53
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 );
63
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 );
71
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 );
81   
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 );
87   
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 );
92   
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 );
97
98   SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1,      0, 0 );
99   SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
100   
101   /* Initialisations */
102   this->mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
103   this->mySel = Sel ;
104   
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 ) ;
110
111
112   this->ValueHasChanged( Slider1->value() ) ;
113   
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) ) );
117   
118   /* Move widget on the botton right corner of main widget */
119   int x, y ;
120   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
121   this->move( x, y ) ;
122   this->show() ; /* Displays this Dialog */
123 }
124
125
126
127
128 //=================================================================================
129 // function : ~SMESHGUI_TransparencyDlg()
130 // purpose  :
131 //=================================================================================
132 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
133 {
134     // no need to delete child widgets, Qt does it all for us
135 }
136
137
138 //=======================================================================
139 // function : ClickOnOk()
140 // purpose  :
141 //=======================================================================
142 void SMESHGUI_TransparencyDlg::ClickOnOk()
143 {
144   accept() ;
145   return ;
146 }
147
148
149 //=======================================================================
150 // function : ClickOnClose()
151 // purpose  :
152 //=======================================================================
153 void SMESHGUI_TransparencyDlg::ClickOnClose()
154 {
155   accept() ;
156   return ;
157 }
158
159
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 )
166 {
167
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) ) ;
178         return;
179       }
180     }
181     
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 );
186     }
187     QApplication::restoreOverrideCursor();
188   }
189   QApplication::restoreOverrideCursor();
190   return ;
191 }