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