[730] | 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> |
---|
[732] | 39 | #include <qpalette.h> |
---|
[730] | 40 | #include <qlabel.h> |
---|
[733] | 41 | #include <qgroupbox.h> |
---|
[730] | 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 | // + ------- + |
---|
[732] | 53 | // + Temp path + |
---|
| 54 | // + _______ + |
---|
| 55 | // + | select| ____________________ + |
---|
| 56 | // + ------- + |
---|
[730] | 57 | // + + |
---|
| 58 | // + max number of frames ________ + |
---|
| 59 | // + .... + |
---|
| 60 | // + + |
---|
| 61 | // + Label : X frames Saves/Encoding + |
---|
| 62 | // + Cancel Encode + |
---|
| 63 | // +---------------------------------------+ |
---|
| 64 | |
---|
| 65 | G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog( |
---|
[731] | 66 | G4OpenGLQtViewer* parentViewer, |
---|
| 67 | QWidget* parentWidget |
---|
[730] | 68 | ) |
---|
[731] | 69 | : QDialog( parentWidget ), |
---|
| 70 | fParentViewer(parentViewer) |
---|
[730] | 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 | |
---|
[733] | 85 | // Encoder group box |
---|
| 86 | QGroupBox *encoderGroupBox = new QGroupBox(tr("Encoder path")); |
---|
[734] | 87 | QVBoxLayout *encoderVGroupBoxLayout = new QVBoxLayout(encoderGroupBox); |
---|
[730] | 88 | |
---|
[732] | 89 | // Encoder Path |
---|
[733] | 90 | QWidget *encoderHBox = new QWidget(encoderGroupBox); |
---|
| 91 | QHBoxLayout *encoderHBoxLayout = new QHBoxLayout(encoderHBox); |
---|
| 92 | fEncoderPath = new QLineEdit("",encoderHBox); |
---|
[730] | 93 | |
---|
[733] | 94 | QPushButton *encoderButton = new QPushButton(tr("..."),encoderHBox); |
---|
[732] | 95 | encoderButton->setMaximumWidth (30); |
---|
[730] | 96 | |
---|
[733] | 97 | fEncoderStatus = new QLabel(encoderGroupBox); |
---|
| 98 | fEncoderStatus->setText(""); |
---|
| 99 | |
---|
[732] | 100 | #if QT_VERSION < 0x040000 |
---|
[733] | 101 | encoderHBoxLayout->add(fEncoderPath); |
---|
| 102 | encoderHBoxLayout->add(encoderButton); |
---|
[734] | 103 | encoderVGroupBoxLayout->add(encoderHBox); |
---|
| 104 | encoderVGroupBoxLayout->add(fEncoderStatus); |
---|
[735] | 105 | |
---|
| 106 | globalVLayout->add(encoderGroupBox); |
---|
[732] | 107 | #else |
---|
[733] | 108 | encoderHBoxLayout->addWidget(fEncoderPath); |
---|
| 109 | encoderHBoxLayout->addWidget(encoderButton); |
---|
[734] | 110 | encoderVGroupBoxLayout->addWidget(encoderHBox); |
---|
| 111 | encoderVGroupBoxLayout->addWidget(fEncoderStatus); |
---|
[730] | 112 | |
---|
[734] | 113 | encoderGroupBox->setLayout(encoderVGroupBoxLayout); |
---|
[735] | 114 | globalVLayout->addWidget(encoderGroupBox); |
---|
[732] | 115 | #endif |
---|
[735] | 116 | |
---|
[733] | 117 | connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) ); |
---|
[732] | 118 | |
---|
[730] | 119 | |
---|
[733] | 120 | // temp folder group box |
---|
| 121 | QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path")); |
---|
[734] | 122 | QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox); |
---|
[733] | 123 | |
---|
[732] | 124 | // temp folder Path |
---|
[733] | 125 | QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox); |
---|
[734] | 126 | QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox); |
---|
[732] | 127 | |
---|
[733] | 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 | |
---|
[730] | 136 | #if QT_VERSION < 0x040000 |
---|
[733] | 137 | tempFolderHBoxLayout->add(fTempFolderPath); |
---|
| 138 | tempFolderHBoxLayout->add(tempButton); |
---|
[734] | 139 | tempFolderVGroupBoxLayout->add(tempFolderHBox); |
---|
| 140 | tempFolderVGroupBoxLayout->add(fTempFolderStatus); |
---|
[735] | 141 | |
---|
| 142 | globalVLayout->add(tempFolderGroupBox); |
---|
[730] | 143 | #else |
---|
[733] | 144 | tempFolderHBoxLayout->addWidget(fTempFolderPath); |
---|
| 145 | tempFolderHBoxLayout->addWidget(tempButton); |
---|
[734] | 146 | tempFolderVGroupBoxLayout->addWidget(tempFolderHBox); |
---|
| 147 | tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus); |
---|
[730] | 148 | |
---|
[734] | 149 | tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout); |
---|
[735] | 150 | globalVLayout->addWidget(tempFolderGroupBox); |
---|
[733] | 151 | #endif |
---|
[735] | 152 | |
---|
[733] | 153 | connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) ); |
---|
[732] | 154 | |
---|
[733] | 155 | |
---|
[734] | 156 | |
---|
| 157 | |
---|
[733] | 158 | // save file group box |
---|
| 159 | QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as")); |
---|
[734] | 160 | QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox); |
---|
[733] | 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 |
---|
[734] | 175 | saveFileHBoxLayout->add(fSaveFileName); |
---|
[733] | 176 | saveFileHBoxLayout->add(saveButton); |
---|
[734] | 177 | saveFileVGroupBoxLayout->add(saveFileHBox); |
---|
| 178 | saveFileVGroupBoxLayout->add(fSaveFileStatus); |
---|
[735] | 179 | |
---|
| 180 | globalVLayout->add(saveFileGroupBox); |
---|
[733] | 181 | #else |
---|
[734] | 182 | saveFileHBoxLayout->addWidget(fSaveFileName); |
---|
[733] | 183 | saveFileHBoxLayout->addWidget(saveButton); |
---|
[734] | 184 | saveFileVGroupBoxLayout->addWidget(saveFileHBox); |
---|
| 185 | saveFileVGroupBoxLayout->addWidget(fSaveFileStatus); |
---|
[733] | 186 | |
---|
[734] | 187 | saveFileGroupBox->setLayout(saveFileVGroupBoxLayout); |
---|
[735] | 188 | globalVLayout->addWidget(saveFileGroupBox); |
---|
[730] | 189 | #endif |
---|
[735] | 190 | |
---|
[733] | 191 | connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) ); |
---|
[730] | 192 | |
---|
| 193 | |
---|
| 194 | |
---|
[732] | 195 | // label |
---|
| 196 | |
---|
[730] | 197 | QLabel *infoLabel = new QLabel(" Press SPACE to Start/Pause video recording \n Press RETURN to Stop video recording"); |
---|
| 198 | |
---|
[733] | 199 | // global status |
---|
[735] | 200 | QGroupBox *statusGroupBox = new QGroupBox(tr("Status")); |
---|
| 201 | QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox); |
---|
| 202 | fGlobalStatus = new QLabel(statusGroupBox); |
---|
[737] | 203 | setStatus(""); |
---|
[733] | 204 | |
---|
[730] | 205 | #if QT_VERSION < 0x040000 |
---|
[735] | 206 | statusVGroupBoxLayout->add(fGlobalStatus); |
---|
| 207 | |
---|
[730] | 208 | globalVLayout->add(infoLabel); |
---|
[735] | 209 | globalVLayout->add(statusGroupBox); |
---|
[730] | 210 | #else |
---|
[735] | 211 | statusVGroupBoxLayout->addWidget(fGlobalStatus); |
---|
| 212 | |
---|
| 213 | statusGroupBox->setLayout(statusVGroupBoxLayout); |
---|
[730] | 214 | globalVLayout->addWidget(infoLabel); |
---|
[735] | 215 | globalVLayout->addWidget(statusGroupBox); |
---|
[730] | 216 | #endif |
---|
[732] | 217 | |
---|
| 218 | // buttons |
---|
[730] | 219 | QWidget *buttonBox = new QWidget(this); |
---|
| 220 | |
---|
| 221 | QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox); |
---|
| 222 | |
---|
[732] | 223 | QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox ); |
---|
| 224 | buttonCancel->setAutoDefault( TRUE ); |
---|
| 225 | buttonBoxLayout->addWidget(buttonCancel); |
---|
[730] | 226 | |
---|
[733] | 227 | QPushButton *buttonApply = new QPushButton( tr( "&Apply" ),buttonBox ); |
---|
| 228 | buttonApply->setAutoDefault( TRUE ); |
---|
[736] | 229 | buttonApply->setDefault( TRUE ); |
---|
[733] | 230 | buttonBoxLayout->addWidget(buttonApply); |
---|
| 231 | |
---|
[739] | 232 | fButtonEncode = new QPushButton( tr( "&Encode" ),buttonBox ); |
---|
[740] | 233 | fButtonEncode->setEnabled(fParentViewer->getRecordFrames()); |
---|
[739] | 234 | fButtonEncode->setAutoDefault( TRUE ); |
---|
| 235 | buttonBoxLayout->addWidget(fButtonEncode); |
---|
[730] | 236 | |
---|
| 237 | #if QT_VERSION >= 0x040000 |
---|
| 238 | buttonBox->setLayout(buttonBoxLayout); |
---|
| 239 | #endif |
---|
| 240 | globalVLayout->addWidget(buttonBox); |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | #if QT_VERSION >= 0x040000 |
---|
| 245 | setLayout(globalVLayout); |
---|
| 246 | #endif |
---|
| 247 | |
---|
| 248 | // signals and slots connections |
---|
[733] | 249 | connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) ); |
---|
[730] | 250 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
[739] | 251 | connect( fButtonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) ); |
---|
[737] | 252 | |
---|
| 253 | // fill |
---|
| 254 | fEncoderPath->setText(fParentViewer->getEncoderPath()); |
---|
| 255 | fTempFolderPath->setText(fParentViewer->getTempFolderPath()); |
---|
| 256 | |
---|
| 257 | if (fParentViewer->getEncoderPath() == "") { |
---|
| 258 | setStatus("mpeg_encode is needed to encode in video format.\nIt is available here: \nhttp://bmrc.berkeley.edu/frame/research/mpeg/"); |
---|
| 259 | } |
---|
| 260 | |
---|
[730] | 261 | } |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog() |
---|
| 266 | { |
---|
| 267 | } |
---|
| 268 | |
---|
[733] | 269 | void G4OpenGLQtMovieDialog::selectEncoderPathAction() |
---|
[730] | 270 | { |
---|
| 271 | QString nomFich = QFileDialog::getOpenFileName ( this, |
---|
| 272 | "Select your encoder", |
---|
| 273 | tr("Select your encoder ...")); |
---|
| 274 | if (nomFich == "") { |
---|
| 275 | return; |
---|
| 276 | } |
---|
[733] | 277 | checkEncoderParameters(nomFich); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | void G4OpenGLQtMovieDialog::selectTempPathAction() |
---|
| 281 | { |
---|
| 282 | QString nomFich = QFileDialog::getOpenFileName ( this, |
---|
| 283 | "Select temporary folder", |
---|
| 284 | tr("Select temporary folder ...")); |
---|
| 285 | if (nomFich == "") { |
---|
| 286 | return; |
---|
| 287 | } |
---|
| 288 | checkTempFolderParameters(nomFich); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | void G4OpenGLQtMovieDialog::selectSaveFileNameAction() |
---|
| 292 | { |
---|
[742] | 293 | QString nomFich = QFileDialog::getSaveFileName ( this, |
---|
[733] | 294 | "Select saved file", |
---|
| 295 | tr("Select saved file ...")); |
---|
| 296 | if (nomFich == "") { |
---|
| 297 | return; |
---|
| 298 | } |
---|
| 299 | checkSaveFileNameParameters(nomFich); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | void G4OpenGLQtMovieDialog::encode() { |
---|
[730] | 303 | } |
---|
| 304 | |
---|
[733] | 305 | /** Check all parameters |
---|
| 306 | */ |
---|
| 307 | void G4OpenGLQtMovieDialog::checkAllParameters() { |
---|
| 308 | checkEncoderParameters(fEncoderPath->text()); |
---|
| 309 | checkTempFolderParameters(fTempFolderPath->text()); |
---|
| 310 | checkSaveFileNameParameters(fSaveFileName->text()); |
---|
[740] | 311 | |
---|
| 312 | // set state of encode button |
---|
| 313 | // if frames had been generated and parameters are valid : enabled encode button |
---|
| 314 | // if ((fParentViewer->getRecordFrames() == false) && (fRecordFrameNumber >1)) { |
---|
| 315 | // } |
---|
| 316 | |
---|
[733] | 317 | } |
---|
| 318 | |
---|
| 319 | /** |
---|
[732] | 320 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
[733] | 321 | * If valid, save it |
---|
[732] | 322 | */ |
---|
[733] | 323 | void G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) { |
---|
[730] | 324 | |
---|
[732] | 325 | QPalette palette( fEncoderPath->palette() ); |
---|
| 326 | |
---|
[733] | 327 | QString temp = fParentViewer->setEncoderPath(param); |
---|
[737] | 328 | setStatus(""); |
---|
[740] | 329 | fEncoderStatus->setText(temp); |
---|
[733] | 330 | if (temp != "") { |
---|
[732] | 331 | palette.setColor( QPalette::Base, Qt::red); |
---|
[737] | 332 | setStatus("If no valid encode defined, screen \ncapture files will be saved in the\ntemp folder in ppm format."); |
---|
[732] | 333 | } else { |
---|
| 334 | palette.setColor( QPalette::Base, Qt::white); |
---|
[733] | 335 | fEncoderPath->setText(fParentViewer->getEncoderPath()); |
---|
[737] | 336 | if (fParentViewer->getEncoderPath() == "") { |
---|
| 337 | setStatus("mpeg_encode is needed to encode in video format.\nIt is available here: \nhttp://bmrc.berkeley.edu/frame/research/mpeg/"); |
---|
| 338 | } |
---|
[732] | 339 | } |
---|
| 340 | fEncoderPath->setPalette(palette); |
---|
[733] | 341 | } |
---|
[732] | 342 | |
---|
| 343 | |
---|
[733] | 344 | /** |
---|
| 345 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
| 346 | * If valid, save it |
---|
| 347 | */ |
---|
| 348 | void G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) { |
---|
[732] | 349 | |
---|
[733] | 350 | QPalette palette( fTempFolderPath->palette() ); |
---|
| 351 | |
---|
| 352 | QString temp = fParentViewer->setTempFolderPath(param); |
---|
[736] | 353 | fTempFolderStatus->setText(temp); |
---|
| 354 | if (temp != "") { |
---|
[732] | 355 | palette.setColor( QPalette::Base, Qt::red); |
---|
| 356 | } else { |
---|
| 357 | palette.setColor( QPalette::Base, Qt::white); |
---|
[736] | 358 | fTempFolderPath->setText(fParentViewer->getTempFolderPath()); |
---|
[732] | 359 | } |
---|
[733] | 360 | fTempFolderPath->setPalette(palette); |
---|
[732] | 361 | } |
---|
| 362 | |
---|
[733] | 363 | |
---|
| 364 | /** |
---|
| 365 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
| 366 | * If valid, save it |
---|
| 367 | */ |
---|
| 368 | void G4OpenGLQtMovieDialog::checkSaveFileNameParameters(QString param) { |
---|
| 369 | |
---|
| 370 | QPalette palette( fSaveFileName->palette() ); |
---|
| 371 | |
---|
| 372 | QString temp = fParentViewer->setSaveFileName(param); |
---|
| 373 | fSaveFileStatus->setText(temp); |
---|
| 374 | if (temp != "") { |
---|
| 375 | palette.setColor( QPalette::Base, Qt::red); |
---|
| 376 | } else { |
---|
| 377 | palette.setColor( QPalette::Base, Qt::white); |
---|
| 378 | fSaveFileName->setText(fParentViewer->getSaveFileName()); |
---|
| 379 | } |
---|
| 380 | fSaveFileName->setPalette(palette); |
---|
| 381 | } |
---|
[737] | 382 | |
---|
| 383 | |
---|
| 384 | void G4OpenGLQtMovieDialog::setStatus(QString txt) { |
---|
| 385 | fGlobalStatus->setText(txt); |
---|
| 386 | } |
---|
| 387 | |
---|
[740] | 388 | void G4OpenGLQtMovieDialog::setEncodeButtonEnabled(bool b) { |
---|
| 389 | fButtonEncode->setEnabled(b); |
---|
| 390 | } |
---|
[730] | 391 | #endif |
---|