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

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

layout oks

  • Property svn:mime-type set to text/cpp
File size: 11.7 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->setText("");
99
100#if QT_VERSION < 0x040000
101  encoderHBoxLayout->add(fEncoderPath);
102  encoderHBoxLayout->add(encoderButton);
103  encoderVGroupBoxLayout->add(encoderHBox);
104  encoderVGroupBoxLayout->add(fEncoderStatus);
105#else
106  encoderHBoxLayout->addWidget(fEncoderPath);
107  encoderHBoxLayout->addWidget(encoderButton);
108  encoderVGroupBoxLayout->addWidget(encoderHBox);
109  encoderVGroupBoxLayout->addWidget(fEncoderStatus);
110#endif
111
112#if QT_VERSION >= 0x040000
113  encoderGroupBox->setLayout(encoderVGroupBoxLayout);
114#endif
115  connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) );
116
117#if QT_VERSION < 0x040000
118  globalVLayout->add(encoderGroupBox);
119#else
120  globalVLayout->addWidget(encoderGroupBox);
121#endif
122
123  fEncoderPath->setText(fParentViewer->getEncoderPath());
124
125
126  // temp folder group box
127  QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path"));           
128  QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox);
129
130  // temp folder Path
131  QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox);
132  QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox);
133
134  fTempFolderPath = new QLineEdit("",tempFolderHBox);
135
136  QPushButton *tempButton = new QPushButton(tr("..."),tempFolderHBox);
137  tempButton->setMaximumWidth (30);
138
139  fTempFolderStatus = new QLabel(tempFolderGroupBox);
140  fTempFolderStatus->setText("");
141
142#if QT_VERSION < 0x040000
143  tempFolderHBoxLayout->add(fTempFolderPath);
144  tempFolderHBoxLayout->add(tempButton);
145  tempFolderVGroupBoxLayout->add(tempFolderHBox);
146  tempFolderVGroupBoxLayout->add(fTempFolderStatus);
147#else
148  tempFolderHBoxLayout->addWidget(fTempFolderPath);
149  tempFolderHBoxLayout->addWidget(tempButton);
150  tempFolderVGroupBoxLayout->addWidget(tempFolderHBox);
151  tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus);
152#endif
153
154#if QT_VERSION >= 0x040000
155  tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout);
156#endif
157  connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) );
158
159#if QT_VERSION < 0x040000
160  globalVLayout->add(tempFolderGroupBox);
161#else
162  globalVLayout->addWidget(tempFolderGroupBox);
163#endif
164
165  fTempFolderPath->setText(fParentViewer->getTempFolderPath());
166
167
168
169  // save file group box
170  QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as"));           
171  QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox);
172
173  // save file
174  QWidget *saveFileHBox = new QWidget(saveFileGroupBox);
175  QHBoxLayout *saveFileHBoxLayout = new QHBoxLayout(saveFileHBox);
176
177  fSaveFileName = new QLineEdit("",saveFileHBox);
178
179  QPushButton *saveButton = new QPushButton(tr("..."),saveFileHBox);
180  saveButton->setMaximumWidth (30);
181
182  fSaveFileStatus = new QLabel(saveFileGroupBox);
183  fSaveFileStatus->setText("");
184
185#if QT_VERSION < 0x040000
186  saveFileHBoxLayout->add(fSaveFileName);
187  saveFileHBoxLayout->add(saveButton);
188  saveFileVGroupBoxLayout->add(saveFileHBox);
189  saveFileVGroupBoxLayout->add(fSaveFileStatus);
190#else
191  saveFileHBoxLayout->addWidget(fSaveFileName);
192  saveFileHBoxLayout->addWidget(saveButton);
193  saveFileVGroupBoxLayout->addWidget(saveFileHBox);
194  saveFileVGroupBoxLayout->addWidget(fSaveFileStatus);
195#endif
196
197#if QT_VERSION >= 0x040000
198  saveFileGroupBox->setLayout(saveFileVGroupBoxLayout);
199#endif
200  connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) );
201
202#if QT_VERSION < 0x040000
203  globalVLayout->add(saveFileGroupBox);
204#else
205  globalVLayout->addWidget(saveFileGroupBox);
206#endif
207
208
209  // label
210
211  QLabel *infoLabel = new QLabel("  Press SPACE to Start/Pause video recording \n  Press RETURN to Stop video recording");
212
213  // global status
214  fGlobalStatus = new QLabel("");
215
216#if QT_VERSION < 0x040000
217  globalVLayout->add(infoLabel);
218  globalVLayout->add(fGlobalStatus);
219#else
220  globalVLayout->addWidget(infoLabel);
221  globalVLayout->addWidget(fGlobalStatus);
222#endif
223
224  // buttons
225  QWidget *buttonBox = new QWidget(this);
226
227  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
228
229  QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
230  buttonCancel->setAutoDefault( TRUE );
231  buttonBoxLayout->addWidget(buttonCancel);
232
233  QPushButton *buttonApply = new QPushButton( tr( "&Apply" ),buttonBox );
234  buttonApply->setAutoDefault( TRUE );
235  buttonBoxLayout->addWidget(buttonApply);
236
237  QPushButton * buttonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
238  buttonEncode->setAutoDefault( TRUE );
239  buttonEncode->setDefault( TRUE );
240  buttonBoxLayout->addWidget(buttonEncode);
241
242#if QT_VERSION >= 0x040000
243  buttonBox->setLayout(buttonBoxLayout);
244#endif
245  globalVLayout->addWidget(buttonBox);
246
247
248
249#if QT_VERSION >= 0x040000
250  setLayout(globalVLayout);
251#endif
252
253  // signals and slots connections
254  connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) );
255  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
256  connect( buttonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
257}
258
259
260
261G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog()
262{
263}
264
265void G4OpenGLQtMovieDialog::selectEncoderPathAction()
266{
267  QString nomFich =  QFileDialog::getOpenFileName ( this,
268                                                    "Select your encoder",
269                                                    tr("Select your encoder ..."));
270  if (nomFich == "") {
271    return;
272  }
273  checkEncoderParameters(nomFich);
274 }
275
276void G4OpenGLQtMovieDialog::selectTempPathAction()
277{
278  QString nomFich =  QFileDialog::getOpenFileName ( this,
279                                                    "Select temporary folder",
280                                                    tr("Select temporary folder ..."));
281  if (nomFich == "") {
282    return;
283  }
284  checkTempFolderParameters(nomFich);
285 }
286
287void G4OpenGLQtMovieDialog::selectSaveFileNameAction()
288{
289  QString nomFich =  QFileDialog::getOpenFileName ( this,
290                                                    "Select saved file",
291                                                    tr("Select saved file ..."));
292  if (nomFich == "") {
293    return;
294  }
295  checkSaveFileNameParameters(nomFich);
296 }
297
298void G4OpenGLQtMovieDialog::encode() {
299}
300
301/** Check all parameters
302*/
303void G4OpenGLQtMovieDialog::checkAllParameters() {
304  checkEncoderParameters(fEncoderPath->text());
305  checkTempFolderParameters(fTempFolderPath->text());
306  checkSaveFileNameParameters(fSaveFileName->text());
307}
308
309        /**
310 * If one of parameter is incorrect, put it in red and don't valid it
311 * If valid, save it
312 */
313void G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) {
314
315  QPalette palette( fEncoderPath->palette() );
316
317  QString temp = fParentViewer->setEncoderPath(param);
318  fGlobalStatus->setText("");
319    fEncoderStatus->setText(temp);
320  if (temp != "") {
321    palette.setColor( QPalette::Base, Qt::red);
322    fGlobalStatus->setText("If no valid encode defined, screnn /ncapture files will be saved in /nthe temp folder in ppm format.");
323  } else {
324    palette.setColor( QPalette::Base, Qt::white);
325    fEncoderPath->setText(fParentViewer->getEncoderPath());
326  }
327  fEncoderPath->setPalette(palette);
328}
329
330
331/**
332 * If one of parameter is incorrect, put it in red and don't valid it
333 * If valid, save it
334 */
335void G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) {
336
337  QPalette palette( fTempFolderPath->palette() );
338
339  QString temp = fParentViewer->setTempFolderPath(param);
340    fTempFolderStatus->setText(temp);
341  if (temp != "") {
342    palette.setColor( QPalette::Base, Qt::red);
343  } else {
344    palette.setColor( QPalette::Base, Qt::white);
345    fTempFolderPath->setText(fParentViewer->getEncoderPath());
346  }
347  fTempFolderPath->setPalette(palette);
348}
349
350
351/**
352 * If one of parameter is incorrect, put it in red and don't valid it
353 * If valid, save it
354 */
355void G4OpenGLQtMovieDialog::checkSaveFileNameParameters(QString param) {
356
357  QPalette palette( fSaveFileName->palette() );
358
359  QString temp = fParentViewer->setSaveFileName(param);
360    fSaveFileStatus->setText(temp);
361  if (temp != "") {
362    palette.setColor( QPalette::Base, Qt::red);
363  } else {
364    palette.setColor( QPalette::Base, Qt::white);
365    fSaveFileName->setText(fParentViewer->getSaveFileName());
366  }
367  fSaveFileName->setPalette(palette);
368}
369#endif
Note: See TracBrowser for help on using the repository browser.