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

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

corrections pour Qt3 mises sous cvs

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