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

Last change on this file since 753 was 752, checked in by garnier, 18 years ago

on bloque si l encoder est un dir+le status est mis a jour des le debut

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