source: trunk/source/visualization/OpenGL/src/G4OpenGLQtMovieDialog.cc@ 843

Last change on this file since 843 was 756, checked in by garnier, 18 years ago

error correct on Qt3.3. Improvement for movie

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