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