G4OpenGLQtMovieDialog.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 
00031 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
00032 
00033 #include "G4OpenGLQtViewer.hh" // should be first in case we include
00034                                // some boost SIGNAL/SLOT library
00035 #include "G4OpenGLQtMovieDialog.hh"
00036 
00037 #include <qpushbutton.h>
00038 #include <qpalette.h>
00039 #include <qlabel.h>
00040 #include <qgroupbox.h>
00041 #include <qlayout.h>
00042 #include <qlineedit.h>
00043 #include <qfiledialog.h>
00044 #include <qprocess.h>
00045 
00046 
00047 // +---------------------------------------+
00048 // +        Path for encoder               +
00049 // +  _______                              +
00050 // + | select| ____________________        +
00051 // +  -------                              +
00052 // +        Temp path                      +
00053 // +  _______                              +
00054 // + | select| ____________________        +
00055 // +  -------                              +
00056 // +                                       +
00057 // + max number of frames  ________        +
00058 // + ....                                  +
00059 // +                                       +
00060 // +     Label : X frames Saves/Encoding   +
00061 // +         Cancel        Encode          +
00062 // +---------------------------------------+
00063 
00064 G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
00065  G4OpenGLQtViewer* parentViewer,
00066  QWidget* parentw
00067 )
00068   : QDialog( parentw ),
00069     fParentViewer(parentViewer)
00070 {
00071   setModal(false);
00072   setWindowTitle( tr( " Movie parameters" ));
00073 
00074 
00075   // global layout
00076   QVBoxLayout* globalVLayout = new QVBoxLayout(this);
00077   globalVLayout->setMargin(10);
00078   globalVLayout->setSpacing(10);
00079   
00080   // Encoder group box
00081   QGroupBox *encoderGroupBox = new QGroupBox(tr("Encoder path"),this);          
00082   QVBoxLayout *encoderVGroupBoxLayout = new QVBoxLayout(encoderGroupBox);
00083 
00084   // Encoder Path 
00085   QWidget *encoderHBox = new QWidget(encoderGroupBox);
00086   QHBoxLayout *encoderHBoxLayout = new QHBoxLayout(encoderHBox);
00087   fEncoderPath = new QLineEdit("",encoderHBox);
00088 
00089   QPushButton *encoderButton = new QPushButton(tr("..."),encoderHBox);
00090   encoderButton->setMaximumWidth (30);
00091 
00092   fEncoderStatus = new QLabel(encoderGroupBox);
00093 
00094   fEncoderStatus->setWordWrap(true);
00095   encoderVGroupBoxLayout->setMargin(15);
00096 
00097   fEncoderStatus->setText("");
00098 
00099   encoderHBoxLayout->addWidget(fEncoderPath);
00100   encoderHBoxLayout->addWidget(encoderButton);
00101   encoderVGroupBoxLayout->addWidget(encoderHBox);
00102   encoderVGroupBoxLayout->addWidget(fEncoderStatus);
00103 
00104   encoderGroupBox->setLayout(encoderVGroupBoxLayout);
00105   globalVLayout->addWidget(encoderGroupBox);
00106 
00107   connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
00108 
00109 
00110   // temp folder group box
00111   QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"),this);
00112   QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
00113 
00114   // temp folder Path 
00115   QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
00116   QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
00117 
00118   fTempFolderPath = new QLineEdit("",tempFolderHBox);
00119 
00120   QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
00121   tempButton->setMaximumWidth (30);
00122 
00123   fTempFolderStatus = new QLabel(tempFolderGroupBox);
00124   fTempFolderStatus->setWordWrap(true);
00125   tempFolderVGroupBoxLayout->setMargin(15);
00126   fTempFolderStatus->setText("");
00127 
00128   tempFolderHBoxLayout->addWidget(fTempFolderPath);
00129   tempFolderHBoxLayout->addWidget(tempButton);
00130   tempFolderVGroupBoxLayout->addWidget(tempFolderHBox);
00131   tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus);
00132 
00133   tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout);
00134   globalVLayout->addWidget(tempFolderGroupBox);
00135 
00136   connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) );
00137 
00138 
00139 
00140 
00141   // save file group box
00142   QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"),this);
00143   QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
00144 
00145   // save file 
00146   QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
00147   QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
00148 
00149   fSaveFileName = new QLineEdit("G4Movie.mpeg",saveFileHBox);
00150 
00151   QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
00152   saveButton->setMaximumWidth (30);
00153 
00154   fSaveFileStatus = new QLabel(saveFileGroupBox);
00155   fSaveFileStatus->setWordWrap(true);
00156   saveFileVGroupBoxLayout->setMargin(15);
00157   fSaveFileStatus->setText("");
00158 
00159   saveFileHBoxLayout->addWidget(fSaveFileName);
00160   saveFileHBoxLayout->addWidget(saveButton);
00161   saveFileVGroupBoxLayout->addWidget(saveFileHBox);
00162   saveFileVGroupBoxLayout->addWidget(fSaveFileStatus);
00163 
00164   saveFileGroupBox->setLayout(saveFileVGroupBoxLayout);
00165   globalVLayout->addWidget(saveFileGroupBox);
00166 
00167   connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) );
00168 
00169 
00170 
00171   // label
00172 
00173   QLabel *infoLabel = new QLabel("  Press SPACE to Start/Pause video recording \n  Press RETURN to Stop video recording",this);
00174 
00175   // global status
00176   QGroupBox *statusGroupBox = new QGroupBox(tr("Status"),this);
00177   QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox);
00178 
00179   fRecordingStatus = new QLabel(statusGroupBox);
00180   statusVGroupBoxLayout->setMargin(15);
00181   fRecordingStatus->setWordWrap(true);
00182   QPalette mypalette( fRecordingStatus->palette() );
00183   mypalette.setColor( QPalette::Text, Qt::green);
00184   fRecordingStatus->setPalette(mypalette);
00185 
00186   fRecordingInfos = new QLabel(statusGroupBox);
00187   fRecordingInfos->setWordWrap(true);
00188   setRecordingInfos("");
00189 
00190   statusVGroupBoxLayout->addWidget(fRecordingStatus);
00191   statusVGroupBoxLayout->addWidget(fRecordingInfos);
00192 
00193   statusGroupBox->setLayout(statusVGroupBoxLayout);
00194   globalVLayout->addWidget(infoLabel);
00195   globalVLayout->addWidget(statusGroupBox);
00196 
00197   // buttons
00198   QWidget *buttonBox = new QWidget(this);
00199 
00200   QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
00201 
00202   QPushButton *buttonReset = new QPushButton( tr( "&Reset" ),buttonBox );
00203   buttonReset->setAutoDefault( TRUE );
00204   buttonBoxLayout->addWidget(buttonReset);
00205 
00206   fButtonStartPause = new QPushButton( tr( "  &Start " ),buttonBox );
00207   fButtonStartPause->setEnabled(true);
00208   fButtonStartPause->setAutoDefault( TRUE );
00209   buttonBoxLayout->addWidget(fButtonStartPause);
00210 
00211   fButtonStopFinishClose = new QPushButton( tr( "&Stop" ),buttonBox );
00212   fButtonStopFinishClose->setEnabled(false);
00213   fButtonStopFinishClose->setAutoDefault( TRUE );
00214   buttonBoxLayout->addWidget(fButtonStopFinishClose);
00215 
00216   fButtonSave = new QPushButton( tr( "&Save" ),buttonBox );
00217   fButtonSave->setEnabled(false);
00218   fButtonSave->setAutoDefault( TRUE );
00219   buttonBoxLayout->addWidget(fButtonSave);
00220 
00221   QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
00222   buttonCancel->setAutoDefault( TRUE );
00223   buttonBoxLayout->addWidget(buttonCancel);
00224 
00225   buttonBox->setLayout(buttonBoxLayout);
00226   globalVLayout->addWidget(buttonBox);
00227 
00228 
00229 
00230   setLayout(globalVLayout);
00231 
00232   // signals and slots connections
00233   connect( fButtonStartPause, SIGNAL( clicked() ), fParentViewer, SLOT(    startPauseVideo() ) );
00234   connect( buttonReset, SIGNAL( clicked() ), this, SLOT( resetRecording() ) );
00235   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00236   connect( fButtonStopFinishClose, SIGNAL( clicked() ), this, SLOT( stopFinishClose() ) );
00237   connect( fButtonSave, SIGNAL( clicked() ), this, SLOT( save() ) );
00238 
00239   // fill
00240   setRecordingStatus("");
00241   fEncoderPath->setText(fParentViewer->getEncoderPath());
00242   fTempFolderPath->setText(fParentViewer->getTempFolderPath());
00243 
00244   // connect line edit signals
00245   connect (fEncoderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(checkEncoderSwParameters()));
00246   connect (fTempFolderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(checkTempFolderParameters()));
00247   connect (fSaveFileName,SIGNAL(textChanged ( const QString&)),this,SLOT(checkSaveFileNameParameters()));
00248 
00249   connect (fEncoderPath,SIGNAL(editingFinished ()),this,SLOT(checkEncoderSwParameters()));
00250   connect (fTempFolderPath,SIGNAL(editingFinished ()),this,SLOT(checkTempFolderParameters()));
00251   connect (fSaveFileName,SIGNAL(editingFinished ()),this,SLOT(checkSaveFileNameParameters()));
00252 
00253 }
00254 
00255 
00256 
00257 G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
00258 {
00259 }
00260 
00261 void G4OpenGLQtMovieDialog::selectEncoderPathAction()
00262 {
00263   QString nomFich =  QFileDialog::getOpenFileName ( this,
00264                                                     "Select your encoder",
00265                                                     tr("Select your encoder ...")); 
00266 
00267 
00268   if (nomFich == "") {
00269     return;
00270   }
00271   fEncoderPath->setText(nomFich);
00272   checkEncoderSwParameters();
00273  }
00274 
00275 
00276 void G4OpenGLQtMovieDialog::selectTempPathAction()
00277 {
00278   QString nomFich =  QFileDialog::getExistingDirectory ( this,
00279                                                     "Select temporary folder",
00280                                                     tr("Select temporary folder ...")); 
00281 
00282   if (nomFich == "") {
00283     return;
00284   }
00285   fTempFolderPath->setText(nomFich);
00286   checkTempFolderParameters();
00287  }
00288 
00289 
00290 void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
00291 {
00292   QString nomFich =  QFileDialog::getSaveFileName ( this,
00293                                                     "Select saved file",
00294                                                     tr("Select saved file ...")); 
00295 
00296   if (nomFich == "") {
00297     return;
00298   }
00299   fSaveFileName->setText(nomFich);
00300   checkSaveFileNameParameters();
00301  }
00302 
00303 
00304 void G4OpenGLQtMovieDialog::stopFinishClose() {
00305   fParentViewer->stopVideo();
00306 }
00307 
00308 void G4OpenGLQtMovieDialog::save() {
00309   if (((fParentViewer->isPaused()) || fParentViewer->isRecording() || fParentViewer->isStopped())) {
00310     fParentViewer->saveVideo();
00311   }
00312 }
00313 
00318 bool G4OpenGLQtMovieDialog::checkEncoderSwParameters() {
00319 
00320   bool status = true;
00321   QPalette mypalette( fEncoderPath->palette() );
00322 
00323   QString temp = fParentViewer->setEncoderPath(fEncoderPath->text());
00324   setRecordingInfos("");
00325   fEncoderStatus->setText(temp);
00326   if (temp != "") {
00327     mypalette.setColor( QPalette::Base, Qt::red);
00328     if (fParentViewer->isReadyToEncode()) {
00329       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");
00330         }
00331     status = false;
00332   } else {
00333     mypalette.setColor( QPalette::Base, Qt::white);
00334     fEncoderPath->setText(fParentViewer->getEncoderPath());
00335   }
00336   fEncoderPath->setPalette(mypalette);
00337   return status;
00338 }
00339 
00340 
00345 bool G4OpenGLQtMovieDialog::checkTempFolderParameters() {
00346 
00347   bool status = true;
00348   QPalette mypalette( fTempFolderPath->palette() );
00349 
00350   QString temp = fParentViewer->setTempFolderPath(fTempFolderPath->text());
00351   fTempFolderStatus->setText(temp);
00352   if (temp != "") {
00353     mypalette.setColor( QPalette::Base, Qt::red);
00354     status = false;
00355   } else {
00356     mypalette.setColor( QPalette::Base, Qt::white);
00357     fTempFolderPath->setText(fParentViewer->getTempFolderPath());
00358   }
00359   fTempFolderPath->setPalette(mypalette);
00360   return status;
00361 }
00362 
00363 
00368 bool G4OpenGLQtMovieDialog::checkSaveFileNameParameters() {
00369 
00370   bool status = true;
00371   QPalette mypalette( fSaveFileName->palette() );
00372 
00373   QString temp = fParentViewer->setSaveFileName(fSaveFileName->text());
00374   fSaveFileStatus->setText(temp);
00375   if (temp != "") { 
00376     mypalette.setColor( QPalette::Base, Qt::red);
00377     status = false;
00378   } else {
00379     mypalette.setColor( QPalette::Base, Qt::white);
00380     fSaveFileName->setText(fParentViewer->getSaveFileName());
00381   }
00382   fSaveFileName->setPalette(mypalette);
00383   return status;
00384 }
00385 
00386 
00387 void G4OpenGLQtMovieDialog::resetRecording() {
00388   fParentViewer->resetRecording();
00389 }
00390 
00391 
00392 void G4OpenGLQtMovieDialog::setRecordingStatus(QString txt) {
00393   fRecordingStatus->setText(txt);
00394   if (fParentViewer->isWaiting()) {
00395     fButtonStartPause->setText("  &Start ");
00396     fButtonStartPause->setEnabled(true);
00397     fButtonStopFinishClose->setEnabled(false);
00398     fButtonSave->setEnabled(false);
00399 
00400   } else if (fParentViewer->isPaused()) {
00401 
00402     fButtonStartPause->setText("  &Continue ");
00403     fButtonStartPause->setEnabled(true);
00404     fButtonStopFinishClose->setEnabled(true);
00405     fButtonSave->setEnabled(false);
00406 
00407   } else if (fParentViewer->isRecording()) {
00408 
00409     fButtonStartPause->setText("  &Pause ");
00410     fButtonStartPause->setEnabled(true);
00411     fButtonStopFinishClose->setEnabled(true);
00412     fButtonSave->setEnabled(false);
00413 
00414   } else if (fParentViewer->isBadOutput()) {
00415 
00416     fButtonStartPause->setText("  &Start ");
00417     fButtonStartPause->setEnabled(true);
00418     fButtonStopFinishClose->setEnabled(false);
00419     fButtonSave->setEnabled(false);
00420 
00421   } else if (fParentViewer->isBadTmp()) {
00422 
00423     fButtonStartPause->setText("  &Start ");
00424     fButtonStartPause->setEnabled(false);
00425     fButtonStopFinishClose->setEnabled(false);
00426     fButtonSave->setEnabled(false);
00427 
00428   } else if (fParentViewer->isBadEncoder()) {
00429 
00430     fButtonStartPause->setText("  &Start ");
00431     fButtonStartPause->setEnabled(true);
00432     fButtonStopFinishClose->setEnabled(false);
00433     fButtonSave->setEnabled(false);
00434 
00435   } else if (fParentViewer->isSuccess()) {
00436 
00437     fButtonStartPause->setText("  &Start ");
00438     fButtonStartPause->setEnabled(false);
00439     fButtonStopFinishClose->setEnabled(false);
00440     fButtonSave->setEnabled(false);
00441 
00442   } else if (fParentViewer->isFailed()) {
00443 
00444     fButtonStartPause->setText("  &Start ");
00445     fButtonStartPause->setEnabled(false);
00446     fButtonStopFinishClose->setEnabled(false);
00447     fButtonSave->setEnabled(false);
00448 
00449   } else if (fParentViewer->isStopped()) {
00450 
00451     fButtonStartPause->setText("  &Start ");
00452     fButtonStartPause->setEnabled(false);
00453     fButtonStopFinishClose->setEnabled(false);
00454     fButtonSave->setEnabled(true);
00455   }
00456 }
00457 
00458 
00459 void G4OpenGLQtMovieDialog::setRecordingInfos(QString txt) {
00460   fRecordingInfos->setText(txt);
00461 }
00462 
00463 
00464 void G4OpenGLQtMovieDialog::enabledApplyButton() {
00465   fButtonStartPause->setEnabled(true);
00466 }
00467 
00468 #endif

Generated on Mon May 27 17:49:09 2013 for Geant4 by  doxygen 1.4.7