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

Last change on this file since 755 was 755, checked in by garnier, 17 years ago

corrections pour Qt3 mises sous cvs

  • Property svn:mime-type set to text/cpp
File size: 17.3 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//
[755]27// $Id: G4OpenGLQtMovieDialog.cc,v 1.5 2008/03/11 17:35:11 lgarnier Exp $
[730]28// GEANT4 tag $Name:  $
29//
30//
31
[754]32//#define GEANT4_QT_DEBUG
[730]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{
[754]72#if QT_VERSION > 0x030200
[730]73  setModal(false);
[754]74#endif
[730]75#if QT_VERSION < 0x040000
76  setCaption( tr( " Movie parameters" ));
77#else
78  setWindowTitle( tr( " Movie parameters" ));
79#endif
80
81
82  // global layout
83  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
84  globalVLayout->setMargin(10);
85  globalVLayout->setSpacing(10);
86 
[733]87  // Encoder group box
[755]88  QGroupBox *encoderGroupBox = new QGroupBox(tr("Encoder path"),this);         
[734]89  QVBoxLayout *encoderVGroupBoxLayout = new QVBoxLayout(encoderGroupBox);
[730]90
[732]91  // Encoder Path
[733]92  QWidget *encoderHBox = new QWidget(encoderGroupBox);
93  QHBoxLayout *encoderHBoxLayout = new QHBoxLayout(encoderHBox);
94  fEncoderPath = new QLineEdit("",encoderHBox);
[730]95
[733]96  QPushButton *encoderButton = new QPushButton(tr("..."),encoderHBox);
[732]97  encoderButton->setMaximumWidth (30);
[730]98
[733]99  fEncoderStatus = new QLabel(encoderGroupBox);
[754]100
101#if QT_VERSION > 0x040000
[748]102  fEncoderStatus->setWordWrap(true);
[755]103  encoderVGroupBoxLayout->setMargin(15);
[754]104#else
105  fEncoderStatus->setAlignment ( Qt::AlignAuto |Qt::WordBreak );
[755]106  encoderGroupBox->setInsideMargin(15);
[754]107#endif
108
[733]109  fEncoderStatus->setText("");
110
[732]111#if QT_VERSION < 0x040000
[733]112  encoderHBoxLayout->add(fEncoderPath);
113  encoderHBoxLayout->add(encoderButton);
[734]114  encoderVGroupBoxLayout->add(encoderHBox);
115  encoderVGroupBoxLayout->add(fEncoderStatus);
[735]116
117  globalVLayout->add(encoderGroupBox);
[732]118#else
[733]119  encoderHBoxLayout->addWidget(fEncoderPath);
120  encoderHBoxLayout->addWidget(encoderButton);
[734]121  encoderVGroupBoxLayout->addWidget(encoderHBox);
122  encoderVGroupBoxLayout->addWidget(fEncoderStatus);
[730]123
[734]124  encoderGroupBox->setLayout(encoderVGroupBoxLayout);
[735]125  globalVLayout->addWidget(encoderGroupBox);
[732]126#endif
[735]127
[733]128  connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
[732]129
[730]130
[733]131  // temp folder group box
[755]132  QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"),this);
[734]133  QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
[733]134
[732]135  // temp folder Path
[733]136  QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
[734]137  QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
[732]138
[733]139  fTempFolderPath = new QLineEdit("",tempFolderHBox);
140
141  QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
142  tempButton->setMaximumWidth (30);
143
144  fTempFolderStatus = new QLabel(tempFolderGroupBox);
[754]145#if QT_VERSION > 0x040000
[748]146  fTempFolderStatus->setWordWrap(true);
[755]147  tempFolderVGroupBoxLayout->setMargin(15);
[754]148#else
149  fTempFolderStatus->setAlignment ( Qt::AlignAuto |Qt::WordBreak );
[755]150  tempFolderGroupBox->setInsideMargin(15);
[754]151#endif
[733]152  fTempFolderStatus->setText("");
153
[730]154#if QT_VERSION < 0x040000
[733]155  tempFolderHBoxLayout->add(fTempFolderPath);
156  tempFolderHBoxLayout->add(tempButton);
[734]157  tempFolderVGroupBoxLayout->add(tempFolderHBox);
158  tempFolderVGroupBoxLayout->add(fTempFolderStatus);
[735]159
160  globalVLayout->add(tempFolderGroupBox);
[730]161#else
[733]162  tempFolderHBoxLayout->addWidget(fTempFolderPath);
163  tempFolderHBoxLayout->addWidget(tempButton);
[734]164  tempFolderVGroupBoxLayout->addWidget(tempFolderHBox);
165  tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus);
[730]166
[734]167  tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout);
[735]168  globalVLayout->addWidget(tempFolderGroupBox);
[733]169#endif
[735]170
[733]171  connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) );
[732]172
[733]173
[734]174
175
[733]176  // save file group box
[755]177  QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"),this);
[734]178  QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
[733]179
180  // save file
181  QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
182  QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
183
184  fSaveFileName = new QLineEdit("",saveFileHBox);
185
186  QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
187  saveButton->setMaximumWidth (30);
188
189  fSaveFileStatus = new QLabel(saveFileGroupBox);
[754]190#if QT_VERSION > 0x040000
[748]191  fSaveFileStatus->setWordWrap(true);
[755]192  saveFileVGroupBoxLayout->setMargin(15);
[754]193#else
194  fSaveFileStatus->setAlignment ( Qt::AlignAuto |Qt::WordBreak );
[755]195  saveFileGroupBox->setInsideMargin(15);
[754]196#endif
[733]197  fSaveFileStatus->setText("");
198
199#if QT_VERSION < 0x040000
[734]200  saveFileHBoxLayout->add(fSaveFileName);
[733]201  saveFileHBoxLayout->add(saveButton);
[734]202  saveFileVGroupBoxLayout->add(saveFileHBox);
203  saveFileVGroupBoxLayout->add(fSaveFileStatus);
[735]204
205  globalVLayout->add(saveFileGroupBox);
[733]206#else
[734]207  saveFileHBoxLayout->addWidget(fSaveFileName);
[733]208  saveFileHBoxLayout->addWidget(saveButton);
[734]209  saveFileVGroupBoxLayout->addWidget(saveFileHBox);
210  saveFileVGroupBoxLayout->addWidget(fSaveFileStatus);
[733]211
[734]212  saveFileGroupBox->setLayout(saveFileVGroupBoxLayout);
[735]213  globalVLayout->addWidget(saveFileGroupBox);
[730]214#endif
[735]215
[733]216  connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) );
[730]217
218
219
[732]220  // label
221
[754]222  QLabel *infoLabel = new QLabel("  Press SPACE to Start/Pause video recording \n  Press RETURN to Stop video recording",this);
[730]223
[733]224  // global status
[755]225  QGroupBox *statusGroupBox = new QGroupBox(tr("Status"),this);
[735]226  QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox);
[733]227
[744]228  fRecordingStatus = new QLabel(statusGroupBox);
[754]229#if QT_VERSION > 0x040000
[755]230  statusVGroupBoxLayout->setMargin(15);
[748]231  fRecordingStatus->setWordWrap(true);
[754]232#else
[755]233  statusGroupBox->setInsideMargin(15);
[754]234  fRecordingStatus->setAlignment ( Qt::AlignAuto |Qt::WordBreak );
235#endif
[744]236  QPalette palette( fRecordingStatus->palette() );
[754]237#if QT_VERSION > 0x040000
[744]238  palette.setColor( QPalette::Text, Qt::green);
[754]239#else
240  palette.setColor( QColorGroup::Text, Qt::green);
241#endif
[744]242  fRecordingStatus->setPalette(palette);
243
244  fRecordingInfos = new QLabel(statusGroupBox);
[754]245#if QT_VERSION > 0x040000
[748]246  fRecordingInfos->setWordWrap(true);
[754]247#else
248  fRecordingInfos->setAlignment ( Qt::AlignAuto |Qt::WordBreak );
249#endif
[744]250  setRecordingInfos("");
251
[730]252#if QT_VERSION < 0x040000
[744]253  statusVGroupBoxLayout->add(fRecordingStatus);
254  statusVGroupBoxLayout->add(fRecordingInfos);
[735]255
[730]256  globalVLayout->add(infoLabel);
[735]257  globalVLayout->add(statusGroupBox);
[730]258#else
[744]259  statusVGroupBoxLayout->addWidget(fRecordingStatus);
260  statusVGroupBoxLayout->addWidget(fRecordingInfos);
[735]261
262  statusGroupBox->setLayout(statusVGroupBoxLayout);
[730]263  globalVLayout->addWidget(infoLabel);
[735]264  globalVLayout->addWidget(statusGroupBox);
[730]265#endif
[732]266
267  // buttons
[730]268  QWidget *buttonBox = new QWidget(this);
269
270  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
271
[732]272  QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
273  buttonCancel->setAutoDefault( TRUE );
274  buttonBoxLayout->addWidget(buttonCancel);
[730]275
[750]276  QPushButton *buttonReset = new QPushButton( tr( "&Reset" ),buttonBox );
277  buttonReset->setAutoDefault( TRUE );
278  buttonBoxLayout->addWidget(buttonReset);
[733]279
[750]280  fButtonApply = new QPushButton( tr( "&Apply" ),buttonBox );
281  fButtonApply->setAutoDefault( TRUE );
[751]282  enabledApplyButton();
[750]283  buttonBoxLayout->addWidget(fButtonApply);
284
[739]285  fButtonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
[745]286  fButtonEncode->setEnabled(fParentViewer->isReadyToEncode());
[739]287  fButtonEncode->setAutoDefault( TRUE );
288  buttonBoxLayout->addWidget(fButtonEncode);
[730]289
290#if QT_VERSION >= 0x040000
291  buttonBox->setLayout(buttonBoxLayout);
292#endif
293  globalVLayout->addWidget(buttonBox);
294
295
296
297#if QT_VERSION >= 0x040000
298  setLayout(globalVLayout);
299#endif
300
301  // signals and slots connections
[750]302  connect( fButtonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) );
303  connect( buttonReset, SIGNAL( clicked() ), this, SLOT( resetRecording() ) );
[730]304  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
[739]305  connect( fButtonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
[737]306
307  // fill
[748]308  setRecordingStatus("");
[737]309  fEncoderPath->setText(fParentViewer->getEncoderPath());
310  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
311
[750]312  // connect line edit signals
[755]313  connect (fEncoderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(enabledApplyButton()));
314  connect (fTempFolderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(enabledApplyButton()));
315  connect (fSaveFileName,SIGNAL(textChanged ( const QString&)),this,SLOT(enabledApplyButton()));
[750]316
[755]317#if QT_VERSION >= 0x040000
[751]318  connect (fEncoderPath,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
319  connect (fTempFolderPath,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
320  connect (fSaveFileName,SIGNAL(editingFinished ()),this,SLOT(checkAllParameters()));
[755]321#else
322  connect (fEncoderPath,SIGNAL(lostFocus ()),this,SLOT(checkAllParameters()));
323  connect (fTempFolderPath,SIGNAL(lostFocus ()),this,SLOT(checkAllParameters()));
324  connect (fSaveFileName,SIGNAL(lostFocus ()),this,SLOT(checkAllParameters()));
325#endif
[751]326
[737]327  if (fParentViewer->getEncoderPath() == "") {
[748]328    setRecordingInfos("mpeg_encode is needed to encode in video format. It is available here: http://bmrc.berkeley.edu/frame/research/mpeg/");
[737]329  }
[752]330 
331  checkAllParameters();
[730]332}
333
334
335
336G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
337{
338}
339
[733]340void G4OpenGLQtMovieDialog::selectEncoderPathAction()
[730]341{
[754]342#if QT_VERSION < 0x040000
343  QString nomFich =  QFileDialog::getOpenFileName ( ".",
344                                                    NULL,
345                                                    this,
346                                                    "Select your encoder",
347                                                    tr("Select your encoder ..."));
348#else
[730]349  QString nomFich =  QFileDialog::getOpenFileName ( this,
350                                                    "Select your encoder",
351                                                    tr("Select your encoder ..."));
[754]352
353#endif
354
[730]355  if (nomFich == "") {
356    return;
357  }
[750]358  fEncoderPath->setText(nomFich);
359  checkAllParameters();
[733]360 }
361
[750]362
[733]363void G4OpenGLQtMovieDialog::selectTempPathAction()
364{
[754]365#if QT_VERSION < 0x040000
[755]366  QString nomFich =  QFileDialog::getExistingDirectory (NULL,
[754]367                                                    this,
368                                                    "Select temporary folder",
369                                                    tr("Select temporary folder ..."));
370#else
[755]371  QString nomFich =  QFileDialog::getExistingDirectory ( this,
[733]372                                                    "Select temporary folder",
373                                                    tr("Select temporary folder ..."));
[754]374
375#endif
[733]376  if (nomFich == "") {
377    return;
378  }
[750]379  fTempFolderPath->setText(nomFich);
380  checkAllParameters();
[733]381 }
382
[750]383
[733]384void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
385{
[754]386#if QT_VERSION < 0x040000
387  QString nomFich =  QFileDialog::getSaveFileName ( ".",
388                                                    NULL,
389                                                    this,
390                                                    "Select saved file",
391                                                    tr("Select saved file ..."));
392#else
[742]393  QString nomFich =  QFileDialog::getSaveFileName ( this,
[733]394                                                    "Select saved file",
395                                                    tr("Select saved file ..."));
[754]396
397#endif
[733]398  if (nomFich == "") {
399    return;
400  }
[750]401  fSaveFileName->setText(nomFich);
402  checkAllParameters();
[733]403 }
404
[750]405
[733]406void G4OpenGLQtMovieDialog::encode() {
[744]407  fParentViewer->encodeVideo();
[730]408}
409
[733]410/** Check all parameters
411*/
412void G4OpenGLQtMovieDialog::checkAllParameters() {
[740]413
414  // set state of encode button
415  // if frames had been generated and parameters are valid : enabled encode button
[748]416  bool status = checkEncoderParameters(fEncoderPath->text())
417              & checkTempFolderParameters(fTempFolderPath->text())
418              & checkSaveFileNameParameters(fSaveFileName->text());
419  if (status) {
420    if (fParentViewer->isStopped()) {
[747]421      if (fParentViewer->generateMpegEncoderParameters()) {
[748]422        fButtonEncode->setEnabled(fParentViewer->isReadyToEncode() );
423      }
424    }
[747]425  }
[750]426  fButtonApply->setEnabled(false);
[733]427}
428
[747]429
[733]430        /**
[732]431 * If one of parameter is incorrect, put it in red and don't valid it
[733]432 * If valid, save it
[732]433 */
[747]434bool G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) {
[730]435
[747]436  bool status = true;
[732]437  QPalette palette( fEncoderPath->palette() );
438
[733]439  QString temp = fParentViewer->setEncoderPath(param);
[744]440  setRecordingInfos("");
[740]441  fEncoderStatus->setText(temp);
[733]442  if (temp != "") {
[754]443#if QT_VERSION > 0x040000
[732]444    palette.setColor( QPalette::Base, Qt::red);
[754]445#else
446    palette.setColor( QColorGroup::Base, Qt::red);
447#endif
[746]448    if (fParentViewer->isReadyToEncode()) {
[748]449      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]450        }
451    status = false;
[732]452  } else {
[754]453#if QT_VERSION > 0x040000
[732]454    palette.setColor( QPalette::Base, Qt::white);
[754]455#else
456    palette.setColor( QColorGroup::Base, Qt::white);
457#endif
[733]458    fEncoderPath->setText(fParentViewer->getEncoderPath());
[732]459  }
460  fEncoderPath->setPalette(palette);
[747]461  return status;
[733]462}
[732]463
464
[733]465/**
466 * If one of parameter is incorrect, put it in red and don't valid it
467 * If valid, save it
468 */
[747]469bool G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) {
[732]470
[747]471  bool status = true;
[733]472  QPalette palette( fTempFolderPath->palette() );
473
474  QString temp = fParentViewer->setTempFolderPath(param);
[736]475  fTempFolderStatus->setText(temp);
476  if (temp != "") {
[754]477#if QT_VERSION > 0x040000
[732]478    palette.setColor( QPalette::Base, Qt::red);
[754]479#else
480    palette.setColor( QColorGroup::Base, Qt::red);
481#endif
[747]482    status = false;
[732]483  } else {
[754]484#if QT_VERSION > 0x040000
[732]485    palette.setColor( QPalette::Base, Qt::white);
[754]486#else
487    palette.setColor( QColorGroup::Base, Qt::white);
488#endif
[736]489    fTempFolderPath->setText(fParentViewer->getTempFolderPath());
[732]490  }
[733]491  fTempFolderPath->setPalette(palette);
[747]492  return status;
[732]493}
494
[733]495
496/**
497 * If one of parameter is incorrect, put it in red and don't valid it
498 * If valid, save it
499 */
[747]500bool G4OpenGLQtMovieDialog::checkSaveFileNameParameters(QString param) {
[733]501
[747]502  bool status = true;
[733]503  QPalette palette( fSaveFileName->palette() );
504
505  QString temp = fParentViewer->setSaveFileName(param);
[750]506  fSaveFileStatus->setText(temp);
[733]507  if (temp != "") {
[754]508#if QT_VERSION > 0x040000
[733]509    palette.setColor( QPalette::Base, Qt::red);
[754]510#else
511    palette.setColor( QColorGroup::Base, Qt::red);
512#endif
[747]513    status = false;
[733]514  } else {
[754]515#if QT_VERSION > 0x040000
[733]516    palette.setColor( QPalette::Base, Qt::white);
[754]517#else
518    palette.setColor( QColorGroup::Base, Qt::white);
519#endif
[733]520    fSaveFileName->setText(fParentViewer->getSaveFileName());
521  }
522  fSaveFileName->setPalette(palette);
[747]523  return status;
[733]524}
[737]525
526
[750]527void G4OpenGLQtMovieDialog::resetRecording() {
528  fParentViewer->resetRecording();
529}
530
531
[744]532void G4OpenGLQtMovieDialog::setRecordingStatus(QString txt) {
[748]533  fButtonEncode->setEnabled(fParentViewer->isReadyToEncode());
[744]534  fRecordingStatus->setText(txt);
[737]535}
536
[750]537
[744]538void G4OpenGLQtMovieDialog::setRecordingInfos(QString txt) {
539  fRecordingInfos->setText(txt);
540}
541
[751]542
543void G4OpenGLQtMovieDialog::enabledApplyButton() {
544  fButtonApply->setEnabled(true);
545}
546
[730]547#endif
Note: See TracBrowser for help on using the repository browser.