G4OpenGLQtExportDialog.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 
00031 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
00032 
00033 #include "G4OpenGLQtExportDialog.hh"
00034 
00035 #include <qvariant.h>
00036 #include <qpushbutton.h>
00037 #include <qcheckbox.h>
00038 #include <qlabel.h>
00039 #include <qcombobox.h>
00040 #include <qslider.h>
00041 #include <qlayout.h>
00042 #include <qgroupbox.h>
00043 #include <qradiobutton.h>
00044 #include <qimage.h>
00045 #include <qlineedit.h>
00046 #include <qbuttongroup.h>
00047 
00048 G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
00049  QWidget* parentw
00050 ,QString format
00051  ,int aHeight
00052  ,int aWidth
00053 )
00054   : QDialog( parentw ),
00055     isChangingSize(false)
00056 {
00057   setWindowTitle( tr( " Export options" ));
00058   originalWidth = aWidth;
00059   originalHeight = aHeight;
00060 
00061   // Initializations
00062   qualitySlider = NULL;
00063   width = NULL;
00064   height = NULL;
00065   colorButton = NULL;
00066   BWButton = NULL;
00067 
00068   // global layout
00069   QVBoxLayout* globalVLayout = new QVBoxLayout(this);
00070   globalVLayout->setMargin(10);
00071   globalVLayout->setSpacing(10);
00072   
00073 
00074 
00075   // FIXME : L. Garnier 4/12/07
00076   // Not implented. Should deal with alpha channel
00077 
00078 //   if((format == "tif") ||
00079 //      (format == "tiff") ||
00080 //      (format == "jpg") ||
00081 //      (format == "jpeg") ||
00082 //      (format == "png") ||
00083 //      (format == "xpm")) {
00084 
00085 //     QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
00086 //     QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
00087 
00088 //     boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
00089 //     boxTransparency->setChecked( false );
00090 
00091 //     transparencyGroupBoxLayout->addWidget(boxTransparency);    
00092 //     globalVLayout->addWidget(transparencyGroupBox);
00093 
00094 //   }
00095 
00096   // FIXME : L. Garnier 4/12/07
00097   // This is not working for PS and PDF images, it does nothing.
00098   // Image is staying in color mode
00099   //  if ((format == "ps") || (format == "pdf") || (format == "eps")) {
00100 
00101 
00102   // size box
00103 
00104   QWidget * sizeWidget = new QWidget(this); // widget containing group button
00105   QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
00106   sizeWidgetLayout->setMargin (10); 
00107 
00108   // original and modify radiobuttons
00109   
00110   sizeGroupBox = new QGroupBox(tr("Size"));
00111   QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
00112   QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
00113   sizeGroupBoxLayout->setMargin (15); 
00114 
00115   original = new QRadioButton("Original");
00116   modify = new QRadioButton("Modify");
00117 
00118   sizeButtonGroupBox->addButton(original);
00119   sizeButtonGroupBox->addButton(modify);
00120   sizeButtonGroupBox->setExclusive(true);
00121 
00122   sizeGroupBoxLayout->addWidget(original);    
00123   sizeGroupBoxLayout->addWidget(modify);    
00124 
00125   sizeGroupBox->setLayout(sizeGroupBoxLayout);
00126   sizeWidgetLayout->addWidget(sizeGroupBox);
00127   
00128   connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) );
00129   original->setChecked( true );
00130 
00131 
00132   // height
00133   heightWidget = new QWidget(sizeWidget);
00134 
00135   QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
00136 
00137   QString tmp;
00138  
00139   heightLineLayout->addWidget(new QLabel("Height",heightWidget));
00140   height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
00141   height->setMaxLength(5);
00142   heightLineLayout->addWidget(height);
00143 
00144   heightWidget->setLayout(heightLineLayout);
00145 
00146   sizeWidgetLayout->addWidget(heightWidget);
00147   connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
00148 
00149 
00150   // width
00151   widthWidget = new QWidget(sizeWidget);
00152 
00153   QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
00154 
00155   widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
00156   width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
00157   width->setMaxLength(5);
00158   widthLineLayout->addWidget(width);
00159   widthWidget->setLayout(widthLineLayout);
00160   sizeWidgetLayout->addWidget(widthWidget);
00161   connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
00162 
00163 
00164 
00165   // ratio check box
00166 
00167   ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
00168   ratioCheckBox->setChecked( true );
00169 
00170   sizeWidgetLayout->addWidget(ratioCheckBox);
00171 
00172   ratioCheckBox->hide();
00173   heightWidget->hide();
00174   widthWidget->hide();
00175 
00176   sizeWidget->setLayout(sizeWidgetLayout);
00177   globalVLayout->addWidget(sizeWidget);
00178 
00179  if (format == "eps") {
00180 
00181    QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
00182 
00183 
00184     QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
00185      EPSGroupBoxLayout->setMargin (15); 
00186 
00187 //     colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
00188 //     BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
00189 
00190 //     QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
00191 //     EPSColorButtonGroupBox->addButton(colorButton);
00192 //     EPSColorButtonGroupBox->addButton(BWButton);
00193 //     EPSColorButtonGroupBox->setExclusive(true);
00194 
00195 //     EPSGroupBoxLayout->addWidget(colorButton);    
00196 //     EPSGroupBoxLayout->addWidget(BWButton);    
00197 
00198     vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
00199     EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
00200 
00201     EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
00202     //    colorButton->setChecked( true );
00203     vectorEPSCheckBox->setChecked( true );
00204     
00205     globalVLayout->addWidget(EPSWidgetGroupBox);
00206     connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
00207 
00208   }
00209 
00210   if ((format == "jpg") || 
00211       (format == "jpeg")) {
00212     
00213     QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
00214     QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
00215     hSliderLayout->setMargin (15); 
00216 
00217     qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
00218     qualitySlider->setMinimum(0);
00219     qualitySlider->setMaximum(100);
00220     qualitySlider->setTickPosition(QSlider::TicksBelow);
00221     qualitySlider->setValue(60);
00222     hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
00223     hSliderLayout->addWidget(qualitySlider);
00224     hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
00225     
00226     imageGroupBox->setLayout(hSliderLayout);
00227 
00228     globalVLayout->addWidget(imageGroupBox);
00229   }
00230 
00231 
00232   // button ok/cancel box
00233 
00234   QWidget *buttonBox = new QWidget(this);
00235 
00236   QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
00237 
00238   buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
00239   buttonOk->setAutoDefault( TRUE );
00240   buttonOk->setDefault( TRUE );
00241   buttonBoxLayout->addWidget(buttonOk);
00242 
00243   buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
00244   buttonCancel->setAutoDefault( TRUE );
00245   buttonBoxLayout->addWidget(buttonCancel);
00246 
00247   buttonBox->setLayout(buttonBoxLayout);
00248   globalVLayout->addWidget(buttonBox);
00249 
00250 
00251 
00252   setLayout(globalVLayout);
00253 
00254   // signals and slots connections
00255   connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
00256   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00257 }
00258 
00259 
00260 
00261 int G4OpenGLQtExportDialog::getSliderValue()
00262 {
00263   if (!qualitySlider) return -1;
00264   return qualitySlider->value();
00265 }
00266 
00267 int G4OpenGLQtExportDialog::getHeight()
00268 {
00269   if (!height) return originalHeight;
00270   return height->text().toInt();
00271 }
00272 
00273 int G4OpenGLQtExportDialog::getWidth()
00274 {
00275   if (!width) return originalWidth;
00276   return width->text().toInt();
00277 }
00278 
00279 int G4OpenGLQtExportDialog::getTransparency()
00280 {
00281   if (!boxTransparency) return -1;
00282   return boxTransparency->isChecked();
00283 }
00284 
00285 int G4OpenGLQtExportDialog::getNbColor()
00286 {
00287   if (!colorButton) return -1;
00288   // Black and white
00289   if (!colorButton->isChecked())
00290     return 1;
00291   // rgb color
00292   return 3;
00293 }
00294 
00295 bool G4OpenGLQtExportDialog::getVectorEPS()
00296 {
00297   if (!vectorEPSCheckBox) return 0;
00298   return vectorEPSCheckBox->isChecked();
00299 }
00300 
00301 
00302 void G4OpenGLQtExportDialog::changeVectorEPS()
00303 {
00304   if (!vectorEPSCheckBox) return;
00305   if (vectorEPSCheckBox->isChecked()) {
00306     sizeGroupBox->show();
00307     original->show();
00308     modify->show();
00309     changeSizeBox();
00310   } else {
00311     sizeGroupBox->hide();
00312     original->hide();
00313     modify->hide();
00314     ratioCheckBox->hide();
00315     heightWidget->hide();
00316     widthWidget->hide();
00317   }
00318 }
00319 
00320 
00321 void G4OpenGLQtExportDialog::changeSizeBox()
00322 {
00323   if (!original) return;
00324   if (!heightWidget) return;
00325   if (!widthWidget) return;
00326   if (!ratioCheckBox) return;
00327 
00328   if ( original->isChecked()) {
00329     ratioCheckBox->hide();
00330     heightWidget->hide();
00331     widthWidget->hide();
00332   } else {
00333     heightWidget->show();
00334     widthWidget->show();
00335     ratioCheckBox->show();
00336   }
00337 }
00338 
00339 
00340 void G4OpenGLQtExportDialog::textWidthChanged(
00341  const QString & s
00342  )
00343 {
00344   if (!ratioCheckBox) return;
00345   if (!width) return;
00346   if (isChangingSize == true) return; // exclusive slot
00347 
00348   if (ratioCheckBox->isChecked()){
00349     isChangingSize = true;
00350     QString tmp;
00351   height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth))));
00352   isChangingSize = false;
00353   }
00354 }
00355 
00356 void G4OpenGLQtExportDialog::  textHeightChanged(
00357  const QString & s
00358 )
00359 {
00360   if (!ratioCheckBox) return;
00361   if (!width) return;
00362   if (isChangingSize == true) return; // exclusive slot
00363 
00364   if (ratioCheckBox->isChecked()){
00365   isChangingSize = true;
00366     QString tmp;
00367     width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
00368   isChangingSize = false;
00369   }
00370 } 
00371 
00372 G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
00373 {
00374 }
00375 
00376 
00377 #endif

Generated on Mon May 27 17:49:09 2013 for Geant4 by  doxygen 1.4.7