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