Back to index

salome-gui  6.5.0
SVTK_RecorderDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SVTK_RecorderDlg.h"
00021 #include "SVTK_Recorder.h"
00022 
00023 #include <SUIT_FileDlg.h>
00024 #include <SUIT_MessageBox.h>
00025 #include <SUIT_ResourceMgr.h>
00026 #include <SUIT_Session.h>
00027 
00028 #include <QtxDoubleSpinBox.h>
00029 #include <QtxIntSpinBox.h>
00030 
00031 #include <QCheckBox>
00032 #include <QComboBox>
00033 #include <QGroupBox>
00034 #include <QKeyEvent>
00035 #include <QLabel>
00036 #include <QLayout>
00037 #include <QLineEdit>
00038 #include <QPushButton>
00039 
00043 SVTK_RecorderDlg::SVTK_RecorderDlg( QWidget* theParent, SVTK_Recorder* theRecorder ):
00044   QDialog( theParent ),
00045   myRecorder( theRecorder )
00046 {
00047   setWindowTitle( tr( "DLG_RECORDER_TITLE" ) );
00048 
00049   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
00050 
00051   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
00052   aTopLayout->setSpacing( 6 );
00053   aTopLayout->setMargin( 6 );
00054 
00055   // Settings
00056   QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this );
00057 
00058   QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox );
00059   aSettingsLayout->setSpacing( 6 );
00060   aSettingsLayout->setMargin( 11 );
00061 
00062   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
00063   myFileNameLineEdit = new QLineEdit( mySettingsBox );
00064   myFileNameLineEdit->setMinimumWidth( 250 );
00065   myFileNameLineEdit->setReadOnly( true );
00066 
00067   QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox );
00068   myRecordingModeComboBox = new QComboBox( mySettingsBox );
00069   myRecordingModeComboBox->addItem( tr( "SKIPPED_FRAMES" ) );
00070   myRecordingModeComboBox->addItem( tr( "ALL_DISLPAYED_FRAMES" ) );
00071   myRecordingModeComboBox->setCurrentIndex( aResourceMgr->integerValue( "VTKViewer", "recorder_mode", 1 ) );
00072 
00073   QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox );
00074   myFPSSpinBox = new QtxDoubleSpinBox( 0.1, 100.0, 1.0, mySettingsBox );
00075   myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VTKViewer", "recorder_fps", 10.0 ) );
00076 
00077   QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox );
00078   myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox );
00079   myQualitySpinBox->setValue( aResourceMgr->integerValue( "VTKViewer", "recorder_quality", 80 ) );
00080 
00081   myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox );
00082   myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VTKViewer", "recorder_progressive", false ) );
00083 
00084   aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
00085   aSettingsLayout->addWidget( myFileNameLineEdit, 1, 0, 1, 2 );
00086   aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 );
00087   aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 );
00088   aSettingsLayout->addWidget( aFPSLabel, 3, 0 );
00089   aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 );
00090   aSettingsLayout->addWidget( aQualityLabel, 4, 0 );
00091   aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 );
00092   aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 );
00093 
00094   aTopLayout->addWidget( mySettingsBox );
00095 
00096   // Start / Close
00097   QGroupBox* CommonGroup = new QGroupBox( this );
00098   QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup );
00099   CommonGroupLayout->setAlignment( Qt::AlignTop );
00100   CommonGroupLayout->setSpacing( 6 );
00101   CommonGroupLayout->setMargin( 11 );
00102 
00103   QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup );
00104   aStartButton->setAutoDefault( true );
00105   aStartButton->setDefault( true );
00106   CommonGroupLayout->addWidget( aStartButton, 0, 0 );
00107   CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
00108 
00109   QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
00110   aCloseButton->setAutoDefault( true );
00111   CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
00112 
00113   //QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
00114   //aHelpButton->setAutoDefault( true );
00115   //CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
00116 
00117   aTopLayout->addWidget( CommonGroup );
00118 
00119   connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
00120   connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
00121   //connect( aHelpButton,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
00122 }
00123 
00124 SVTK_RecorderDlg::~SVTK_RecorderDlg()
00125 {
00126 }
00127 
00128 void SVTK_RecorderDlg::onStart()
00129 {
00130   if( myFileName.isNull() )
00131     return;
00132 
00133   myRecorder->SetName( (const char*)myFileName.toLatin1() );
00134 
00135   myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentIndex() == 0 );
00136   myRecorder->SetNbFPS( myFPSSpinBox->value() );
00137   myRecorder->SetQuality( myQualitySpinBox->value() );
00138   myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() );
00139 
00140   accept();
00141 
00142 }
00143 
00144 void SVTK_RecorderDlg::onClose()
00145 {
00146   reject();
00147 }
00148 
00149 void SVTK_RecorderDlg::onHelp()
00150 {
00151   /*
00152   QString aHelpFileName = "animation_in_gauss_viewer.htm";
00153   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00154   if (app)
00155     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
00156   else {
00157                 QString platform;
00158 #ifdef WIN32
00159                 platform = "winapplication";
00160 #else
00161                 platform = "application";
00162 #endif
00163     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
00164                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00165                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
00166   }
00167   */
00168 }
00169 
00170 bool SVTK_RecorderDlg::onBrowseFile()
00171 {
00172   QStringList aFilter;
00173   aFilter.append( tr( "FLT_AVI_FILES" ) );
00174   aFilter.append( tr( "FLT_ALL_FILES" ) );
00175 
00176   QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter,
00177                                                  tr( "FILE_NAME" ), false );
00178 
00179   if( aFileName.isNull() )
00180     return false;
00181 
00182   myFileName = aFileName;
00183   myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
00184 
00185   return true;
00186 }
00187 
00188 int SVTK_RecorderDlg::exec()
00189 {
00190   if( !onBrowseFile() )
00191   {
00192     reject();
00193     return 0;
00194   }
00195   return QDialog::exec();
00196 }
00197 
00198 void SVTK_RecorderDlg::keyPressEvent( QKeyEvent* e )
00199 {
00200   QDialog::keyPressEvent( e );
00201   if ( e->isAccepted() )
00202     return;
00203 
00204   if ( e->key() == Qt::Key_F1 )
00205     {
00206       e->accept();
00207       onHelp();
00208     }
00209 }