Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id$ 27 // 28 // 28 // << 29 // >> 30 >> 31 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER 29 32 30 #include "G4OpenGLQtExportDialog.hh" 33 #include "G4OpenGLQtExportDialog.hh" 31 34 32 #include <qvariant.h> 35 #include <qvariant.h> 33 #include <qpushbutton.h> 36 #include <qpushbutton.h> 34 #include <qcheckbox.h> 37 #include <qcheckbox.h> 35 #include <qlabel.h> 38 #include <qlabel.h> 36 #include <qcombobox.h> 39 #include <qcombobox.h> 37 #include <qslider.h> 40 #include <qslider.h> 38 #include <qlayout.h> 41 #include <qlayout.h> 39 #include <qgroupbox.h> 42 #include <qgroupbox.h> 40 #include <qradiobutton.h> 43 #include <qradiobutton.h> 41 #include <qimage.h> 44 #include <qimage.h> 42 #include <qlineedit.h> 45 #include <qlineedit.h> 43 #include <qbuttongroup.h> 46 #include <qbuttongroup.h> 44 47 45 #ifndef G4GMAKE << 46 #include "moc_G4OpenGLQtExportDialog.cpp" << 47 #endif << 48 << 49 G4OpenGLQtExportDialog::G4OpenGLQtExportDialog 48 G4OpenGLQtExportDialog::G4OpenGLQtExportDialog( 50 QWidget* parentw 49 QWidget* parentw 51 ,QString format 50 ,QString format 52 ,int aHeight 51 ,int aHeight 53 ,int aWidth 52 ,int aWidth 54 ) 53 ) 55 : QDialog( parentw ), 54 : QDialog( parentw ), 56 isChangingSize(false) 55 isChangingSize(false) 57 { 56 { 58 setWindowTitle( tr( " Export options" )); 57 setWindowTitle( tr( " Export options" )); 59 originalWidth = aWidth; 58 originalWidth = aWidth; 60 originalHeight = aHeight; 59 originalHeight = aHeight; 61 60 62 // Initializations 61 // Initializations 63 vectorEPSCheckBox = NULL; << 64 qualitySlider = NULL; 62 qualitySlider = NULL; 65 width = NULL; 63 width = NULL; 66 height = NULL; 64 height = NULL; 67 colorButton = NULL; 65 colorButton = NULL; 68 BWButton = NULL; 66 BWButton = NULL; 69 67 70 // global layout 68 // global layout 71 QVBoxLayout* globalVLayout = new QVBoxLayout 69 QVBoxLayout* globalVLayout = new QVBoxLayout(this); 72 globalVLayout->setContentsMargins(10,10,10,1 << 70 globalVLayout->setMargin(10); 73 globalVLayout->setSpacing(10); 71 globalVLayout->setSpacing(10); 74 << 72 75 73 76 74 77 75 78 // size box 76 // size box 79 77 80 QWidget * sizeWidget = new QWidget(this); // 78 QWidget * sizeWidget = new QWidget(this); // widget containing group button 81 QVBoxLayout * sizeWidgetLayout = new QVBoxLa 79 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget); 82 sizeWidgetLayout->setContentsMargins(10,10,1 << 80 sizeWidgetLayout->setMargin (10); 83 81 84 // original and modify radiobuttons 82 // original and modify radiobuttons 85 << 83 86 sizeGroupBox = new QGroupBox(tr("Size")); 84 sizeGroupBox = new QGroupBox(tr("Size")); 87 QVBoxLayout *sizeGroupBoxLayout = new QVBoxL 85 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox); 88 QButtonGroup * sizeButtonGroupBox = new QBut 86 QButtonGroup * sizeButtonGroupBox = new QButtonGroup(); 89 sizeGroupBoxLayout->setContentsMargins(15,15 << 87 sizeGroupBoxLayout->setMargin (15); 90 88 91 original = new QRadioButton("Original"); 89 original = new QRadioButton("Original"); 92 modify = new QRadioButton("Modify"); 90 modify = new QRadioButton("Modify"); 93 91 94 sizeButtonGroupBox->addButton(original); 92 sizeButtonGroupBox->addButton(original); 95 sizeButtonGroupBox->addButton(modify); 93 sizeButtonGroupBox->addButton(modify); 96 sizeButtonGroupBox->setExclusive(true); 94 sizeButtonGroupBox->setExclusive(true); 97 95 98 sizeGroupBoxLayout->addWidget(original); << 96 sizeGroupBoxLayout->addWidget(original); 99 sizeGroupBoxLayout->addWidget(modify); << 97 sizeGroupBoxLayout->addWidget(modify); 100 98 101 sizeGroupBox->setLayout(sizeGroupBoxLayout); 99 sizeGroupBox->setLayout(sizeGroupBoxLayout); 102 sizeWidgetLayout->addWidget(sizeGroupBox); 100 sizeWidgetLayout->addWidget(sizeGroupBox); 103 << 101 104 connect( sizeButtonGroupBox, SIGNAL( buttonC 102 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) ); 105 original->setChecked( true ); 103 original->setChecked( true ); 106 104 107 105 108 // height 106 // height 109 heightWidget = new QWidget(sizeWidget); 107 heightWidget = new QWidget(sizeWidget); 110 108 111 QHBoxLayout *heightLineLayout = new QHBoxLay 109 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget); 112 110 113 QString tmp; 111 QString tmp; 114 << 112 115 heightLineLayout->addWidget(new QLabel("Heig 113 heightLineLayout->addWidget(new QLabel("Height",heightWidget)); 116 height = new QLineEdit(tmp.setNum(originalHe 114 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget); 117 height->setMaxLength(5); 115 height->setMaxLength(5); 118 heightLineLayout->addWidget(height); 116 heightLineLayout->addWidget(height); 119 117 120 heightWidget->setLayout(heightLineLayout); 118 heightWidget->setLayout(heightLineLayout); 121 119 122 sizeWidgetLayout->addWidget(heightWidget); 120 sizeWidgetLayout->addWidget(heightWidget); 123 connect( height, SIGNAL( textChanged ( const 121 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) ); 124 122 125 123 126 // width 124 // width 127 widthWidget = new QWidget(sizeWidget); 125 widthWidget = new QWidget(sizeWidget); 128 126 129 QHBoxLayout *widthLineLayout = new QHBoxLayo 127 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget); 130 128 131 widthLineLayout->addWidget(new QLabel("Width 129 widthLineLayout->addWidget(new QLabel("Width ",widthWidget)); 132 width = new QLineEdit(tmp.setNum(originalWid 130 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget); 133 width->setMaxLength(5); 131 width->setMaxLength(5); 134 widthLineLayout->addWidget(width); 132 widthLineLayout->addWidget(width); 135 widthWidget->setLayout(widthLineLayout); 133 widthWidget->setLayout(widthLineLayout); 136 sizeWidgetLayout->addWidget(widthWidget); 134 sizeWidgetLayout->addWidget(widthWidget); 137 connect( width, SIGNAL( textChanged ( const 135 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) ); 138 136 139 137 140 138 141 // ratio check box 139 // ratio check box 142 140 143 ratioCheckBox = new QCheckBox( "Keep ratio", 141 ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget); 144 ratioCheckBox->setChecked( true ); 142 ratioCheckBox->setChecked( true ); 145 143 146 sizeWidgetLayout->addWidget(ratioCheckBox); 144 sizeWidgetLayout->addWidget(ratioCheckBox); 147 145 148 ratioCheckBox->hide(); 146 ratioCheckBox->hide(); 149 heightWidget->hide(); 147 heightWidget->hide(); 150 widthWidget->hide(); 148 widthWidget->hide(); 151 149 152 sizeWidget->setLayout(sizeWidgetLayout); 150 sizeWidget->setLayout(sizeWidgetLayout); 153 globalVLayout->addWidget(sizeWidget); 151 globalVLayout->addWidget(sizeWidget); 154 152 155 if (format == "eps") { 153 if (format == "eps") { 156 154 157 QGroupBox *EPSWidgetGroupBox = new QGroupBo 155 QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button 158 156 159 157 160 QVBoxLayout * EPSGroupBoxLayout = new QVBo 158 QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox); 161 EPSGroupBoxLayout->setContentsMargins(15, << 159 EPSGroupBoxLayout->setMargin (15); 162 160 163 // colorButton = new QRadioButton("Color", 161 // colorButton = new QRadioButton("Color",EPSWidgetGroupBox); 164 // BWButton = new QRadioButton("Grayscale" 162 // BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); 165 163 166 // QButtonGroup * EPSColorButtonGroupBox = 164 // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup(); 167 // EPSColorButtonGroupBox->addButton(color 165 // EPSColorButtonGroupBox->addButton(colorButton); 168 // EPSColorButtonGroupBox->addButton(BWBut 166 // EPSColorButtonGroupBox->addButton(BWButton); 169 // EPSColorButtonGroupBox->setExclusive(tr 167 // EPSColorButtonGroupBox->setExclusive(true); 170 168 171 // EPSGroupBoxLayout->addWidget(colorButto << 169 // EPSGroupBoxLayout->addWidget(colorButton); 172 // EPSGroupBoxLayout->addWidget(BWButton); << 170 // EPSGroupBoxLayout->addWidget(BWButton); 173 171 174 vectorEPSCheckBox = new QCheckBox( "Vector 172 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox); 175 EPSGroupBoxLayout->addWidget(vectorEPSChec 173 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox); 176 174 177 EPSWidgetGroupBox->setLayout(EPSGroupBoxLa 175 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout); 178 // colorButton->setChecked( true ); 176 // colorButton->setChecked( true ); 179 vectorEPSCheckBox->setChecked( true ); 177 vectorEPSCheckBox->setChecked( true ); 180 << 178 181 globalVLayout->addWidget(EPSWidgetGroupBox 179 globalVLayout->addWidget(EPSWidgetGroupBox); 182 connect( vectorEPSCheckBox, SIGNAL( clicke 180 connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) ); 183 181 184 } 182 } 185 183 186 if ((format == "jpg") || << 184 if ((format == "jpg") || 187 (format == "jpeg")) { 185 (format == "jpeg")) { 188 << 186 189 QGroupBox *imageGroupBox = new QGroupBox(t 187 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this); 190 QHBoxLayout *hSliderLayout = new QHBoxLayo 188 QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox); 191 hSliderLayout->setContentsMargins(15,15,15 << 189 hSliderLayout->setMargin (15); 192 190 193 qualitySlider= new QSlider(Qt::Horizontal, 191 qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox); 194 qualitySlider->setMinimum(0); 192 qualitySlider->setMinimum(0); 195 qualitySlider->setMaximum(100); 193 qualitySlider->setMaximum(100); 196 qualitySlider->setTickPosition(QSlider::Ti 194 qualitySlider->setTickPosition(QSlider::TicksBelow); 197 qualitySlider->setValue(60); 195 qualitySlider->setValue(60); 198 hSliderLayout->addWidget(new QLabel("Low " 196 hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox)); 199 hSliderLayout->addWidget(qualitySlider); 197 hSliderLayout->addWidget(qualitySlider); 200 hSliderLayout->addWidget(new QLabel(" Maxi 198 hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox)); 201 << 199 202 imageGroupBox->setLayout(hSliderLayout); 200 imageGroupBox->setLayout(hSliderLayout); 203 201 204 globalVLayout->addWidget(imageGroupBox); 202 globalVLayout->addWidget(imageGroupBox); 205 } 203 } 206 204 207 205 208 // button ok/cancel box 206 // button ok/cancel box 209 207 210 QWidget *buttonBox = new QWidget(this); 208 QWidget *buttonBox = new QWidget(this); 211 209 212 QHBoxLayout *buttonBoxLayout = new QHBoxLayo 210 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox); 213 211 214 buttonOk = new QPushButton( tr( "&OK" ),butt 212 buttonOk = new QPushButton( tr( "&OK" ),buttonBox ); 215 buttonOk->setAutoDefault( true ); 213 buttonOk->setAutoDefault( true ); 216 buttonOk->setDefault( true ); 214 buttonOk->setDefault( true ); 217 buttonBoxLayout->addWidget(buttonOk); 215 buttonBoxLayout->addWidget(buttonOk); 218 216 219 buttonCancel = new QPushButton( tr( "&Cancel 217 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox ); 220 buttonCancel->setAutoDefault( true ); 218 buttonCancel->setAutoDefault( true ); 221 buttonBoxLayout->addWidget(buttonCancel); 219 buttonBoxLayout->addWidget(buttonCancel); 222 220 223 buttonBox->setLayout(buttonBoxLayout); 221 buttonBox->setLayout(buttonBoxLayout); 224 globalVLayout->addWidget(buttonBox); 222 globalVLayout->addWidget(buttonBox); 225 223 226 224 227 225 228 setLayout(globalVLayout); 226 setLayout(globalVLayout); 229 227 230 // signals and slots connections 228 // signals and slots connections 231 connect( buttonOk, SIGNAL( clicked() ), this 229 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); 232 connect( buttonCancel, SIGNAL( clicked() ), 230 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); 233 } 231 } 234 232 235 233 236 234 237 int G4OpenGLQtExportDialog::getSliderValue() 235 int G4OpenGLQtExportDialog::getSliderValue() 238 { 236 { 239 if (!qualitySlider) return -1; 237 if (!qualitySlider) return -1; 240 return qualitySlider->value(); 238 return qualitySlider->value(); 241 } 239 } 242 240 243 int G4OpenGLQtExportDialog::getHeight() 241 int G4OpenGLQtExportDialog::getHeight() 244 { 242 { 245 if (!height) return originalHeight; 243 if (!height) return originalHeight; 246 return height->text().toInt(); 244 return height->text().toInt(); 247 } 245 } 248 246 249 int G4OpenGLQtExportDialog::getWidth() 247 int G4OpenGLQtExportDialog::getWidth() 250 { 248 { 251 if (!width) return originalWidth; 249 if (!width) return originalWidth; 252 return width->text().toInt(); 250 return width->text().toInt(); 253 } 251 } 254 252 255 bool G4OpenGLQtExportDialog::getVectorEPS() 253 bool G4OpenGLQtExportDialog::getVectorEPS() 256 { 254 { 257 if (!vectorEPSCheckBox) return 0; 255 if (!vectorEPSCheckBox) return 0; 258 return vectorEPSCheckBox->isChecked(); 256 return vectorEPSCheckBox->isChecked(); 259 } 257 } 260 258 261 259 262 void G4OpenGLQtExportDialog::changeVectorEPS() 260 void G4OpenGLQtExportDialog::changeVectorEPS() 263 { 261 { 264 if (!vectorEPSCheckBox) return; 262 if (!vectorEPSCheckBox) return; 265 if (vectorEPSCheckBox->isChecked()) { 263 if (vectorEPSCheckBox->isChecked()) { 266 sizeGroupBox->show(); 264 sizeGroupBox->show(); 267 original->show(); 265 original->show(); 268 modify->show(); 266 modify->show(); 269 changeSizeBox(); 267 changeSizeBox(); 270 } else { 268 } else { 271 sizeGroupBox->hide(); 269 sizeGroupBox->hide(); 272 original->hide(); 270 original->hide(); 273 modify->hide(); 271 modify->hide(); 274 ratioCheckBox->hide(); 272 ratioCheckBox->hide(); 275 heightWidget->hide(); 273 heightWidget->hide(); 276 widthWidget->hide(); 274 widthWidget->hide(); 277 } 275 } 278 } 276 } 279 277 280 278 281 void G4OpenGLQtExportDialog::changeSizeBox() 279 void G4OpenGLQtExportDialog::changeSizeBox() 282 { 280 { 283 if (!original) return; 281 if (!original) return; 284 if (!heightWidget) return; 282 if (!heightWidget) return; 285 if (!widthWidget) return; 283 if (!widthWidget) return; 286 if (!ratioCheckBox) return; 284 if (!ratioCheckBox) return; 287 285 288 if ( original->isChecked()) { 286 if ( original->isChecked()) { 289 ratioCheckBox->hide(); 287 ratioCheckBox->hide(); 290 heightWidget->hide(); 288 heightWidget->hide(); 291 widthWidget->hide(); 289 widthWidget->hide(); 292 } else { 290 } else { 293 heightWidget->show(); 291 heightWidget->show(); 294 widthWidget->show(); 292 widthWidget->show(); 295 ratioCheckBox->show(); 293 ratioCheckBox->show(); 296 } 294 } 297 } 295 } 298 296 299 297 300 void G4OpenGLQtExportDialog::textWidthChanged( 298 void G4OpenGLQtExportDialog::textWidthChanged( 301 const QString & s 299 const QString & s 302 ) 300 ) 303 { 301 { 304 if (!ratioCheckBox) return; 302 if (!ratioCheckBox) return; 305 if (!width) return; 303 if (!width) return; 306 if (isChangingSize == true) return; // exclu 304 if (isChangingSize == true) return; // exclusive slot 307 305 308 if (ratioCheckBox->isChecked()){ 306 if (ratioCheckBox->isChecked()){ 309 isChangingSize = true; 307 isChangingSize = true; 310 QString tmp; 308 QString tmp; 311 height->setText(tmp.setNum((int)(s.toInt()*( 309 height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth)))); 312 isChangingSize = false; 310 isChangingSize = false; 313 } 311 } 314 } 312 } 315 313 316 void G4OpenGLQtExportDialog:: textHeightChang 314 void G4OpenGLQtExportDialog:: textHeightChanged( 317 const QString & s 315 const QString & s 318 ) 316 ) 319 { 317 { 320 if (!ratioCheckBox) return; 318 if (!ratioCheckBox) return; 321 if (!width) return; 319 if (!width) return; 322 if (isChangingSize == true) return; // exclu 320 if (isChangingSize == true) return; // exclusive slot 323 321 324 if (ratioCheckBox->isChecked()){ 322 if (ratioCheckBox->isChecked()){ 325 isChangingSize = true; 323 isChangingSize = true; 326 QString tmp; 324 QString tmp; 327 width->setText(tmp.setNum(s.toInt()*origin 325 width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight)); 328 isChangingSize = false; 326 isChangingSize = false; 329 } 327 } 330 } << 328 } 331 329 332 G4OpenGLQtExportDialog::~G4OpenGLQtExportDialo 330 G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog() 333 { 331 { 334 } 332 } >> 333 >> 334 >> 335 #endif 335 336