source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtMovieDialog.cc @ 751

Last change on this file since 751 was 751, checked in by garnier, 16 years ago

corrections sur le removeTempFolder et autres

  • Property svn:mime-type set to text/cpp
File size: 14.5 KB
RevLine 
[730]1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLQtMovieDialog.cc,v 1.6 2008/02/15 10:54:13 lgarnier Exp $
28// GEANT4 tag $Name:  $
29//
30//
31
32#define GEANT4_QT_DEBUG
33#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
34
35#include "G4OpenGLQtMovieDialog.hh"
36#include "G4OpenGLQtViewer.hh"
37
38#include <qpushbutton.h>
[732]39#include <qpalette.h>
[730]40#include <qlabel.h>
[733]41#include <qgroupbox.h>
[730]42#include <qlayout.h>
43#include <qlineedit.h>
44#include <qfiledialog.h>
45#include <qprocess.h>
46
47
48// +---------------------------------------+
49// +        Path for encoder               +
50// +  _______                              +
51// + | select| ____________________        +
52// +  -------                              +
[732]53// +        Temp path                      +
54// +  _______                              +
55// + | select| ____________________        +
56// +  -------                              +
[730]57// +                                       +
58// + max number of frames  ________        +
59// + ....                                  +
60// +                                       +
61// +     Label : X frames Saves/Encoding   +
62// +         Cancel        Encode          +
63// +---------------------------------------+
64
65G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
[731]66 G4OpenGLQtViewer* parentViewer,
67 QWidget* parentWidget
[730]68)
[731]69  : QDialog( parentWidget ),
70    fParentViewer(parentViewer)
[730]71{
72  setModal(false);
73#if QT_VERSION < 0x040000
74  setCaption( tr( " Movie parameters" ));
75#else
76  setWindowTitle( tr( " Movie parameters" ));
77#endif
78
79
80  // global layout
81  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
82  globalVLayout->setMargin(10);
83  globalVLayout->setSpacing(10);
84 
[733]85  // Encoder group box
86  QGroupBox *encoderGroupBox = new QGroupBox(tr("Encoder path"));               
[734]87  QVBoxLayout *encoderVGroupBoxLayout = new QVBoxLayout(encoderGroupBox);
[730]88
[732]89  // Encoder Path
[733]90  QWidget *encoderHBox = new QWidget(encoderGroupBox);
91  QHBoxLayout *encoderHBoxLayout = new QHBoxLayout(encoderHBox);
92  fEncoderPath = new QLineEdit("",encoderHBox);
[730]93
[733]94  QPushButton *encoderButton = new QPushButton(tr("..."),encoderHBox);
[732]95  encoderButton->setMaximumWidth (30);
[730]96
[733]97  fEncoderStatus = new QLabel(encoderGroupBox);
[748]98  fEncoderStatus->setWordWrap(true);
[733]99  fEncoderStatus->setText("");
100
[732]101#if QT_VERSION < 0x040000
[733]102  encoderHBoxLayout->add(fEncoderPath);
103  encoderHBoxLayout->add(encoderButton);
[734]104  encoderVGroupBoxLayout->add(encoderHBox);
105  encoderVGroupBoxLayout->add(fEncoderStatus);
[735]106
107  globalVLayout->add(encoderGroupBox);
[732]108#else
[733]109  encoderHBoxLayout->addWidget(fEncoderPath);
110  encoderHBoxLayout->addWidget(encoderButton);
[734]111  encoderVGroupBoxLayout->addWidget(encoderHBox);
112  encoderVGroupBoxLayout->addWidget(fEncoderStatus);
[730]113
[734]114  encoderGroupBox->setLayout(encoderVGroupBoxLayout);
[735]115  globalVLayout->addWidget(encoderGroupBox);
[732]116#endif
[735]117
[733]118  connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
[732]119
[730]120
[733]121  // temp folder group box
122  QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"));           
[734]123  QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
[733]124
[732]125  // temp folder Path
[733]126  QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
[734]127  QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
[732]128
[733]129  fTempFolderPath = new QLineEdit("",tempFolderHBox);
130
131  QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
132  tempButton->setMaximumWidth (30);
133
134  fTempFolderStatus = new QLabel(tempFolderGroupBox);
[748]135  fTempFolderStatus->setWordWrap(true);
[733]136  fTempFolderStatus->setText("");
137
[730]138#if QT_VERSION < 0x040000
[733]139  tempFolderHBoxLayout->add(fTempFolderPath);
140  tempFolderHBoxLayout->add(tempButton);
[734]141  tempFolderVGroupBoxLayout->add(tempFolderHBox);
142  tempFolderVGroupBoxLayout->add(fTempFolderStatus);
[735]143
144  globalVLayout->add(tempFolderGroupBox);
[730]145#else
[733]146  tempFolderHBoxLayout->addWidget(fTempFolderPath);
147  tempFolderHBoxLayout->addWidget(tempButton);
[734]148  tempFolderVGroupBoxLayout->addWidget(tempFolderHBox);
149  tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus);
[730]150
[734]151  tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout);
[735]152  globalVLayout->addWidget(tempFolderGroupBox);
[733]153#endif
[735]154
[733]155  connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) );
[732]156
[733]157
[734]158
159
[733]160  // save file group box
161  QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"));           
[734]162  QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
[733]163
164  // save file
165  QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
166  QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
167
168  fSaveFileName = new QLineEdit("",saveFileHBox);
169
170  QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
171  saveButton->setMaximumWidth (30);
172
173  fSaveFileStatus = new QLabel(saveFileGroupBox);
[748]174  fSaveFileStatus->setWordWrap(true);
[733]175  fSaveFileStatus->setText("");
176
177#if QT_VERSION < 0x040000
[734]178  saveFileHBoxLayout->add(fSaveFileName);
[733]179  saveFileHBoxLayout->add(saveButton);
[734]180  saveFileVGroupBoxLayout->add(saveFileHBox);
181  saveFileVGroupBoxLayout->add(fSaveFileStatus);
[735]182
183  globalVLayout->add(saveFileGroupBox);
[733]184#else
[734]185  saveFileHBoxLayout->addWidget(fSaveFileName);
[733]186  saveFileHBoxLayout->addWidget(saveButton);
[734]187  saveFileVGroupBoxLayout->addWidget(saveFileHBox);
188  saveFileVGroupBoxLayout->addWidget(fSaveFileStatus);
[733]189
[734]190  saveFileGroupBox->setLayout(saveFileVGroupBoxLayout);
[735]191  globalVLayout->addWidget(saveFileGroupBox);
[730]192#endif
[735]193
[733]194  connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) );
[730]195
196
197
[732]198  // label
199
[730]200  QLabel *infoLabel = new QLabel("  Press SPACE to Start/Pause video recording \n  Press RETURN to Stop video recording");
201
[733]202  // global status
[735]203  QGroupBox *statusGroupBox = new QGroupBox(tr("Status"));
204  QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox);
[733]205
[744]206  fRecordingStatus = new QLabel(statusGroupBox);
[748]207  fRecordingStatus->setWordWrap(true);
[744]208  QPalette palette( fRecordingStatus->palette() );
209  palette.setColor( QPalette::Text, Qt::green);
210  fRecordingStatus->setPalette(palette);
211
212  fRecordingInfos = new QLabel(statusGroupBox);
[748]213  fRecordingInfos->setWordWrap(true);
[744]214  setRecordingInfos("");
215
[730]216#if QT_VERSION < 0x040000
[744]217  statusVGroupBoxLayout->add(fRecordingStatus);
218  statusVGroupBoxLayout->add(fRecordingInfos);
[735]219
[730]220  globalVLayout->add(infoLabel);
[735]221  globalVLayout->add(statusGroupBox);
[730]222#else
[744]223  statusVGroupBoxLayout->addWidget(fRecordingStatus);
224  statusVGroupBoxLayout->addWidget(fRecordingInfos);
[735]225
226  statusGroupBox->setLayout(statusVGroupBoxLayout);
[730]227  globalVLayout->addWidget(infoLabel);
[735]228  globalVLayout->addWidget(statusGroupBox);
[730]229#endif
[732]230
231  // buttons
[730]232  QWidget *buttonBox = new QWidget(this);
233
234  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
235
[732]236  QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
237  buttonCancel->setAutoDefault( TRUE );
238  buttonBoxLayout->addWidget(buttonCancel);
[730]239
[750]240  QPushButton *buttonReset = new QPushButton( tr( "&Reset" ),buttonBox );
241  buttonReset->setAutoDefault( TRUE );
242  buttonBoxLayout->addWidget(buttonReset);
[733]243
[750]244  fButtonApply = new QPushButton( tr( "&Apply" ),buttonBox );
245  fButtonApply->setAutoDefault( TRUE );
[751]246  enabledApplyButton();
[750]247  buttonBoxLayout->addWidget(fButtonApply);
248
[739]249  fButtonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
[745]250  fButtonEncode->setEnabled(fParentViewer->isReadyToEncode());
[739]251  fButtonEncode->setAutoDefault( TRUE );
252  buttonBoxLayout->addWidget(fButtonEncode);
[730]253
254#if QT_VERSION >= 0x040000
255  buttonBox->setLayout(buttonBoxLayout);
256#endif
257  globalVLayout->addWidget(buttonBox);
258
259
260
261#if QT_VERSION >= 0x040000
262  setLayout(globalVLayout);
263#endif
264
265  // signals and slots connections
[750]266  connect( fButtonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) );
267  connect( buttonReset, SIGNAL( clicked() ), this, SLOT( resetRecording() ) );
[730]268  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
[739]269  connect( fButtonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
[737]270
271  // fill
[748]272  setRecordingStatus("");
[737]273  fEncoderPath->setText(fParentViewer->getEncoderPath());
274  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
275
[750]276  // connect line edit signals
[751]277  connect (fEncoderPath,SIGNAL(textEdited ( const QString&)),this,SLOT(enabledApplyButton()));
278  connect (fTempFolderPath,SIGNAL(textEdited ( const QString&)),this,SLOT(enabledApplyButton()));
279  connect (fSaveFileName,SIGNAL(textEdited ( const QString&)),this,SLOT(enabledApplyButton()));
[750]280
[751]281  connect (fEncoderPath,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
282  connect (fTempFolderPath,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
283  connect (fSaveFileName,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
284
[737]285  if (fParentViewer->getEncoderPath() == "") {
[748]286    setRecordingInfos("mpeg_encode is needed to encode in video format. It is available here: http://bmrc.berkeley.edu/frame/research/mpeg/");
[737]287  }
288
[730]289}
290
291
292
293G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
294{
295}
296
[733]297void G4OpenGLQtMovieDialog::selectEncoderPathAction()
[730]298{
299  QString nomFich =  QFileDialog::getOpenFileName ( this,
300                                                    "Select your encoder",
301                                                    tr("Select your encoder ..."));
302  if (nomFich == "") {
303    return;
304  }
[750]305  fEncoderPath->setText(nomFich);
306  checkAllParameters();
[733]307 }
308
[750]309
[733]310void G4OpenGLQtMovieDialog::selectTempPathAction()
311{
312  QString nomFich =  QFileDialog::getOpenFileName ( this,
313                                                    "Select temporary folder",
314                                                    tr("Select temporary folder ..."));
315  if (nomFich == "") {
316    return;
317  }
[750]318  fTempFolderPath->setText(nomFich);
319  checkAllParameters();
[733]320 }
321
[750]322
[733]323void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
324{
[742]325  QString nomFich =  QFileDialog::getSaveFileName ( this,
[733]326                                                    "Select saved file",
327                                                    tr("Select saved file ..."));
328  if (nomFich == "") {
329    return;
330  }
[750]331  fSaveFileName->setText(nomFich);
332  checkAllParameters();
[733]333 }
334
[750]335
[733]336void G4OpenGLQtMovieDialog::encode() {
[744]337  fParentViewer->encodeVideo();
[730]338}
339
[733]340/** Check all parameters
341*/
342void G4OpenGLQtMovieDialog::checkAllParameters() {
[740]343
344  // set state of encode button
345  // if frames had been generated and parameters are valid : enabled encode button
[748]346  bool status = checkEncoderParameters(fEncoderPath->text())
347              & checkTempFolderParameters(fTempFolderPath->text())
348              & checkSaveFileNameParameters(fSaveFileName->text());
349  if (status) {
350    if (fParentViewer->isStopped()) {
[747]351      if (fParentViewer->generateMpegEncoderParameters()) {
[748]352        fButtonEncode->setEnabled(fParentViewer->isReadyToEncode() );
353      }
354    }
[747]355  }
[750]356  fButtonApply->setEnabled(false);
[733]357}
358
[747]359
[733]360        /**
[732]361 * If one of parameter is incorrect, put it in red and don't valid it
[733]362 * If valid, save it
[732]363 */
[747]364bool G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) {
[730]365
[747]366  bool status = true;
[732]367  QPalette palette( fEncoderPath->palette() );
368
[733]369  QString temp = fParentViewer->setEncoderPath(param);
[744]370  setRecordingInfos("");
[740]371  fEncoderStatus->setText(temp);
[733]372  if (temp != "") {
[732]373    palette.setColor( QPalette::Base, Qt::red);
[746]374    if (fParentViewer->isReadyToEncode()) {
[748]375      setRecordingInfos("No valid encode defined, screen capture had been saved in the temp folder in ppm format.\nPlease define a encoder and clic on Apply button");
[747]376        }
377    status = false;
[732]378  } else {
379    palette.setColor( QPalette::Base, Qt::white);
[733]380    fEncoderPath->setText(fParentViewer->getEncoderPath());
[732]381  }
382  fEncoderPath->setPalette(palette);
[747]383  return status;
[733]384}
[732]385
386
[733]387/**
388 * If one of parameter is incorrect, put it in red and don't valid it
389 * If valid, save it
390 */
[747]391bool G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) {
[732]392
[747]393  bool status = true;
[733]394  QPalette palette( fTempFolderPath->palette() );
395
396  QString temp = fParentViewer->setTempFolderPath(param);
[736]397  fTempFolderStatus->setText(temp);
398  if (temp != "") {
[732]399    palette.setColor( QPalette::Base, Qt::red);
[747]400    status = false;
[732]401  } else {
402    palette.setColor( QPalette::Base, Qt::white);
[736]403    fTempFolderPath->setText(fParentViewer->getTempFolderPath());
[732]404  }
[733]405  fTempFolderPath->setPalette(palette);
[747]406  return status;
[732]407}
408
[733]409
410/**
411 * If one of parameter is incorrect, put it in red and don't valid it
412 * If valid, save it
413 */
[747]414bool G4OpenGLQtMovieDialog::checkSaveFileNameParameters(QString param) {
[733]415
[747]416  bool status = true;
[733]417  QPalette palette( fSaveFileName->palette() );
418
419  QString temp = fParentViewer->setSaveFileName(param);
[750]420  fSaveFileStatus->setText(temp);
[733]421  if (temp != "") {
422    palette.setColor( QPalette::Base, Qt::red);
[747]423    status = false;
[733]424  } else {
425    palette.setColor( QPalette::Base, Qt::white);
426    fSaveFileName->setText(fParentViewer->getSaveFileName());
427  }
428  fSaveFileName->setPalette(palette);
[747]429  return status;
[733]430}
[737]431
432
[750]433void G4OpenGLQtMovieDialog::resetRecording() {
434  fParentViewer->resetRecording();
435}
436
437
[744]438void G4OpenGLQtMovieDialog::setRecordingStatus(QString txt) {
[748]439  fButtonEncode->setEnabled(fParentViewer->isReadyToEncode());
[744]440  fRecordingStatus->setText(txt);
[737]441}
442
[750]443
[744]444void G4OpenGLQtMovieDialog::setRecordingInfos(QString txt) {
445  fRecordingInfos->setText(txt);
446}
447
[751]448
449void G4OpenGLQtMovieDialog::enabledApplyButton() {
450  fButtonApply->setEnabled(true);
451}
452
[730]453#endif
Note: See TracBrowser for help on using the repository browser.