Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_TransparencyDlg.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 #include "SMESHGUI_Utils.h"
00033 #include "SMESH_Actor.h"
00034
00035
00036 #include <SUIT_Desktop.h>
00037 #include <SUIT_OverrideCursor.h>
00038 #include <SUIT_Session.h>
00039 #include <SUIT_MessageBox.h>
00040 #include <SUIT_ResourceMgr.h>
00041
00042 #include <SALOME_ListIO.hxx>
00043 #include <SALOME_ListIteratorOfListIO.hxx>
00044
00045 #include <LightApp_Application.h>
00046 #include <LightApp_SelectionMgr.h>
00047
00048 #include <SVTK_ViewWindow.h>
00049
00050
00051 #include <QLabel>
00052 #include <QPushButton>
00053 #include <QSlider>
00054 #include <QVBoxLayout>
00055 #include <QHBoxLayout>
00056 #include <QGridLayout>
00057 #include <QGroupBox>
00058 #include <QKeyEvent>
00059
00060 #define SPACING 6
00061 #define MARGIN 11
00062
00063
00064
00065
00066
00067
00068 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule )
00069 : QDialog( SMESH::GetDesktop( theModule ) ),
00070 mySMESHGUI( theModule ),
00071 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00072 myViewWindow( SMESH::GetViewWindow( theModule ) )
00073 {
00074 setModal( false );
00075 setAttribute( Qt::WA_DeleteOnClose, true );
00076 setWindowTitle( tr( "SMESH_TRANSPARENCY_TITLE" ) );
00077 setSizeGripEnabled( true );
00078
00079 QVBoxLayout* SMESHGUI_TransparencyDlgLayout = new QVBoxLayout( this );
00080 SMESHGUI_TransparencyDlgLayout->setSpacing( SPACING );
00081 SMESHGUI_TransparencyDlgLayout->setMargin( MARGIN );
00082
00083
00084 QGroupBox* GroupC1 = new QGroupBox( this );
00085 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
00086 GroupC1Layout->setSpacing( SPACING );
00087 GroupC1Layout->setMargin( MARGIN );
00088
00089 TextLabelTransparent = new QLabel( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
00090 TextLabelTransparent->setAlignment( Qt::AlignRight );
00091
00092 ValueLab = new QLabel( GroupC1 );
00093 ValueLab->setAlignment( Qt::AlignCenter );
00094 ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00095 QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
00096
00097 TextLabelOpaque = new QLabel( tr( "SMESH_TRANSPARENCY_OPAQUE" ), GroupC1 );
00098 TextLabelOpaque->setAlignment( Qt::AlignLeft );
00099
00100 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
00101 Slider1->setRange( 0, 100 );
00102 Slider1->setSingleStep( 1 );
00103 Slider1->setPageStep( 10 );
00104 Slider1->setTickPosition( QSlider::TicksAbove );
00105 Slider1->setTickInterval( 10 );
00106 Slider1->setTracking( true );
00107 Slider1->setFocusPolicy( Qt::NoFocus );
00108 Slider1->setMinimumWidth( 300 );
00109
00110 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
00111 GroupC1Layout->addWidget( ValueLab, 0, 1 );
00112 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
00113 GroupC1Layout->addWidget( Slider1, 1, 0, 1, 3 );
00114
00115
00116 QGroupBox* GroupButtons = new QGroupBox( this );
00117 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00118 GroupButtonsLayout->setSpacing( SPACING );
00119 GroupButtonsLayout->setMargin( MARGIN );
00120
00121 buttonOk = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
00122 buttonOk->setAutoDefault( true );
00123 buttonOk->setDefault( true );
00124 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
00125 buttonHelp->setAutoDefault( true );
00126
00127 GroupButtonsLayout->addWidget( buttonOk );
00128 GroupButtonsLayout->addSpacing( 10 );
00129 GroupButtonsLayout->addStretch();
00130 GroupButtonsLayout->addWidget( buttonHelp );
00131
00132
00133 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1 );
00134 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons );
00135
00136
00137 onSelectionChanged();
00138
00139
00140 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00141 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00142 connect( Slider1, SIGNAL( valueChanged( int ) ), this, SLOT( SetTransparency() ) );
00143 connect( Slider1, SIGNAL( sliderMoved( int ) ), this, SLOT( ValueHasChanged() ) );
00144 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnOk() ) );
00145 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
00146
00147 myHelpFileName = "transparency_page.html";
00148 }
00149
00150
00151
00152
00153
00154 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
00155 {
00156 }
00157
00158
00159
00160
00161
00162 void SMESHGUI_TransparencyDlg::ClickOnOk()
00163 {
00164 close();
00165 }
00166
00167
00168
00169
00170
00171 void SMESHGUI_TransparencyDlg::ClickOnHelp()
00172 {
00173 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00174 if ( app )
00175 app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) :
00176 QString( "" ), myHelpFileName );
00177 else {
00178 QString platform;
00179 #ifdef WIN32
00180 platform = "winapplication";
00181 #else
00182 platform = "application";
00183 #endif
00184 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
00185 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
00186 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
00187 platform ) ).
00188 arg( myHelpFileName ) );
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197 void SMESHGUI_TransparencyDlg::SetTransparency()
00198 {
00199 if ( myViewWindow ) {
00200 SUIT_OverrideCursor wc;
00201 float opacity = ( 100 - Slider1->value() ) / 100.;
00202
00203 SALOME_ListIO aList;
00204 mySelectionMgr->selectedObjects( aList );
00205
00206 SALOME_ListIteratorOfListIO It( aList );
00207 for ( ; It.More(); It.Next() ) {
00208 Handle(SALOME_InteractiveObject) IOS = It.Value();
00209 SMESH_Actor* anActor = SMESH::FindActorByEntry( IOS->getEntry() );
00210 if ( anActor )
00211 anActor->SetOpacity( opacity );
00212 }
00213 myViewWindow->Repaint();
00214 }
00215 ValueHasChanged();
00216 }
00217
00218
00219
00220
00221
00222 void SMESHGUI_TransparencyDlg::ValueHasChanged()
00223 {
00224 ValueLab->setText( QString::number( Slider1->value() ) + "%") ;
00225 }
00226
00227
00228
00229
00230
00231 void SMESHGUI_TransparencyDlg::onSelectionChanged()
00232 {
00233 if ( myViewWindow ) {
00234 int opacity = 100;
00235
00236 SALOME_ListIO aList;
00237 mySelectionMgr->selectedObjects( aList );
00238
00239 if ( aList.Extent() == 1 ) {
00240 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
00241 if ( !FirstIOS.IsNull() ) {
00242 SMESH_Actor* anActor = SMESH::FindActorByEntry( FirstIOS->getEntry() );
00243 if ( anActor )
00244 opacity = int( anActor->GetOpacity() * 100. + 0.5 );
00245 }
00246 }
00247 else if ( aList.Extent() > 1 ) {
00248 SALOME_ListIteratorOfListIO It( aList );
00249 int setOp = -1;
00250 for ( ; It.More(); It.Next() ) {
00251 Handle(SALOME_InteractiveObject) IO = It.Value();
00252 if ( !IO.IsNull() ) {
00253 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
00254 if ( anActor ) {
00255 int op = int( anActor->GetOpacity() * 100. + 0.5 );
00256 if ( setOp < 0 )
00257 setOp = op;
00258 else if ( setOp != op ) {
00259 setOp = 100;
00260 break;
00261 }
00262 }
00263 }
00264 }
00265 if ( setOp >= 0 )
00266 opacity = setOp;
00267 }
00268 else {
00269 }
00270 Slider1->setValue( 100 - opacity );
00271 }
00272 ValueHasChanged();
00273 }
00274
00275
00276
00277
00278
00279 void SMESHGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
00280 {
00281 QDialog::keyPressEvent( e );
00282 if ( e->isAccepted() )
00283 return;
00284
00285 if ( e->key() == Qt::Key_F1 ) {
00286 e->accept();
00287 ClickOnHelp();
00288 }
00289 }