ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLQtMovieDialog.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLQtMovieDialog.cc
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 //
28 //
29 
30 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
31 
32 #include "G4OpenGLQtViewer.hh" // should be first in case we include
33  // some boost SIGNAL/SLOT library
34 #include "G4OpenGLQtMovieDialog.hh"
35 
36 #include <qpushbutton.h>
37 #include <qpalette.h>
38 #include <qlabel.h>
39 #include <qgroupbox.h>
40 #include <qlayout.h>
41 #include <qlineedit.h>
42 #include <qfiledialog.h>
43 #include <qprocess.h>
44 
45 
46 // +---------------------------------------+
47 // + Path for encoder +
48 // + _______ +
49 // + | select| ____________________ +
50 // + ------- +
51 // + Temp path +
52 // + _______ +
53 // + | select| ____________________ +
54 // + ------- +
55 // + +
56 // + max number of frames ________ +
57 // + .... +
58 // + +
59 // + Label : X frames Saves/Encoding +
60 // + Cancel Encode +
61 // +---------------------------------------+
62 
63 G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
64  G4OpenGLQtViewer* parentViewer,
65  QWidget* parentw
66 )
67  : QDialog( parentw ),
68  fParentViewer(parentViewer)
69 {
70  setModal(false);
71  setWindowTitle( tr( " Save as movie" ));
72 
73 
74  // global layout
75  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
76  globalVLayout->setMargin(10);
77  globalVLayout->setSpacing(10);
78 
79  // Encoder group box
80  QGroupBox *encoderGroupBox = new QGroupBox(tr("Encoder path"),this);
81  QVBoxLayout *encoderVGroupBoxLayout = new QVBoxLayout(encoderGroupBox);
82 
83  // Encoder Path
84  QWidget *encoderHBox = new QWidget(encoderGroupBox);
85  QHBoxLayout *encoderHBoxLayout = new QHBoxLayout(encoderHBox);
86  fEncoderPath = new QLineEdit("",encoderHBox);
87 
88  QPushButton *encoderButton = new QPushButton(tr("..."),encoderHBox);
89  encoderButton->setMaximumWidth (30);
90 
91  fEncoderStatus = new QLabel(encoderGroupBox);
92 
93  fEncoderStatus->setWordWrap(true);
94  encoderVGroupBoxLayout->setMargin(15);
95 
96  fEncoderStatus->setText("");
97 
98  encoderHBoxLayout->addWidget(fEncoderPath);
99  encoderHBoxLayout->addWidget(encoderButton);
100  encoderVGroupBoxLayout->addWidget(encoderHBox);
101  encoderVGroupBoxLayout->addWidget(fEncoderStatus);
102 
103  encoderGroupBox->setLayout(encoderVGroupBoxLayout);
104  globalVLayout->addWidget(encoderGroupBox);
105 
106  connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
107 
108 
109  // temp folder group box
110  QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"),this);
111  QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
112 
113  // temp folder Path
114  QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
115  QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
116 
117  fTempFolderPath = new QLineEdit("",tempFolderHBox);
118 
119  QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
120  tempButton->setMaximumWidth (30);
121 
122  fTempFolderStatus = new QLabel(tempFolderGroupBox);
123  fTempFolderStatus->setWordWrap(true);
124  tempFolderVGroupBoxLayout->setMargin(15);
125  fTempFolderStatus->setText("");
126 
127  tempFolderHBoxLayout->addWidget(fTempFolderPath);
128  tempFolderHBoxLayout->addWidget(tempButton);
129  tempFolderVGroupBoxLayout->addWidget(tempFolderHBox);
130  tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus);
131 
132  tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout);
133  globalVLayout->addWidget(tempFolderGroupBox);
134 
135  connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) );
136 
137 
138 
139 
140  // save file group box
141  QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"),this);
142  QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
143 
144  // save file
145  QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
146  QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
147 
148  fSaveFileName = new QLineEdit("G4Movie.mpeg",saveFileHBox);
149 
150  QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
151  saveButton->setMaximumWidth (30);
152 
153  fSaveFileStatus = new QLabel(saveFileGroupBox);
154  fSaveFileStatus->setWordWrap(true);
155  saveFileVGroupBoxLayout->setMargin(15);
156  fSaveFileStatus->setText("");
157 
158  saveFileHBoxLayout->addWidget(fSaveFileName);
159  saveFileHBoxLayout->addWidget(saveButton);
160  saveFileVGroupBoxLayout->addWidget(saveFileHBox);
161  saveFileVGroupBoxLayout->addWidget(fSaveFileStatus);
162 
163  saveFileGroupBox->setLayout(saveFileVGroupBoxLayout);
164  globalVLayout->addWidget(saveFileGroupBox);
165 
166  connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) );
167 
168 
169 
170  // label
171 
172  QLabel *infoLabel = new QLabel(" Press SPACE to Start/Pause video recording \n Press RETURN to Stop video recording",this);
173 
174  // global status
175  QGroupBox *statusGroupBox = new QGroupBox(tr("Status"),this);
176  QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox);
177 
178  fRecordingStatus = new QLabel(statusGroupBox);
179  statusVGroupBoxLayout->setMargin(15);
180  fRecordingStatus->setWordWrap(true);
181  QPalette mypalette( fRecordingStatus->palette() );
182  mypalette.setColor( QPalette::Text, Qt::green);
183  fRecordingStatus->setPalette(mypalette);
184 
185  fRecordingInfos = new QLabel(statusGroupBox);
186  fRecordingInfos->setWordWrap(true);
187  setRecordingInfos("");
188 
189  statusVGroupBoxLayout->addWidget(fRecordingStatus);
190  statusVGroupBoxLayout->addWidget(fRecordingInfos);
191 
192  statusGroupBox->setLayout(statusVGroupBoxLayout);
193  globalVLayout->addWidget(infoLabel);
194  globalVLayout->addWidget(statusGroupBox);
195 
196  // buttons
197  QWidget *buttonBox = new QWidget(this);
198 
199  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
200 
201  QPushButton *buttonReset = new QPushButton( tr( "&Reset" ),buttonBox );
202  buttonReset->setAutoDefault( TRUE );
203  buttonBoxLayout->addWidget(buttonReset);
204 
205  fButtonStartPause = new QPushButton( tr( " &Start " ),buttonBox );
206  fButtonStartPause->setEnabled(true);
207  fButtonStartPause->setAutoDefault( TRUE );
208  buttonBoxLayout->addWidget(fButtonStartPause);
209 
210  fButtonStopFinishClose = new QPushButton( tr( "&Stop" ),buttonBox );
211  fButtonStopFinishClose->setEnabled(false);
212  fButtonStopFinishClose->setAutoDefault( TRUE );
213  buttonBoxLayout->addWidget(fButtonStopFinishClose);
214 
215  fButtonSave = new QPushButton( tr( "&Save" ),buttonBox );
216  fButtonSave->setEnabled(false);
217  fButtonSave->setAutoDefault( TRUE );
218  buttonBoxLayout->addWidget(fButtonSave);
219 
220  QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
221  buttonCancel->setAutoDefault( TRUE );
222  buttonBoxLayout->addWidget(buttonCancel);
223 
224  buttonBox->setLayout(buttonBoxLayout);
225  globalVLayout->addWidget(buttonBox);
226 
227 
228 
229  setLayout(globalVLayout);
230 
231  // signals and slots connections
232  connect( fButtonStartPause, SIGNAL( clicked() ), fParentViewer, SLOT( startPauseVideo() ) );
233  connect( buttonReset, SIGNAL( clicked() ), this, SLOT( resetRecording() ) );
234  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
235  connect( fButtonStopFinishClose, SIGNAL( clicked() ), this, SLOT( stopFinishClose() ) );
236  connect( fButtonSave, SIGNAL( clicked() ), this, SLOT( save() ) );
237 
238  // fill
239  setRecordingStatus("");
240  fEncoderPath->setText(fParentViewer->getEncoderPath());
241  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
242 
243  // connect line edit signals
244  connect (fEncoderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(checkEncoderSwParameters()));
245  connect (fTempFolderPath,SIGNAL(textChanged ( const QString&)),this,SLOT(checkTempFolderParameters()));
246  connect (fSaveFileName,SIGNAL(textChanged ( const QString&)),this,SLOT(checkSaveFileNameParameters()));
247 
248  connect (fEncoderPath,SIGNAL(editingFinished ()),this,SLOT(checkEncoderSwParameters()));
249  connect (fTempFolderPath,SIGNAL(editingFinished ()),this,SLOT(checkTempFolderParameters()));
250  connect (fSaveFileName,SIGNAL(editingFinished ()),this,SLOT(checkSaveFileNameParameters()));
251 
252 }
253 
254 
255 
256 G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
257 {
258 }
259 
260 void G4OpenGLQtMovieDialog::selectEncoderPathAction()
261 {
262  QString nomFich = QFileDialog::getOpenFileName ( this,
263  "Select your encoder",
264  tr("Select your encoder ..."));
265 
266 
267  if (nomFich == "") {
268  return;
269  }
270  fEncoderPath->setText(nomFich);
271  checkEncoderSwParameters();
272  }
273 
274 
275 void G4OpenGLQtMovieDialog::selectTempPathAction()
276 {
277  QString nomFich = QFileDialog::getExistingDirectory ( this,
278  "Select temporary folder",
279  tr("Select temporary folder ..."));
280 
281  if (nomFich == "") {
282  return;
283  }
284  fTempFolderPath->setText(nomFich);
285  checkTempFolderParameters();
286  }
287 
288 
289 void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
290 {
291  QString nomFich = QFileDialog::getSaveFileName ( this,
292  "Select saved file",
293  tr("Select saved file ..."));
294 
295  if (nomFich == "") {
296  return;
297  }
298  fSaveFileName->setText(nomFich);
299  checkSaveFileNameParameters();
300  }
301 
302 
303 void G4OpenGLQtMovieDialog::stopFinishClose() {
304  fParentViewer->stopVideo();
305 }
306 
307 void G4OpenGLQtMovieDialog::save() {
308  if (((fParentViewer->isPaused()) || fParentViewer->isRecording() || fParentViewer->isStopped())) {
309  fParentViewer->saveVideo();
310  }
311 }
312 
317 bool G4OpenGLQtMovieDialog::checkEncoderSwParameters() {
318 
319  bool status = true;
320  QPalette mypalette( fEncoderPath->palette() );
321 
322  QString temp = fParentViewer->setEncoderPath(fEncoderPath->text());
323  setRecordingInfos("");
324  fEncoderStatus->setText(temp);
325  if (temp != "") {
326  mypalette.setColor( QPalette::Base, Qt::red);
327  if (fParentViewer->isReadyToEncode()) {
328  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");
329  }
330  status = false;
331  } else {
332  mypalette.setColor( QPalette::Base, Qt::white);
333  fEncoderPath->setText(fParentViewer->getEncoderPath());
334  }
335  fEncoderPath->setPalette(mypalette);
336  return status;
337 }
338 
339 
344 bool G4OpenGLQtMovieDialog::checkTempFolderParameters() {
345 
346  bool status = true;
347  QPalette mypalette( fTempFolderPath->palette() );
348 
349  QString temp = fParentViewer->setTempFolderPath(fTempFolderPath->text());
350  fTempFolderStatus->setText(temp);
351  if (temp != "") {
352  mypalette.setColor( QPalette::Base, Qt::red);
353  status = false;
354  } else {
355  mypalette.setColor( QPalette::Base, Qt::white);
356  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
357  }
358  fTempFolderPath->setPalette(mypalette);
359  return status;
360 }
361 
362 
367 bool G4OpenGLQtMovieDialog::checkSaveFileNameParameters() {
368 
369  bool status = true;
370  QPalette mypalette( fSaveFileName->palette() );
371 
372  QString temp = fParentViewer->setSaveFileName(fSaveFileName->text());
373  fSaveFileStatus->setText(temp);
374  if (temp != "") {
375  mypalette.setColor( QPalette::Base, Qt::red);
376  status = false;
377  } else {
378  mypalette.setColor( QPalette::Base, Qt::white);
379  fSaveFileName->setText(fParentViewer->getSaveFileName());
380  }
381  fSaveFileName->setPalette(mypalette);
382  return status;
383 }
384 
385 
386 void G4OpenGLQtMovieDialog::resetRecording() {
387  fParentViewer->resetRecording();
388 }
389 
390 
391 void G4OpenGLQtMovieDialog::setRecordingStatus(QString txt) {
392  fRecordingStatus->setText(txt);
393  if (fParentViewer->isWaiting()) {
394  fButtonStartPause->setText(" &Start ");
395  fButtonStartPause->setEnabled(true);
396  fButtonStopFinishClose->setEnabled(false);
397  fButtonSave->setEnabled(false);
398 
399  } else if (fParentViewer->isPaused()) {
400 
401  fButtonStartPause->setText(" &Continue ");
402  fButtonStartPause->setEnabled(true);
403  fButtonStopFinishClose->setEnabled(true);
404  fButtonSave->setEnabled(false);
405 
406  } else if (fParentViewer->isRecording()) {
407 
408  fButtonStartPause->setText(" &Pause ");
409  fButtonStartPause->setEnabled(true);
410  fButtonStopFinishClose->setEnabled(true);
411  fButtonSave->setEnabled(false);
412 
413  } else if (fParentViewer->isBadOutput()) {
414 
415  fButtonStartPause->setText(" &Start ");
416  fButtonStartPause->setEnabled(true);
417  fButtonStopFinishClose->setEnabled(false);
418  fButtonSave->setEnabled(false);
419 
420  } else if (fParentViewer->isBadTmp()) {
421 
422  fButtonStartPause->setText(" &Start ");
423  fButtonStartPause->setEnabled(false);
424  fButtonStopFinishClose->setEnabled(false);
425  fButtonSave->setEnabled(false);
426 
427  } else if (fParentViewer->isBadEncoder()) {
428 
429  fButtonStartPause->setText(" &Start ");
430  fButtonStartPause->setEnabled(true);
431  fButtonStopFinishClose->setEnabled(false);
432  fButtonSave->setEnabled(false);
433 
434  } else if (fParentViewer->isSuccess()) {
435 
436  fButtonStartPause->setText(" &Start ");
437  fButtonStartPause->setEnabled(false);
438  fButtonStopFinishClose->setEnabled(false);
439  fButtonSave->setEnabled(false);
440 
441  } else if (fParentViewer->isFailed()) {
442 
443  fButtonStartPause->setText(" &Start ");
444  fButtonStartPause->setEnabled(false);
445  fButtonStopFinishClose->setEnabled(false);
446  fButtonSave->setEnabled(false);
447 
448  } else if (fParentViewer->isStopped()) {
449 
450  fButtonStartPause->setText(" &Start ");
451  fButtonStartPause->setEnabled(false);
452  fButtonStopFinishClose->setEnabled(false);
453  fButtonSave->setEnabled(true);
454  }
455 }
456 
457 
458 void G4OpenGLQtMovieDialog::setRecordingInfos(QString txt) {
459  fRecordingInfos->setText(txt);
460 }
461 
462 
463 void G4OpenGLQtMovieDialog::enabledApplyButton() {
464  fButtonStartPause->setEnabled(true);
465 }
466 
467 #endif