]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_RecorderDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VVTK / VVTK_RecorderDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : VVTK_RecorderDlg.cxx
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27
28 #include "VVTK_RecorderDlg.h"
29 #include "VVTK_Recorder.h"
30
31 #include "SUIT_FileDlg.h"
32 #include "SUIT_MessageBox.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
35
36 #include "QtxDblSpinBox.h"
37 #include "QtxIntSpinBox.h"
38
39 #include "LightApp_Application.h"
40
41 #include <qcheckbox.h>
42 #include <qcombobox.h>
43 #include <qgroupbox.h>
44 #include <qlabel.h>
45 #include <qlayout.h>
46 #include <qlineedit.h>
47 #include <qpushbutton.h>
48
49 /*!
50  * Constructor
51  */
52 VVTK_RecorderDlg::VVTK_RecorderDlg( QWidget* theParent, VVTK_Recorder* theRecorder ):
53   QDialog( theParent, "VVTK_RecorderDlg", false ),
54   myRecorder( theRecorder )
55 {
56   setCaption( tr( "DLG_RECORDER_TITLE" ) );
57
58   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
59
60   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
61   aTopLayout->setSpacing( 6 );
62   aTopLayout->setMargin( 6 );
63   aTopLayout->setAutoAdd( true );
64
65   // Settings
66   QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this );
67   mySettingsBox->setColumnLayout( 0, Qt::Vertical );
68   mySettingsBox->layout()->setSpacing( 0 );
69   mySettingsBox->layout()->setMargin( 0 );
70
71   QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox->layout() );
72   aSettingsLayout->setSpacing( 6 );
73   aSettingsLayout->setMargin( 11 );
74
75   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
76   myFileNameLineEdit = new QLineEdit( mySettingsBox );
77   myFileNameLineEdit->setMinimumWidth( 250 );
78   myFileNameLineEdit->setReadOnly( true );
79   /*
80   QPushButton* aFileNameButton = new QPushButton( mySettingsBox );
81   aFileNameButton->setAutoDefault( false );
82   aFileNameButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
83   connect( aFileNameButton, SIGNAL( clicked() ), this, SLOT( onBrowseFile() ) );
84   */
85   QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox );
86   myRecordingModeComboBox = new QComboBox( mySettingsBox );
87   myRecordingModeComboBox->insertItem( tr( "SKIPPED_FRAMES" ) );
88   myRecordingModeComboBox->insertItem( tr( "ALL_DISLPAYED_FRAMES" ) );
89   myRecordingModeComboBox->setCurrentItem( aResourceMgr->integerValue( "VISU", "recorder_mode", 1 ) );
90
91   QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox );
92   myFPSSpinBox = new QtxDblSpinBox( 0.1, 100.0, 1.0, mySettingsBox );
93   myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VISU", "recorder_fps", 10.0 ) );
94
95   QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox );
96   myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox );
97   myQualitySpinBox->setValue( aResourceMgr->integerValue( "VISU", "recorder_quality", 80 ) );
98
99   myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox );
100   myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "recorder_progressive", false ) );
101
102   aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
103   aSettingsLayout->addMultiCellWidget( myFileNameLineEdit, 1, 1, 0, 1 );
104   //aSettingsLayout->addWidget( aFileNameButton, 1, 2 );
105   aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 );
106   aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 );
107   aSettingsLayout->addWidget( aFPSLabel, 3, 0 );
108   aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 );
109   aSettingsLayout->addWidget( aQualityLabel, 4, 0 );
110   aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 );
111   aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 );
112
113   // Start / Close
114   QGroupBox* CommonGroup = new QGroupBox( this );
115   CommonGroup->setColumnLayout(0, Qt::Vertical );
116   CommonGroup->layout()->setSpacing( 0 );
117   CommonGroup->layout()->setMargin( 0 );
118   QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup->layout() );
119   CommonGroupLayout->setAlignment( Qt::AlignTop );
120   CommonGroupLayout->setSpacing( 6 );
121   CommonGroupLayout->setMargin( 11 );
122
123   QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup );
124   aStartButton->setAutoDefault( true );
125   aStartButton->setDefault( true );
126   CommonGroupLayout->addWidget( aStartButton, 0, 0 );
127   CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
128
129   QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
130   aCloseButton->setAutoDefault( true );
131   CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
132
133   QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
134   aHelpButton->setAutoDefault( true );
135   CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
136
137   connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
138   connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
139   connect( aHelpButton,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
140 }
141
142 VVTK_RecorderDlg::~VVTK_RecorderDlg()
143 {
144 }
145
146 void VVTK_RecorderDlg::show()
147 {
148   if( onBrowseFile() )
149     QWidget::show();
150 }
151
152 void VVTK_RecorderDlg::onStart()
153 {
154   if( myFileName.isNull() )
155     return;
156
157   myRecorder->SetName( myFileName.latin1() );
158
159   myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentItem() == 0 );
160   myRecorder->SetNbFPS( myFPSSpinBox->value() );
161   myRecorder->SetQuality( myQualitySpinBox->value() );
162   myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() );
163
164   accept();
165
166 }
167
168 void VVTK_RecorderDlg::onClose()
169 {
170   reject();
171 }
172
173 void VVTK_RecorderDlg::onHelp()
174 {
175   QString aHelpFileName = "animation_in_gauss_viewer.htm";
176   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
177   if (app)
178     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
179   else {
180                 QString platform;
181 #ifdef WIN32
182                 platform = "winapplication";
183 #else
184                 platform = "application";
185 #endif
186     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
187                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
188                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
189                            QObject::tr("BUT_OK"));
190   }
191 }
192
193 bool VVTK_RecorderDlg::onBrowseFile()
194 {
195   QString aRootDir = QString( getenv( "VISU_ROOT_DIR") );
196
197   QStringList aFilter;
198   aFilter.append( tr( "FLT_AVI_FILES" ) );
199   aFilter.append( tr( "FLT_ALL_FILES" ) );
200
201   QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter,
202                                                  tr( "FILE_NAME" ), false );
203
204   if( aFileName.isNull() )
205     return false;
206
207   myFileName = aFileName;
208   myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
209
210   return true;
211 }
212
213 void VVTK_RecorderDlg::keyPressEvent( QKeyEvent* e )
214 {
215   QDialog::keyPressEvent( e );
216   if ( e->isAccepted() )
217     return;
218
219   if ( e->key() == Key_F1 )
220     {
221       e->accept();
222       onHelp();
223     }
224 }