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

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

on avance

  • Property svn:mime-type set to text/cpp
File size: 11.8 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);
98  fEncoderStatus->setText("");
99
[732]100#if QT_VERSION < 0x040000
[733]101  encoderHBoxLayout->add(fEncoderPath);
102  encoderHBoxLayout->add(encoderButton);
[734]103  encoderVGroupBoxLayout->add(encoderHBox);
104  encoderVGroupBoxLayout->add(fEncoderStatus);
[735]105
106  globalVLayout->add(encoderGroupBox);
[732]107#else
[733]108  encoderHBoxLayout->addWidget(fEncoderPath);
109  encoderHBoxLayout->addWidget(encoderButton);
[734]110  encoderVGroupBoxLayout->addWidget(encoderHBox);
111  encoderVGroupBoxLayout->addWidget(fEncoderStatus);
[730]112
[734]113  encoderGroupBox->setLayout(encoderVGroupBoxLayout);
[735]114  globalVLayout->addWidget(encoderGroupBox);
[732]115#endif
[735]116
[733]117  connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
[732]118
119  fEncoderPath->setText(fParentViewer->getEncoderPath());
[730]120
[732]121
[733]122  // temp folder group box
123  QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"));           
[734]124  QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
[733]125
[732]126  // temp folder Path
[733]127  QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
[734]128  QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
[732]129
[733]130  fTempFolderPath = new QLineEdit("",tempFolderHBox);
131
132  QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
133  tempButton->setMaximumWidth (30);
134
135  fTempFolderStatus = new QLabel(tempFolderGroupBox);
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  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
158
[734]159
160
[733]161  // save file group box
162  QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"));           
[734]163  QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
[733]164
165  // save file
166  QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
167  QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
168
169  fSaveFileName = new QLineEdit("",saveFileHBox);
170
171  QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
172  saveButton->setMaximumWidth (30);
173
174  fSaveFileStatus = new QLabel(saveFileGroupBox);
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);
205  fGlobalStatus = new QLabel(statusGroupBox);
206  fGlobalStatus->setText("");
[733]207
[730]208#if QT_VERSION < 0x040000
[735]209  statusVGroupBoxLayout->add(fGlobalStatus);
210
[730]211  globalVLayout->add(infoLabel);
[735]212  globalVLayout->add(statusGroupBox);
[730]213#else
[735]214  statusVGroupBoxLayout->addWidget(fGlobalStatus);
215
216  statusGroupBox->setLayout(statusVGroupBoxLayout);
[730]217  globalVLayout->addWidget(infoLabel);
[735]218  globalVLayout->addWidget(statusGroupBox);
[730]219#endif
[732]220
221  // buttons
[730]222  QWidget *buttonBox = new QWidget(this);
223
224  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
225
[732]226  QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
227  buttonCancel->setAutoDefault( TRUE );
228  buttonBoxLayout->addWidget(buttonCancel);
[730]229
[733]230  QPushButton *buttonApply = new QPushButton( tr( "&Apply" ),buttonBox );
231  buttonApply->setAutoDefault( TRUE );
232  buttonBoxLayout->addWidget(buttonApply);
233
234  QPushButton * buttonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
[735]235  buttonEncode->setEnabled(false);
[730]236  buttonEncode->setAutoDefault( TRUE );
237  buttonEncode->setDefault( TRUE );
238  buttonBoxLayout->addWidget(buttonEncode);
239
240#if QT_VERSION >= 0x040000
241  buttonBox->setLayout(buttonBoxLayout);
242#endif
243  globalVLayout->addWidget(buttonBox);
244
245
246
247#if QT_VERSION >= 0x040000
248  setLayout(globalVLayout);
249#endif
250
251  // signals and slots connections
[733]252  connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) );
[730]253  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
[733]254  connect( buttonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
[730]255}
256
257
258
259G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
260{
261}
262
[733]263void G4OpenGLQtMovieDialog::selectEncoderPathAction()
[730]264{
265  QString nomFich =  QFileDialog::getOpenFileName ( this,
266                                                    "Select your encoder",
267                                                    tr("Select your encoder ..."));
268  if (nomFich == "") {
269    return;
270  }
[733]271  checkEncoderParameters(nomFich);
272 }
273
274void G4OpenGLQtMovieDialog::selectTempPathAction()
275{
276  QString nomFich =  QFileDialog::getOpenFileName ( this,
277                                                    "Select temporary folder",
278                                                    tr("Select temporary folder ..."));
279  if (nomFich == "") {
280    return;
281  }
282  checkTempFolderParameters(nomFich);
283 }
284
285void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
286{
287  QString nomFich =  QFileDialog::getOpenFileName ( this,
288                                                    "Select saved file",
289                                                    tr("Select saved file ..."));
290  if (nomFich == "") {
291    return;
292  }
293  checkSaveFileNameParameters(nomFich);
294 }
295
296void G4OpenGLQtMovieDialog::encode() {
[730]297}
298
[733]299/** Check all parameters
300*/
301void G4OpenGLQtMovieDialog::checkAllParameters() {
302  checkEncoderParameters(fEncoderPath->text());
303  checkTempFolderParameters(fTempFolderPath->text());
304  checkSaveFileNameParameters(fSaveFileName->text());
305}
306
307        /**
[732]308 * If one of parameter is incorrect, put it in red and don't valid it
[733]309 * If valid, save it
[732]310 */
[733]311void G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) {
[730]312
[732]313  QPalette palette( fEncoderPath->palette() );
314
[733]315  QString temp = fParentViewer->setEncoderPath(param);
316  fGlobalStatus->setText("");
317    fEncoderStatus->setText(temp);
318  if (temp != "") {
[732]319    palette.setColor( QPalette::Base, Qt::red);
[735]320    fGlobalStatus->setText("If no valid encode defined, screnn \ncapture files will be saved in the\ntemp folder in ppm format.");
[732]321  } else {
322    palette.setColor( QPalette::Base, Qt::white);
[733]323    fEncoderPath->setText(fParentViewer->getEncoderPath());
[732]324  }
325  fEncoderPath->setPalette(palette);
[733]326}
[732]327
328
[733]329/**
330 * If one of parameter is incorrect, put it in red and don't valid it
331 * If valid, save it
332 */
333void G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) {
[732]334
[733]335  QPalette palette( fTempFolderPath->palette() );
336
337  QString temp = fParentViewer->setTempFolderPath(param);
338    fTempFolderStatus->setText(temp);
339  if (temp != "") {
[732]340    palette.setColor( QPalette::Base, Qt::red);
341  } else {
342    palette.setColor( QPalette::Base, Qt::white);
[733]343    fTempFolderPath->setText(fParentViewer->getEncoderPath());
[732]344  }
[733]345  fTempFolderPath->setPalette(palette);
[732]346}
347
[733]348
349/**
350 * If one of parameter is incorrect, put it in red and don't valid it
351 * If valid, save it
352 */
353void G4OpenGLQtMovieDialog::checkSaveFileNameParameters(QString param) {
354
355  QPalette palette( fSaveFileName->palette() );
356
357  QString temp = fParentViewer->setSaveFileName(param);
358    fSaveFileStatus->setText(temp);
359  if (temp != "") {
360    palette.setColor( QPalette::Base, Qt::red);
361  } else {
362    palette.setColor( QPalette::Base, Qt::white);
363    fSaveFileName->setText(fParentViewer->getSaveFileName());
364  }
365  fSaveFileName->setPalette(palette);
366}
[730]367#endif
Note: See TracBrowser for help on using the repository browser.