Salome HOME
Run SALOME with UNICODE path.
[modules/gui.git] / src / SVTK / SVTK_RecorderDlg.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SVTK_RecorderDlg.h"
21 #include "SVTK_Recorder.h"
22
23 #include <SUIT_FileDlg.h>
24 #include <SUIT_MessageBox.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
27
28 #include <Qtx.h>
29
30 #include <QtxDoubleSpinBox.h>
31 #include <QtxIntSpinBox.h>
32
33 #include <QCheckBox>
34 #include <QComboBox>
35 #include <QGroupBox>
36 #include <QKeyEvent>
37 #include <QLabel>
38 #include <QLayout>
39 #include <QLineEdit>
40 #include <QPushButton>
41
42 /*!
43  * Constructor
44  */
45 SVTK_RecorderDlg::SVTK_RecorderDlg( QWidget* theParent, SVTK_Recorder* theRecorder ):
46   QDialog( theParent ),
47   myRecorder( theRecorder )
48 {
49   setWindowTitle( tr( "DLG_RECORDER_TITLE" ) );
50
51   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
52
53   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
54   aTopLayout->setSpacing( 6 );
55   aTopLayout->setMargin( 6 );
56
57   // Settings
58   QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this );
59
60   QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox );
61   aSettingsLayout->setSpacing( 6 );
62   aSettingsLayout->setMargin( 11 );
63
64   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
65   myFileNameLineEdit = new QLineEdit( mySettingsBox );
66   myFileNameLineEdit->setMinimumWidth( 250 );
67   myFileNameLineEdit->setReadOnly( true );
68
69   QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox );
70   myRecordingModeComboBox = new QComboBox( mySettingsBox );
71   myRecordingModeComboBox->addItem( tr( "SKIPPED_FRAMES" ) );
72   myRecordingModeComboBox->addItem( tr( "ALL_DISLPAYED_FRAMES" ) );
73   myRecordingModeComboBox->setCurrentIndex( aResourceMgr->integerValue( "VTKViewer", "recorder_mode", 1 ) );
74
75   QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox );
76   myFPSSpinBox = new QtxDoubleSpinBox( 0.1, 100.0, 1.0, mySettingsBox );
77   myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VTKViewer", "recorder_fps", 10.0 ) );
78
79   QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox );
80   myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox );
81   myQualitySpinBox->setValue( aResourceMgr->integerValue( "VTKViewer", "recorder_quality", 80 ) );
82
83   myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox );
84   myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VTKViewer", "recorder_progressive", false ) );
85
86   aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
87   aSettingsLayout->addWidget( myFileNameLineEdit, 1, 0, 1, 2 );
88   aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 );
89   aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 );
90   aSettingsLayout->addWidget( aFPSLabel, 3, 0 );
91   aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 );
92   aSettingsLayout->addWidget( aQualityLabel, 4, 0 );
93   aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 );
94   aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 );
95
96   aTopLayout->addWidget( mySettingsBox );
97
98   // Start / Close
99   QGroupBox* CommonGroup = new QGroupBox( this );
100   QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup );
101   CommonGroupLayout->setAlignment( Qt::AlignTop );
102   CommonGroupLayout->setSpacing( 6 );
103   CommonGroupLayout->setMargin( 11 );
104
105   QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup );
106   aStartButton->setAutoDefault( true );
107   aStartButton->setDefault( true );
108   CommonGroupLayout->addWidget( aStartButton, 0, 0 );
109   CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
110
111   QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
112   aCloseButton->setAutoDefault( true );
113   CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
114
115   //QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
116   //aHelpButton->setAutoDefault( true );
117   //CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
118
119   aTopLayout->addWidget( CommonGroup );
120
121   connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
122   connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
123   //connect( aHelpButton,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
124 }
125
126 SVTK_RecorderDlg::~SVTK_RecorderDlg()
127 {
128 }
129
130 void SVTK_RecorderDlg::onStart()
131 {
132   if( myFileName.isNull() )
133     return;
134
135   myRecorder->SetName( (const char*)myFileName.toUtf8() );
136
137   myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentIndex() == 0 );
138   myRecorder->SetNbFPS( myFPSSpinBox->value() );
139   myRecorder->SetQuality( myQualitySpinBox->value() );
140   myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() );
141
142   accept();
143
144 }
145
146 void SVTK_RecorderDlg::onClose()
147 {
148   reject();
149 }
150
151 void SVTK_RecorderDlg::onHelp()
152 {
153   /*
154   QString aHelpFileName = "animation_in_gauss_viewer.htm";
155   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
156   if (app)
157     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
158   else {
159                 QString platform;
160 #ifdef WIN32
161                 platform = "winapplication";
162 #else
163                 platform = "application";
164 #endif
165     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
166                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
167                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
168   }
169   */
170 }
171
172 bool SVTK_RecorderDlg::onBrowseFile()
173 {
174   QStringList aFilter;
175   aFilter.append( tr( "FLT_AVI_FILES" ) );
176   aFilter.append( tr( "FLT_ALL_FILES" ) );
177
178   QString aFileName = SUIT_FileDlg::getFileName( this, Qtx::getenv( "HOME" ), aFilter,
179                                                  tr( "FILE_NAME" ), false );
180
181   if( aFileName.isNull() )
182     return false;
183
184   myFileName = aFileName;
185   myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
186
187   return true;
188 }
189
190 int SVTK_RecorderDlg::exec()
191 {
192   if( !onBrowseFile() )
193   {
194     reject();
195     return 0;
196   }
197   return QDialog::exec();
198 }
199
200 void SVTK_RecorderDlg::keyPressEvent( QKeyEvent* e )
201 {
202   QDialog::keyPressEvent( e );
203   if ( e->isAccepted() )
204     return;
205
206   if ( e->key() == Qt::Key_F1 )
207     {
208       e->accept();
209       onHelp();
210     }
211 }