[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); |
---|
[732] | 105 | #else |
---|
[733] | 106 | encoderHBoxLayout->addWidget(fEncoderPath); |
---|
| 107 | encoderHBoxLayout->addWidget(encoderButton); |
---|
[734] | 108 | encoderVGroupBoxLayout->addWidget(encoderHBox); |
---|
| 109 | encoderVGroupBoxLayout->addWidget(fEncoderStatus); |
---|
[732] | 110 | #endif |
---|
[730] | 111 | |
---|
[732] | 112 | #if QT_VERSION >= 0x040000 |
---|
[734] | 113 | encoderGroupBox->setLayout(encoderVGroupBoxLayout); |
---|
[732] | 114 | #endif |
---|
[733] | 115 | connect( encoderButton, SIGNAL( clicked( ) ), this, SLOT(selectEncoderPathAction() ) ); |
---|
[732] | 116 | |
---|
[730] | 117 | #if QT_VERSION < 0x040000 |
---|
[733] | 118 | globalVLayout->add(encoderGroupBox); |
---|
[730] | 119 | #else |
---|
[733] | 120 | globalVLayout->addWidget(encoderGroupBox); |
---|
[730] | 121 | #endif |
---|
| 122 | |
---|
[732] | 123 | fEncoderPath->setText(fParentViewer->getEncoderPath()); |
---|
[730] | 124 | |
---|
[732] | 125 | |
---|
[733] | 126 | // temp folder group box |
---|
| 127 | QGroupBox *tempFolderGroupBox = new QGroupBox(tr("Temporary folder path")); |
---|
[734] | 128 | QVBoxLayout *tempFolderVGroupBoxLayout = new QVBoxLayout(tempFolderGroupBox); |
---|
[733] | 129 | |
---|
[732] | 130 | // temp folder Path |
---|
[733] | 131 | QWidget *tempFolderHBox = new QWidget(tempFolderGroupBox); |
---|
[734] | 132 | QHBoxLayout *tempFolderHBoxLayout = new QHBoxLayout(tempFolderHBox); |
---|
[732] | 133 | |
---|
[733] | 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 | |
---|
[730] | 142 | #if QT_VERSION < 0x040000 |
---|
[733] | 143 | tempFolderHBoxLayout->add(fTempFolderPath); |
---|
| 144 | tempFolderHBoxLayout->add(tempButton); |
---|
[734] | 145 | tempFolderVGroupBoxLayout->add(tempFolderHBox); |
---|
| 146 | tempFolderVGroupBoxLayout->add(fTempFolderStatus); |
---|
[730] | 147 | #else |
---|
[733] | 148 | tempFolderHBoxLayout->addWidget(fTempFolderPath); |
---|
| 149 | tempFolderHBoxLayout->addWidget(tempButton); |
---|
[734] | 150 | tempFolderVGroupBoxLayout->addWidget(tempFolderHBox); |
---|
| 151 | tempFolderVGroupBoxLayout->addWidget(fTempFolderStatus); |
---|
[730] | 152 | #endif |
---|
| 153 | |
---|
[733] | 154 | #if QT_VERSION >= 0x040000 |
---|
[734] | 155 | tempFolderGroupBox->setLayout(tempFolderVGroupBoxLayout); |
---|
[733] | 156 | #endif |
---|
| 157 | connect( tempButton, SIGNAL( clicked( ) ), this, SLOT(selectTempPathAction() ) ); |
---|
[732] | 158 | |
---|
| 159 | #if QT_VERSION < 0x040000 |
---|
[733] | 160 | globalVLayout->add(tempFolderGroupBox); |
---|
[732] | 161 | #else |
---|
[733] | 162 | globalVLayout->addWidget(tempFolderGroupBox); |
---|
[732] | 163 | #endif |
---|
| 164 | |
---|
[733] | 165 | fTempFolderPath->setText(fParentViewer->getTempFolderPath()); |
---|
| 166 | |
---|
[734] | 167 | |
---|
| 168 | |
---|
[733] | 169 | // save file group box |
---|
| 170 | QGroupBox *saveFileGroupBox = new QGroupBox(tr("Save as")); |
---|
[734] | 171 | QVBoxLayout *saveFileVGroupBoxLayout = new QVBoxLayout(saveFileGroupBox); |
---|
[733] | 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 |
---|
[734] | 186 | saveFileHBoxLayout->add(fSaveFileName); |
---|
[733] | 187 | saveFileHBoxLayout->add(saveButton); |
---|
[734] | 188 | saveFileVGroupBoxLayout->add(saveFileHBox); |
---|
| 189 | saveFileVGroupBoxLayout->add(fSaveFileStatus); |
---|
[733] | 190 | #else |
---|
[734] | 191 | saveFileHBoxLayout->addWidget(fSaveFileName); |
---|
[733] | 192 | saveFileHBoxLayout->addWidget(saveButton); |
---|
[734] | 193 | saveFileVGroupBoxLayout->addWidget(saveFileHBox); |
---|
| 194 | saveFileVGroupBoxLayout->addWidget(fSaveFileStatus); |
---|
[733] | 195 | #endif |
---|
| 196 | |
---|
[730] | 197 | #if QT_VERSION >= 0x040000 |
---|
[734] | 198 | saveFileGroupBox->setLayout(saveFileVGroupBoxLayout); |
---|
[730] | 199 | #endif |
---|
[733] | 200 | connect( saveButton, SIGNAL( clicked( ) ), this, SLOT(selectSaveFileNameAction() ) ); |
---|
[730] | 201 | |
---|
| 202 | #if QT_VERSION < 0x040000 |
---|
[733] | 203 | globalVLayout->add(saveFileGroupBox); |
---|
[730] | 204 | #else |
---|
[733] | 205 | globalVLayout->addWidget(saveFileGroupBox); |
---|
[730] | 206 | #endif |
---|
| 207 | |
---|
| 208 | |
---|
[732] | 209 | // label |
---|
| 210 | |
---|
[730] | 211 | QLabel *infoLabel = new QLabel(" Press SPACE to Start/Pause video recording \n Press RETURN to Stop video recording"); |
---|
| 212 | |
---|
[733] | 213 | // global status |
---|
| 214 | fGlobalStatus = new QLabel(""); |
---|
| 215 | |
---|
[730] | 216 | #if QT_VERSION < 0x040000 |
---|
| 217 | globalVLayout->add(infoLabel); |
---|
[733] | 218 | globalVLayout->add(fGlobalStatus); |
---|
[730] | 219 | #else |
---|
| 220 | globalVLayout->addWidget(infoLabel); |
---|
[733] | 221 | globalVLayout->addWidget(fGlobalStatus); |
---|
[730] | 222 | #endif |
---|
[732] | 223 | |
---|
| 224 | // buttons |
---|
[730] | 225 | QWidget *buttonBox = new QWidget(this); |
---|
| 226 | |
---|
| 227 | QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox); |
---|
| 228 | |
---|
[732] | 229 | QPushButton *buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox ); |
---|
| 230 | buttonCancel->setAutoDefault( TRUE ); |
---|
| 231 | buttonBoxLayout->addWidget(buttonCancel); |
---|
[730] | 232 | |
---|
[733] | 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 ); |
---|
[730] | 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 |
---|
[733] | 254 | connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) ); |
---|
[730] | 255 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
[733] | 256 | connect( buttonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) ); |
---|
[730] | 257 | } |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | G4OpenGLQtMovieDialog::~G4OpenGLQtMovieDialog() |
---|
| 262 | { |
---|
| 263 | } |
---|
| 264 | |
---|
[733] | 265 | void G4OpenGLQtMovieDialog::selectEncoderPathAction() |
---|
[730] | 266 | { |
---|
| 267 | QString nomFich = QFileDialog::getOpenFileName ( this, |
---|
| 268 | "Select your encoder", |
---|
| 269 | tr("Select your encoder ...")); |
---|
| 270 | if (nomFich == "") { |
---|
| 271 | return; |
---|
| 272 | } |
---|
[733] | 273 | checkEncoderParameters(nomFich); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | void 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 | |
---|
| 287 | void 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 | |
---|
| 298 | void G4OpenGLQtMovieDialog::encode() { |
---|
[730] | 299 | } |
---|
| 300 | |
---|
[733] | 301 | /** Check all parameters |
---|
| 302 | */ |
---|
| 303 | void G4OpenGLQtMovieDialog::checkAllParameters() { |
---|
| 304 | checkEncoderParameters(fEncoderPath->text()); |
---|
| 305 | checkTempFolderParameters(fTempFolderPath->text()); |
---|
| 306 | checkSaveFileNameParameters(fSaveFileName->text()); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | /** |
---|
[732] | 310 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
[733] | 311 | * If valid, save it |
---|
[732] | 312 | */ |
---|
[733] | 313 | void G4OpenGLQtMovieDialog::checkEncoderParameters(QString param) { |
---|
[730] | 314 | |
---|
[732] | 315 | QPalette palette( fEncoderPath->palette() ); |
---|
| 316 | |
---|
[733] | 317 | QString temp = fParentViewer->setEncoderPath(param); |
---|
| 318 | fGlobalStatus->setText(""); |
---|
| 319 | fEncoderStatus->setText(temp); |
---|
| 320 | if (temp != "") { |
---|
[732] | 321 | palette.setColor( QPalette::Base, Qt::red); |
---|
[733] | 322 | fGlobalStatus->setText("If no valid encode defined, screnn /ncapture files will be saved in /nthe temp folder in ppm format."); |
---|
[732] | 323 | } else { |
---|
| 324 | palette.setColor( QPalette::Base, Qt::white); |
---|
[733] | 325 | fEncoderPath->setText(fParentViewer->getEncoderPath()); |
---|
[732] | 326 | } |
---|
| 327 | fEncoderPath->setPalette(palette); |
---|
[733] | 328 | } |
---|
[732] | 329 | |
---|
| 330 | |
---|
[733] | 331 | /** |
---|
| 332 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
| 333 | * If valid, save it |
---|
| 334 | */ |
---|
| 335 | void G4OpenGLQtMovieDialog::checkTempFolderParameters(QString param) { |
---|
[732] | 336 | |
---|
[733] | 337 | QPalette palette( fTempFolderPath->palette() ); |
---|
| 338 | |
---|
| 339 | QString temp = fParentViewer->setTempFolderPath(param); |
---|
| 340 | fTempFolderStatus->setText(temp); |
---|
| 341 | if (temp != "") { |
---|
[732] | 342 | palette.setColor( QPalette::Base, Qt::red); |
---|
| 343 | } else { |
---|
| 344 | palette.setColor( QPalette::Base, Qt::white); |
---|
[733] | 345 | fTempFolderPath->setText(fParentViewer->getEncoderPath()); |
---|
[732] | 346 | } |
---|
[733] | 347 | fTempFolderPath->setPalette(palette); |
---|
[732] | 348 | } |
---|
| 349 | |
---|
[733] | 350 | |
---|
| 351 | /** |
---|
| 352 | * If one of parameter is incorrect, put it in red and don't valid it |
---|
| 353 | * If valid, save it |
---|
| 354 | */ |
---|
| 355 | void 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 | } |
---|
[730] | 369 | #endif |
---|