[581] | 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 | // |
---|
[606] | 27 | // $Id: G4OpenGLQtExportDialog.cc,v 1.4 2007/11/13 17:48:51 lgarnier Exp $ |
---|
[593] | 28 | // GEANT4 tag $Name: $ |
---|
[581] | 29 | // |
---|
| 30 | // |
---|
| 31 | |
---|
[633] | 32 | #define GEANT4_QT_DEBUG |
---|
[581] | 33 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER |
---|
| 34 | |
---|
| 35 | #include "G4OpenGLQtExportDialog.hh" |
---|
| 36 | |
---|
[595] | 37 | #include <qvariant.h> |
---|
| 38 | #include <qpushbutton.h> |
---|
| 39 | #include <qcheckbox.h> |
---|
| 40 | #include <qlabel.h> |
---|
| 41 | #include <qcombobox.h> |
---|
| 42 | #include <qslider.h> |
---|
| 43 | #include <qlayout.h> |
---|
| 44 | #include <qgroupbox.h> |
---|
| 45 | #include <qradiobutton.h> |
---|
| 46 | #include <qimage.h> |
---|
| 47 | #include <qlineedit.h> |
---|
[633] | 48 | #include <qbuttongroup.h> |
---|
[581] | 49 | |
---|
| 50 | G4OpenGLQtExportDialog::G4OpenGLQtExportDialog( |
---|
| 51 | QWidget* parent |
---|
[583] | 52 | ,QString nomFich |
---|
| 53 | ,int aHeight |
---|
| 54 | ,int aWidth |
---|
| 55 | ) |
---|
[581] | 56 | : QDialog( parent ) |
---|
| 57 | { |
---|
[599] | 58 | #if QT_VERSION < 0x040000 |
---|
| 59 | setCaption( tr( " Export options" )); |
---|
| 60 | #else |
---|
[582] | 61 | setWindowTitle( tr( " Export options" )); |
---|
[599] | 62 | #endif |
---|
[583] | 63 | originalWidth = aWidth; |
---|
| 64 | originalHeight = aHeight; |
---|
| 65 | |
---|
[593] | 66 | // Initializations |
---|
| 67 | qualitySlider = NULL; |
---|
| 68 | width = NULL; |
---|
| 69 | height = NULL; |
---|
| 70 | colorButton = NULL; |
---|
| 71 | BWButton = NULL; |
---|
| 72 | |
---|
[583] | 73 | // global layout |
---|
[599] | 74 | QVBoxLayout* globalVLayout = new QVBoxLayout(this); |
---|
[583] | 75 | |
---|
[581] | 76 | |
---|
[585] | 77 | if (nomFich.endsWith(".jpg") || |
---|
| 78 | nomFich.endsWith(".jepg")) { |
---|
[581] | 79 | |
---|
[633] | 80 | QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this); |
---|
[599] | 81 | QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout(imageGroupBox); |
---|
[635] | 82 | QWidget *sliderBox = new QWidget(); |
---|
[583] | 83 | |
---|
[635] | 84 | QHBoxLayout *hSliderLayout = new QHBoxLayout(sliderBox); |
---|
[599] | 85 | |
---|
[582] | 86 | // qualityLabel = new QLabel( tr( "Image quality" ) ); |
---|
[583] | 87 | // imageGroupBoxLayout->addWidget(qualityLabel); |
---|
[635] | 88 | qualitySlider= new QSlider(Qt::Horizontal,sliderBox); |
---|
[599] | 89 | #if QT_VERSION < 0x040000 |
---|
| 90 | qualitySlider->setMinValue(0); |
---|
| 91 | qualitySlider->setMaxValue(100); |
---|
| 92 | qualitySlider->setTickmarks(QSlider::Below); |
---|
| 93 | #else |
---|
[582] | 94 | qualitySlider->setMinimum(0); |
---|
| 95 | qualitySlider->setMaximum(100); |
---|
| 96 | qualitySlider->setTickPosition(QSlider::TicksBelow); |
---|
[599] | 97 | #endif |
---|
[582] | 98 | qualitySlider->setValue(60); |
---|
[635] | 99 | hSliderLayout->addWidget(new QLabel("low",sliderBox)); |
---|
| 100 | hSliderLayout->addWidget(qualitySlider); |
---|
| 101 | hSliderLayout->addWidget(new QLabel("Maximum",sliderBox)); |
---|
[599] | 102 | #if QT_VERSION >= 0x040000 |
---|
[635] | 103 | sliderBox->setLayout(hSliderLayout); |
---|
[599] | 104 | #endif |
---|
[583] | 105 | imageGroupBoxLayout->addWidget(sliderBox); |
---|
| 106 | |
---|
[599] | 107 | #if QT_VERSION >= 0x040000 |
---|
[583] | 108 | imageGroupBox->setLayout(imageGroupBoxLayout); |
---|
[599] | 109 | #endif |
---|
[583] | 110 | globalVLayout->addWidget(imageGroupBox); |
---|
[581] | 111 | } |
---|
| 112 | |
---|
[589] | 113 | if(nomFich.endsWith(".eps")) { |
---|
[599] | 114 | |
---|
[589] | 115 | // transparencyEPS = new QCheckBox( "transparencyEPS" ); |
---|
| 116 | // transparencyEPS->setText( "save background" ); |
---|
| 117 | // transparencyEPS->setChecked( true ); |
---|
[583] | 118 | |
---|
[633] | 119 | QWidget * EPSWidgetGroupBox; // widget containing group button |
---|
| 120 | QButtonGroup * EPSButtonGroupBox; // group button |
---|
[635] | 121 | |
---|
| 122 | |
---|
[633] | 123 | #if QT_VERSION < 0x040000 |
---|
[635] | 124 | colorButton = new QRadioButton("Color",EPSWidgetGroupBox); |
---|
| 125 | BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); |
---|
[633] | 126 | EPSButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this); |
---|
| 127 | EPSButtonGroupBox->insert(colorButton); |
---|
| 128 | EPSButtonGroupBox->insert(BWButton); |
---|
| 129 | EPSButtonGroupBox->setExclusive(true); |
---|
| 130 | EPSWidgetGroupBox = EPSButtonGroupBox; |
---|
[583] | 131 | |
---|
[633] | 132 | #else |
---|
| 133 | EPSWidgetGroupBox = new QGroupBox(tr("EPS options")); |
---|
| 134 | QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox); |
---|
[635] | 135 | |
---|
| 136 | colorButton = new QRadioButton("Color",EPSWidgetGroupBox); |
---|
| 137 | BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); |
---|
| 138 | |
---|
[633] | 139 | EPSButtonGroupBox = new QButtonGroup(); |
---|
| 140 | EPSButtonGroupBox->addButton(colorButton); |
---|
| 141 | EPSButtonGroupBox->addButton(BWButton); |
---|
| 142 | EPSButtonGroupBox->setExclusive(true); |
---|
[583] | 143 | |
---|
[593] | 144 | EPSGroupBoxLayout->addWidget(colorButton); |
---|
| 145 | EPSGroupBoxLayout->addWidget(BWButton); |
---|
[633] | 146 | EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout); |
---|
| 147 | |
---|
[599] | 148 | #endif |
---|
[635] | 149 | colorButton->setChecked( true ); |
---|
[583] | 150 | |
---|
[633] | 151 | // EPSGroupBoxLayout->addWidget(transparencyEPS); |
---|
| 152 | globalVLayout->addWidget(EPSWidgetGroupBox); |
---|
| 153 | |
---|
[581] | 154 | } |
---|
| 155 | |
---|
| 156 | if(nomFich.endsWith(".tif") || |
---|
| 157 | nomFich.endsWith(".tiff") || |
---|
[582] | 158 | nomFich.endsWith(".jpg") || |
---|
[581] | 159 | nomFich.endsWith(".png") || |
---|
| 160 | nomFich.endsWith(".xpm")) { |
---|
[583] | 161 | |
---|
[633] | 162 | QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this); |
---|
[599] | 163 | QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox); |
---|
[583] | 164 | |
---|
[635] | 165 | boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox); |
---|
[581] | 166 | boxTransparency->setChecked( false ); |
---|
[583] | 167 | // boxTransparency->setEnabled(false); |
---|
| 168 | |
---|
| 169 | transparencyGroupBoxLayout->addWidget(boxTransparency); |
---|
[599] | 170 | #if QT_VERSION >= 0x040000 |
---|
[583] | 171 | transparencyGroupBox->setLayout(transparencyGroupBoxLayout); |
---|
[599] | 172 | #endif |
---|
[583] | 173 | globalVLayout->addWidget(transparencyGroupBox); |
---|
| 174 | |
---|
[581] | 175 | } |
---|
| 176 | |
---|
[584] | 177 | // size box |
---|
[635] | 178 | QWidget* modifyAndRatioWidget = new QWidget(); |
---|
[584] | 179 | |
---|
[599] | 180 | QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget); |
---|
| 181 | |
---|
[633] | 182 | QWidget * sizeWidgetGroupBox; // widget containing group button |
---|
| 183 | QButtonGroup * sizeButtonGroupBox; // group button |
---|
| 184 | QLayout *sizeGroupBoxLayout; |
---|
| 185 | #if QT_VERSION < 0x040000 |
---|
| 186 | sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this); |
---|
| 187 | |
---|
| 188 | original = new QRadioButton("Original",sizeButtonGroupBox); |
---|
| 189 | modify = new QRadioButton("Modify",sizeButtonGroupBox); |
---|
| 190 | |
---|
| 191 | sizeButtonGroupBox->insert(original); |
---|
| 192 | sizeButtonGroupBox->insert(modify); |
---|
| 193 | sizeButtonGroupBox->setExclusive(true); |
---|
| 194 | sizeWidgetGroupBox = sizeButtonGroupBox; |
---|
| 195 | sizeGroupBoxLayout = sizeWidgetGroupBox->layout(); |
---|
[584] | 196 | |
---|
[633] | 197 | #else |
---|
| 198 | |
---|
| 199 | sizeWidgetGroupBox = new QGroupBox(tr("Size")); |
---|
| 200 | sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox); |
---|
| 201 | sizeButtonGroupBox = new QButtonGroup(); |
---|
[584] | 202 | |
---|
[633] | 203 | original = new QRadioButton("Original"); |
---|
| 204 | modify = new QRadioButton("Modify"); |
---|
| 205 | |
---|
| 206 | sizeButtonGroupBox->addButton(modify); |
---|
| 207 | sizeButtonGroupBox->addButton(original); |
---|
| 208 | sizeButtonGroupBox->setExclusive(true); |
---|
| 209 | |
---|
| 210 | sizeGroupBoxLayout->addWidget(modify); |
---|
| 211 | sizeGroupBoxLayout->addWidget(original); |
---|
| 212 | |
---|
| 213 | sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout); |
---|
| 214 | #endif |
---|
[635] | 215 | original->setChecked( true ); |
---|
[633] | 216 | |
---|
| 217 | |
---|
| 218 | ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget); |
---|
[584] | 219 | ratioCheckBox->setChecked( true ); |
---|
| 220 | |
---|
| 221 | modifyAndRatioLayout->addWidget(modify); |
---|
| 222 | modifyAndRatioLayout->addWidget(ratioCheckBox); |
---|
[599] | 223 | #if QT_VERSION >= 0x040000 |
---|
[584] | 224 | modifyAndRatioWidget->setLayout(modifyAndRatioLayout); |
---|
[599] | 225 | #endif |
---|
[633] | 226 | #if QT_VERSION < 0x040000 |
---|
| 227 | sizeGroupBoxLayout->add(modifyAndRatioWidget); |
---|
| 228 | #else |
---|
[584] | 229 | sizeGroupBoxLayout->addWidget(modifyAndRatioWidget); |
---|
[633] | 230 | #endif |
---|
[599] | 231 | if (modify->isChecked()) { |
---|
| 232 | ratioCheckBox->show(); |
---|
| 233 | } else { |
---|
| 234 | ratioCheckBox->hide(); |
---|
| 235 | } |
---|
[584] | 236 | |
---|
[633] | 237 | #if QT_VERSION < 0x040000 |
---|
| 238 | connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
| 239 | #else |
---|
| 240 | connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
| 241 | #endif |
---|
[581] | 242 | |
---|
[584] | 243 | // height |
---|
[635] | 244 | heightWidget = new QWidget(); |
---|
[599] | 245 | |
---|
| 246 | QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget); |
---|
| 247 | |
---|
[583] | 248 | QString tmp; |
---|
| 249 | |
---|
[635] | 250 | heightLineLayout->addWidget(new QLabel("Height",heightWidget)); |
---|
| 251 | height = new QLineEdit(tmp.setNum(originalHeight),heightWidget); |
---|
[583] | 252 | height->setMaxLength(5); |
---|
[633] | 253 | #if QT_VERSION < 0x040000 |
---|
| 254 | heightLineLayout->add(height); |
---|
| 255 | #else |
---|
[583] | 256 | heightLineLayout->addWidget(height); |
---|
[633] | 257 | #endif |
---|
[599] | 258 | #if QT_VERSION >= 0x040000 |
---|
[583] | 259 | heightWidget->setLayout(heightLineLayout); |
---|
[599] | 260 | #endif |
---|
[633] | 261 | #if QT_VERSION < 0x040000 |
---|
| 262 | sizeGroupBoxLayout->add(heightWidget); |
---|
| 263 | #else |
---|
[583] | 264 | sizeGroupBoxLayout->addWidget(heightWidget); |
---|
[633] | 265 | #endif |
---|
[584] | 266 | connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) ); |
---|
[581] | 267 | |
---|
[584] | 268 | |
---|
| 269 | // width |
---|
[635] | 270 | widthWidget = new QWidget(); |
---|
[583] | 271 | |
---|
[633] | 272 | QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget); |
---|
| 273 | |
---|
[599] | 274 | #if QT_VERSION < 0x040000 |
---|
[633] | 275 | widthLineLayout->add(new QLabel("Width ",widthWidget)); |
---|
[599] | 276 | #else |
---|
[633] | 277 | widthLineLayout->addWidget(new QLabel("Width ",widthWidget)); |
---|
[599] | 278 | #endif |
---|
[635] | 279 | width = new QLineEdit(tmp.setNum(originalWidth),widthWidget); |
---|
[583] | 280 | width->setMaxLength(5); |
---|
[633] | 281 | #if QT_VERSION < 0x040000 |
---|
| 282 | widthLineLayout->add(width); |
---|
| 283 | #else |
---|
[583] | 284 | widthLineLayout->addWidget(width); |
---|
[633] | 285 | #endif |
---|
[599] | 286 | #if QT_VERSION >= 0x040000 |
---|
[583] | 287 | widthWidget->setLayout(widthLineLayout); |
---|
[599] | 288 | #endif |
---|
[633] | 289 | #if QT_VERSION < 0x040000 |
---|
| 290 | sizeGroupBoxLayout->add(widthWidget); |
---|
| 291 | #else |
---|
[583] | 292 | sizeGroupBoxLayout->addWidget(widthWidget); |
---|
[633] | 293 | #endif |
---|
[584] | 294 | connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) ); |
---|
[583] | 295 | |
---|
[599] | 296 | #if QT_VERSION >= 0x040000 |
---|
[633] | 297 | sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout); |
---|
[599] | 298 | #endif |
---|
[633] | 299 | globalVLayout->addWidget(sizeWidgetGroupBox); |
---|
[583] | 300 | |
---|
[599] | 301 | heightWidget->hide(); |
---|
| 302 | widthWidget->hide(); |
---|
[583] | 303 | |
---|
[584] | 304 | // button ok/cancel box |
---|
[583] | 305 | |
---|
[633] | 306 | QGroupBox *buttonGroupBox = new QGroupBox(this); |
---|
[599] | 307 | |
---|
| 308 | QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox); |
---|
[583] | 309 | |
---|
[633] | 310 | buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox ); |
---|
[581] | 311 | buttonOk->setAutoDefault( TRUE ); |
---|
| 312 | buttonOk->setDefault( TRUE ); |
---|
[583] | 313 | buttonGroupBoxLayout->addWidget(buttonOk); |
---|
[581] | 314 | |
---|
[633] | 315 | buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox ); |
---|
[581] | 316 | buttonCancel->setAutoDefault( TRUE ); |
---|
[583] | 317 | buttonGroupBoxLayout->addWidget(buttonCancel); |
---|
[581] | 318 | |
---|
[599] | 319 | #if QT_VERSION >= 0x040000 |
---|
[583] | 320 | buttonGroupBox->setLayout(buttonGroupBoxLayout); |
---|
[599] | 321 | #endif |
---|
[583] | 322 | globalVLayout->addWidget(buttonGroupBox); |
---|
[581] | 323 | |
---|
| 324 | |
---|
[599] | 325 | #if QT_VERSION >= 0x040000 |
---|
[583] | 326 | setLayout(globalVLayout); |
---|
[599] | 327 | #endif |
---|
[583] | 328 | |
---|
[581] | 329 | // signals and slots connections |
---|
| 330 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
---|
| 331 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
[582] | 336 | int G4OpenGLQtExportDialog::getSliderValue() |
---|
| 337 | { |
---|
[593] | 338 | if (!qualitySlider) return -1; |
---|
[582] | 339 | return qualitySlider->value(); |
---|
| 340 | } |
---|
| 341 | |
---|
[585] | 342 | int G4OpenGLQtExportDialog::getHeight() |
---|
| 343 | { |
---|
[593] | 344 | if (!height) return -1; |
---|
[585] | 345 | return height->text().toInt(); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | int G4OpenGLQtExportDialog::getWidth() |
---|
| 349 | { |
---|
[593] | 350 | if (!width) return -1; |
---|
[585] | 351 | return width->text().toInt(); |
---|
| 352 | } |
---|
| 353 | |
---|
[593] | 354 | bool G4OpenGLQtExportDialog::getTransparency() |
---|
[586] | 355 | { |
---|
[593] | 356 | if (!boxTransparency) return -1; |
---|
[586] | 357 | return boxTransparency->isChecked(); |
---|
| 358 | } |
---|
[585] | 359 | |
---|
[587] | 360 | int G4OpenGLQtExportDialog::getNbColor() |
---|
[581] | 361 | { |
---|
[587] | 362 | // Black and white |
---|
[593] | 363 | if (!colorButton->isChecked()) |
---|
[586] | 364 | return 1; |
---|
[587] | 365 | // rgb color |
---|
[586] | 366 | return 3; |
---|
[583] | 367 | } |
---|
[581] | 368 | |
---|
[586] | 369 | |
---|
[633] | 370 | void G4OpenGLQtExportDialog::changeSizeBox() |
---|
[586] | 371 | { |
---|
| 372 | if ( original->isChecked()) { |
---|
[599] | 373 | heightWidget->hide(); |
---|
| 374 | widthWidget->hide(); |
---|
| 375 | ratioCheckBox->hide(); |
---|
[586] | 376 | } else { |
---|
[599] | 377 | heightWidget->show(); |
---|
| 378 | widthWidget->show(); |
---|
| 379 | ratioCheckBox->show(); |
---|
[586] | 380 | } |
---|
| 381 | } |
---|
| 382 | |
---|
[584] | 383 | void G4OpenGLQtExportDialog::textWidthChanged( |
---|
| 384 | const QString & s |
---|
| 385 | ) |
---|
[583] | 386 | { |
---|
[584] | 387 | if (ratioCheckBox->isChecked()){ |
---|
| 388 | QString tmp; |
---|
| 389 | width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight)); |
---|
| 390 | } |
---|
[581] | 391 | } |
---|
| 392 | |
---|
[584] | 393 | void G4OpenGLQtExportDialog:: textHeightChanged( |
---|
| 394 | const QString & s |
---|
| 395 | ) |
---|
| 396 | { |
---|
| 397 | if (ratioCheckBox->isChecked()){ |
---|
| 398 | QString tmp; |
---|
| 399 | width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth)); |
---|
| 400 | } |
---|
| 401 | } |
---|
[581] | 402 | |
---|
| 403 | G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog() |
---|
| 404 | { |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | #endif |
---|