Salome HOME
d01dbe362c53b3fb957a9771e8cb06b3a4866967
[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 <QtxDoubleSpinBox.h>
29 #include <QtxIntSpinBox.h>
30
31 #include <QCheckBox>
32 #include <QComboBox>
33 #include <QGroupBox>
34 #include <QKeyEvent>
35 #include <QLabel>
36 #include <QLayout>
37 #include <QLineEdit>
38 #include <QPushButton>
39
40 /*!
41  * Constructor
42  */
43 SVTK_RecorderDlg::SVTK_RecorderDlg( QWidget* theParent, SVTK_Recorder* theRecorder ):
44   QDialog( theParent ),
45   myRecorder( theRecorder )
46 {
47   setWindowTitle( tr( "DLG_RECORDER_TITLE" ) );
48
49   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
50
51   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
52   aTopLayout->setSpacing( 6 );
53   aTopLayout->setMargin( 6 );
54
55   // Settings
56   QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this );
57
58   QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox );
59   aSettingsLayout->setSpacing( 6 );
60   aSettingsLayout->setMargin( 11 );
61
62   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
63   myFileNameLineEdit = new QLineEdit( mySettingsBox );
64   myFileNameLineEdit->setMinimumWidth( 250 );
65   myFileNameLineEdit->setReadOnly( true );
66
67   QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox );
68   myRecordingModeComboBox = new QComboBox( mySettingsBox );
69   myRecordingModeComboBox->addItem( tr( "SKIPPED_FRAMES" ) );
70   myRecordingModeComboBox->addItem( tr( "ALL_DISLPAYED_FRAMES" ) );
71   myRecordingModeComboBox->setCurrentIndex( aResourceMgr->integerValue( "VTKViewer", "recorder_mode", 1 ) );
72
73   QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox );
74   myFPSSpinBox = new QtxDoubleSpinBox( 0.1, 100.0, 1.0, mySettingsBox );
75   myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VTKViewer", "recorder_fps", 10.0 ) );
76
77   QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox );
78   myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox );
79   myQualitySpinBox->setValue( aResourceMgr->integerValue( "VTKViewer", "recorder_quality", 80 ) );
80
81   myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox );
82   myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VTKViewer", "recorder_progressive", false ) );
83
84   aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
85   aSettingsLayout->addWidget( myFileNameLineEdit, 1, 0, 1, 2 );
86   aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 );
87   aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 );
88   aSettingsLayout->addWidget( aFPSLabel, 3, 0 );
89   aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 );
90   aSettingsLayout->addWidget( aQualityLabel, 4, 0 );
91   aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 );
92   aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 );
93
94   aTopLayout->addWidget( mySettingsBox );
95
96   // Start / Close
97   QGroupBox* CommonGroup = new QGroupBox( this );
98   QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup );
99   CommonGroupLayout->setAlignment( Qt::AlignTop );
100   CommonGroupLayout->setSpacing( 6 );
101   CommonGroupLayout->setMargin( 11 );
102
103   QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup );
104   aStartButton->setAutoDefault( true );
105   aStartButton->setDefault( true );
106   CommonGroupLayout->addWidget( aStartButton, 0, 0 );
107   CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
108
109   QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
110   aCloseButton->setAutoDefault( true );
111   CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
112
113   //QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
114   //aHelpButton->setAutoDefault( true );
115   //CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
116
117   aTopLayout->addWidget( CommonGroup );
118
119   connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
120   connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
121   //connect( aHelpButton,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
122 }
123
124 SVTK_RecorderDlg::~SVTK_RecorderDlg()
125 {
126 }
127
128 void SVTK_RecorderDlg::onStart()
129 {
130   if( myFileName.isNull() )
131     return;
132
133   myRecorder->SetName( (const char*)myFileName.toUtf8() );
134
135   myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentIndex() == 0 );
136   myRecorder->SetNbFPS( myFPSSpinBox->value() );
137   myRecorder->SetQuality( myQualitySpinBox->value() );
138   myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() );
139
140   accept();
141
142 }
143
144 void SVTK_RecorderDlg::onClose()
145 {
146   reject();
147 }
148
149 void SVTK_RecorderDlg::onHelp()
150 {
151   /*
152   QString aHelpFileName = "animation_in_gauss_viewer.htm";
153   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
154   if (app)
155     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
156   else {
157                 QString platform;
158 #ifdef WIN32
159                 platform = "winapplication";
160 #else
161                 platform = "application";
162 #endif
163     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
164                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
165                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
166   }
167   */
168 }
169
170 bool SVTK_RecorderDlg::onBrowseFile()
171 {
172   QStringList aFilter;
173   aFilter.append( tr( "FLT_AVI_FILES" ) );
174   aFilter.append( tr( "FLT_ALL_FILES" ) );
175
176   QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter,
177                                                  tr( "FILE_NAME" ), false );
178
179   if( aFileName.isNull() )
180     return false;
181
182   myFileName = aFileName;
183   myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
184
185   return true;
186 }
187
188 int SVTK_RecorderDlg::exec()
189 {
190   if( !onBrowseFile() )
191   {
192     reject();
193     return 0;
194   }
195   return QDialog::exec();
196 }
197
198 void SVTK_RecorderDlg::keyPressEvent( QKeyEvent* e )
199 {
200   QDialog::keyPressEvent( e );
201   if ( e->isAccepted() )
202     return;
203
204   if ( e->key() == Qt::Key_F1 )
205     {
206       e->accept();
207       onHelp();
208     }
209 }