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